Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

458/450/RefactorVMPages #458

Merged
merged 13 commits into from
Mar 13, 2019
6 changes: 3 additions & 3 deletions app/views/dashboard/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
</div>
<div class="row">
<div class="col-8">
<%= render 'widget', {vms: @vms, id: 'vms_active', header: 'Active machines', buttons: nil} %>
<%= render 'widget', {vms: @archivable, id: 'vms_to_be_archived', header: 'Archivable Machines', buttons: 'vms/archive_buttons'} %>
<%= render 'widget', {vms: @revivable, id: 'vms_to_be_revived', header: 'Revivable Machines', buttons: 'vms/to_revive_buttons'} %>
<%= render 'widget', {vms: @vms, id: 'vms_active', header: 'Active VMs', buttons: nil} %>
<%= render 'widget', {vms: @archivable, id: 'vms_to_be_archived', header: 'Archivable VMs', buttons: nil} %>
<%= render 'widget', {vms: @revivable, id: 'vms_to_be_revived', header: 'Revivable VMs', buttons: nil} %>
</div>


Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<div class="round <%= vm.powered_on? ? 'bg-success' : 'bg-warning mt-1' %>"></div>
<% if current_user.admin? || vm.sudo_users.include?(current_user) %>
<% if vm.vm_ware_tools? %>
<%= link_to '',
{controller: :vms, action: 'change_power_state', id: vm.name},
method: :post,
data: { confirm: 'Are you sure?' },
class: "btn-manage float-right #{ vm.powered_on? ? 'stop' : 'play' }" %>
data: {confirm: "Are you sure you want to #{ vm.powered_on? ? 'stop' : 'start' } '#{vm.name}'?"},
class: "btn-manage float-right fa #{ vm.powered_on? ? 'fa-stop' : 'fa-play' }" %>
<% if vm.powered_on? %>
<%= link_to '',
{controller: :vms, action: 'reboot_guest_os', id: vm.name},
method: :post,
data: { confirm: 'Are you sure?' },
class: "btn-manage float-right replay" %>
data: {confirm: "Are you sure you want to reboot the guest OS of '#{vm.name}'?"},
class: "btn-manage float-right fa fa-repeat" %>
<% end %>
<% end %>
<% end %>
<% end %>
25 changes: 17 additions & 8 deletions app/views/vms/_table.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
<table data-toggle="table" class="table" id=<%= id %>>
<thead>
<tr>
<th scope="col" data-sortable="true" class="rounded-left">Name</th>
<th scope="col" data-sortable="true" class="rounded-left">Status</th>
<th scope="col" data-sortable="true">Name</th>
<th scope="col" data-sortable="true">Project</th>
<th scope="col" data-sortable="true" class="rounded-right">Responsible</th>
<th scope="col" data-sortable="true">Responsible</th>
<% unless buttons.nil? %>
<th scope="col" class="rounded-right">Actions</th>
<% end %>
<th scope="col" class="d-none">Description</th> <!-- This is not intended to be shown, just important for the search functionality -->
</tr>
</thead>
<tbody id="vms">
<% vms&.slice(0...10)&.each do |vm| %>
<tr>
<td class="table-active">
<%= render 'vms/vm_status', vm: vm %>
<% vm.powered_on? %>
<p class="d-none"><%= vm.archived? ? 'archived' : vm.powered_on? ? 'online' : 'offline' %></p>
<div class="round <%= vm.archived? ? 'bg-secondary' : (vm.powered_on? ? 'bg-success' : 'bg-danger') %>"></div>
</td>
<td class="table-active">
<%= link_to vm.name,
{controller: :vms, action: 'show', id: vm.name},
method: :get, class: "btn btn-link" %>
method: :get, class: "btn btn-link" %>
</td>
<td class="table-active">
<% if vm.project.nil? %>
Expand All @@ -33,11 +41,12 @@
<% end %>
</ul>
<% end %>

