Skip to content

Commit

Permalink
Fix(VMs Show): Show request associated with VM
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisma committed Apr 5, 2019
1 parent 026e483 commit f70ddb6
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 100 deletions.
4 changes: 3 additions & 1 deletion app/controllers/vms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def index
filter_vm_categories current_user unless current_user.admin?
end

def show; end
def show
@vm_request = Request.find_by_name params[:id]
end

def edit_config
@vm.ensure_config
Expand Down
4 changes: 0 additions & 4 deletions app/views/application/_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
<div class="modal-body">
<%= yield %>
</div>
<div class="modal-footer">
<%= yield :footer %>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
91 changes: 91 additions & 0 deletions app/views/requests/_detail.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<table class="table">
<tbody>
<tr>
<td><strong>VM Name</strong></td>
<td><%= request.name %></td>
</tr>

<tr>
<td><strong>CPU Cores</strong></td>
<td><%= request.cpu_cores %></td>
</tr>

<tr>
<td><strong>RAM</strong></td>
<td><%= request.ram_gb %> GB</td>
</tr>

<tr>
<td><strong>Storage</strong></td>
<td><%= request.storage_gb %> GB</td>
</tr>

<tr>
<td><strong>Operating System</strong></td>
<td><%= request.operating_system %></td>
</tr>

<tr>
<td><strong>Port Forwarding</strong></td>
<td>
Enabled: <%= t request.port_forwarding %><br>
<%= request.application_name %> <%= request.port %>
</td>
</tr>

<tr>
<td><strong>Description</strong></td>
<td class="col-md-4"><%= request.description %></td>
</tr>

<tr>
<td><strong>Comment</strong></td>
<td class="col-md-4"><%= request.comment %></td>
</tr>

<tr>
<td><strong>Status</strong></td>
<td>
<%= request.status %><br>
<% if request.rejected? %>
<strong>Rejection Information:</strong> <%= request.rejection_information %>
<% end %>
</td>
</tr>

<tr>
<td><strong>Responsible users</strong></td>
<td>
<% request.responsible_users.each do |user| %>
<p><%= user.email %></p>
<% end %>
</td>
</tr>

<tr>
<td><strong>Users with sudo rights</strong></td>
<td>
<% request.sudo_user_assignments.each do |assignment| %>
<p><%= assignment.user.email %></p>
<% end %>
</td>
</tr>

<tr>
<td><strong>Users</strong></td>
<td>
<% request.non_sudo_user_assignments.each do |assignment| %>
<p><%= assignment.user.email %></p>
<% end %>
</td>
</tr>

<tr>
<td><strong>Request Date</strong></td>
<td>
<%= I18n.l request.created_at, format: :long %> (<%= time_ago_in_words request.created_at %> ago)
</td>
</tr>
</tbody>
</table>

89 changes: 1 addition & 88 deletions app/views/requests/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,92 +1,5 @@
<h1>Request Information</h1>

<table class="table">
<tbody>
<tr>
<td><strong>VM Name</strong></td>
<td><%= @request.name %></td>
</tr>

<tr>
<td><strong>CPU cores</strong></td>
<td><%= @request.cpu_cores %></td>
</tr>

<tr>
<td><strong>RAM in GB:</strong></td>
<td><%= @request.ram_gb %></td>
</tr>

<tr>
<td><strong>Storage in GB:</strong></td>
<td><%= @request.storage_gb %></td>
</tr>

<tr>
<td><strong>Operating System</strong></td>
<td><%= @request.operating_system %></td>
</tr>

<tr>
<td><strong>Port</strong></td>
<td><%= @request.port %></td>
</tr>

<tr>
<td><strong>Application Name</strong></td>
<td><%= @request.application_name %></td>
</tr>

<tr>
<td><strong>Description</strong></td>
<td class="col-md-4"><%= @request.description %></td>
</tr>

<tr>
<td><strong>Comment</strong></td>
<td class="col-md-4"><%= @request.comment %></td>
</tr>