<% unless buttons.nil? %>
<%= render buttons.to_s, vm: vm %>
<% end %>
</td>
<% unless buttons.nil? %>
<td class="table-active">
<%= render buttons.to_s, vm: vm %>
</td>
<% end %>
<td class="d-none"> <!-- Also not intended to be shown! -->
<%= vm.config&.description %>
</td>
Expand Down
Empty file.
8 changes: 4 additions & 4 deletions app/views/vms/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<input class="filter-box" type="text" id="filter_active" onkeyup="filterTables('filter_active', ['vms_active', 'vms_to_be_archived', 'vms_to_be_revived', 'vms_archived'])" placeholder="Search">

<%= render 'section', {header: 'Active vms', id: 'active', vms: @vms, buttons: nil} %>
<%= render 'section', {header: 'To be archived vms', id: 'to_be_archived', vms: @pending_archivation_vms, buttons: 'archive_buttons'} %>
<%= render 'section', {header: 'To be revived vms', id: 'to_be_revived', vms: @pending_reviving_vms, buttons: 'to_revive_buttons'} %>
<%= render 'section', {header: 'Archived vms', id: 'archived', vms: @archived_vms, buttons: 'revive_buttons'} %>
<%= render 'section', {header: 'Active VMs', id: 'active', vms: @vms, buttons: 'running_vm_buttons'} %>
<%= render 'section', {header: 'Archivable VMs', id: 'to_be_archived', vms: @pending_archivation_vms, buttons: 'archive_buttons'} %>
<%= render 'section', {header: 'Revivable VMs', id: 'to_be_revived', vms: @pending_reviving_vms, buttons: 'to_revive_buttons'} %>
<%= render 'section', {header: 'Archived VMs', id: 'archived', vms: @archived_vms, buttons: 'revive_buttons'} %>
32 changes: 13 additions & 19 deletions spec/views/vms/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@
end

it 'shows correct power on / off button' do
expect(rendered).to have_css('a.btn-manage.play')
expect(rendered).to have_css('a.fa-play')
end

it 'demands confirmation on shutdown' do
expect(rendered).to have_css('a.btn-manage[data-confirm="Are you sure?"]')
expect(rendered).to have_css 'a.btn-manage[data-confirm]'
end

context 'when vmwaretools are not installed' do
Expand All @@ -65,16 +65,16 @@

it 'shows no power buttons' do
rendered = render
expect(rendered).not_to have_css('a.btn-manage.play')
expect(rendered).not_to have_css('a.btn-manage.stop')
expect(rendered).not_to have_css('a.fa-play')
expect(rendered).not_to have_css('a.fa-stop')
chrisma marked this conversation as resolved.
Show resolved Hide resolved
end
end
end

context 'when the user is not a root user for the vms' do
it 'does not show any manage buttons' do
expect(rendered).not_to have_css('a.btn-manage.play')
expect(rendered).not_to have_css('a.btn-manage.stop')
expect(rendered).not_to have_css('a.fa-play')
expect(rendered).not_to have_css('a.fa-stop')
end
end

Expand All @@ -98,24 +98,18 @@
let(:current_user) { FactoryBot.create :admin }

it 'shows correct power on / off button' do
expect(rendered).to have_css('a.btn-manage.play')
expect(rendered).to have_css('a.fa-play')
end

it 'demands confirmation on shutdown' do
expect(rendered).to have_css('a.btn-manage[data-confirm="Are you sure?"]')
expect(rendered).to have_css('a.btn-manage[data-confirm]')
end

context 'when vmwaretools are not installed' do
before do
assign(:vms, mock_vms_without_tools)
render
end

it 'shows no power buttons' do
rendered = render
expect(rendered).not_to have_css('a.btn-manage.play')
expect(rendered).not_to have_css('a.btn-manage.stop')
end
it 'shows no power buttons when vmwaretools are not installed' do
assign(:vms, mock_vms_without_tools)
rendered = render
expect(rendered).not_to have_css('a.fa-play')
expect(rendered).not_to have_css('a.fa-stop')
end

it 'links to new vm page' do
Expand Down