<tr>
<td><strong>Status</strong></td>
<td><%= @request.status %></td>
</tr>

<tr>
<td><strong>Responsible users</strong></td>
<td>
<% @request.responsible_users.each do |user| %>
<p><%= user.email %></p>
<% end %>
</td>
</tr>

<tr>
<td><strong>Users with sudo rights</strong></td>
<td>
<% @request.sudo_user_assignments.each do |assignment| %>
<p><%= assignment.user.email %></p>
<% end %>
</td>
</tr>

<tr>
<td><strong>Users</strong></td>
<td>
<% @request.non_sudo_user_assignments.each do |assignment| %>
<p><%= assignment.user.email %></p>
<% end %>
</td>
</tr>

</tbody>
</table>

<% if @request.rejected? %>
<p>
<strong>Rejection Information:</strong>
<%= @request.rejection_information %>
</p>
<% end %>
<%= render 'detail', request: @request %>
<%= link_to 'Back', requests_path, class: "btn btn-secondary" %>
28 changes: 21 additions & 7 deletions app/views/vms/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ end %>

<div class="container mb-3 mt-0 pl-0 pr-0 lead clearfix" style="width: 100%">
<div class="float-left">Host: <%= link_to @vm.host_name, controller: "hosts", action: "show", id: @vm.host_name unless @vm.nil? %></div>
<div class="text-right">Project: <%= @vm.project.nil? ? 'No project found!' : @vm.project.name %></div>
<div class="text-right">Project: <%= @vm.project.nil? ? 'No project' : @vm.project.name %></div>
</div>

<%
Expand Down Expand Up @@ -107,6 +107,15 @@ end %>
<div class="table-active container mb-3 pb-3 pt-3">
<h4 class="mb-4">Description</h4>
<%= simple_format(@vm&.config&.description) %>
<div class="mb-4">
VM created by HART: <%= t @vm_request.present? %>
<% if @vm_request.present? %>
<button class="btn btn-sm btn-secondary text-white"
data-toggle="modal" data-target="#vm_request">
Show Request
</button>
<% end %>
</div>
</div>
<div class="container mb-3 pb-3 pl-0 pr-0 clearfix" style="width: 100%; display: flex;">
<div class="column float-left mr-3 half-screen-box">
Expand All @@ -122,8 +131,8 @@ end %>
<%# Button that shows the Puppet Script modal %>
<% if @vm.config.present? && current_user.admin? %>
<button class="btn btn-sm btn-secondary text-white float-right"
data-toggle="modal" title="Show Puppet Scripts" data-target="#puppetscript">
<%= fa_icon('code') %>
data-toggle="modal" data-target="#puppetscript">
<%= fa_icon('code', text: 'Show Puppet Scripts') %>
</button>
<% end %>
</h4>
Expand All @@ -150,7 +159,6 @@ end %>
<% if @vm.config.present? && current_user.admin? %>
<%# Modal for Puppet Script display %>
<%= render 'application/modal', {title: 'Puppet Scripts', id: 'puppetscript', dialog_class: 'modal-lg'} do %>
<%# Main body of modal gets rendered into unnamed yield %>
<div class="card">
<div class="card-header">
Generated Node Script<br>
Expand All @@ -177,10 +185,16 @@ end %>
<pre class="mb-0"><%= Puppetscript.name_script @vm.name %></pre>
</div>
</div><%# card %>
<%# Additonal content in the modal footer %>
<% content_for :footer do %>
<div class="modal-footer">
<%= link_to "Push to git", push_to_git_request_path(request), method: :post, class: "btn btn-primary" %>
<% end %><%# content_for :footer %>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
<% end %>
<% end %>
<% if @vm_request.present? %>
<%# Modal for displaying associated request %>
<%= render 'application/modal', {title: "#{@vm_request.name} VM Request", id: 'vm_request', dialog_class: 'modal-lg'} do %>
<%= render "requests/detail", request: @vm_request %>
<% end %>
<% end %>

0 comments on commit f70ddb6

Please sign in to comment.