From f70ddb653da88a8384acb98e657f14a0d19cb1cc Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Fri, 5 Apr 2019 15:14:12 +0200 Subject: [PATCH] Fix(VMs Show): Show request associated with VM --- app/controllers/vms_controller.rb | 4 +- app/views/application/_modal.html.erb | 4 -- app/views/requests/_detail.html.erb | 91 +++++++++++++++++++++++++++ app/views/requests/show.html.erb | 89 +------------------------- app/views/vms/show.html.erb | 28 ++++++--- 5 files changed, 116 insertions(+), 100 deletions(-) create mode 100644 app/views/requests/_detail.html.erb diff --git a/app/controllers/vms_controller.rb b/app/controllers/vms_controller.rb index f1bd2365..ddf02112 100644 --- a/app/controllers/vms_controller.rb +++ b/app/controllers/vms_controller.rb @@ -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 diff --git a/app/views/application/_modal.html.erb b/app/views/application/_modal.html.erb index 58586b37..907fe171 100644 --- a/app/views/application/_modal.html.erb +++ b/app/views/application/_modal.html.erb @@ -11,10 +11,6 @@ - \ No newline at end of file diff --git a/app/views/requests/_detail.html.erb b/app/views/requests/_detail.html.erb new file mode 100644 index 00000000..0bfd101b --- /dev/null +++ b/app/views/requests/_detail.html.erb @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
VM Name<%= request.name %>
CPU Cores<%= request.cpu_cores %>
RAM<%= request.ram_gb %> GB
Storage<%= request.storage_gb %> GB
Operating System<%= request.operating_system %>
Port Forwarding + Enabled: <%= t request.port_forwarding %>
+ <%= request.application_name %> <%= request.port %> +
Description<%= request.description %>
Comment<%= request.comment %>
Status + <%= request.status %>
+ <% if request.rejected? %> + Rejection Information: <%= request.rejection_information %> + <% end %> +
Responsible users + <% request.responsible_users.each do |user| %> +

<%= user.email %>

+ <% end %> +
Users with sudo rights + <% request.sudo_user_assignments.each do |assignment| %> +

<%= assignment.user.email %>

+ <% end %> +
Users + <% request.non_sudo_user_assignments.each do |assignment| %> +

<%= assignment.user.email %>

+ <% end %> +
Request Date + <%= I18n.l request.created_at, format: :long %> (<%= time_ago_in_words request.created_at %> ago) +
+ diff --git a/app/views/requests/show.html.erb b/app/views/requests/show.html.erb index 99487255..3e72067e 100644 --- a/app/views/requests/show.html.erb +++ b/app/views/requests/show.html.erb @@ -1,92 +1,5 @@

Request Information

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
VM Name<%= @request.name %>
CPU cores<%= @request.cpu_cores %>
RAM in GB:<%= @request.ram_gb %>
Storage in GB:<%= @request.storage_gb %>
Operating System<%= @request.operating_system %>
Port<%= @request.port %>
Application Name<%= @request.application_name %>
Description<%= @request.description %>
Comment<%= @request.comment %>
Status<%= @request.status %>
Responsible users - <% @request.responsible_users.each do |user| %> -

<%= user.email %>

- <% end %> -
Users with sudo rights - <% @request.sudo_user_assignments.each do |assignment| %> -

<%= assignment.user.email %>

- <% end %> -
Users - <% @request.non_sudo_user_assignments.each do |assignment| %> -

<%= assignment.user.email %>

- <% end %> -
- -<% if @request.rejected? %> -

- Rejection Information: - <%= @request.rejection_information %> -

-<% end %> +<%= render 'detail', request: @request %> <%= link_to 'Back', requests_path, class: "btn btn-secondary" %> \ No newline at end of file diff --git a/app/views/vms/show.html.erb b/app/views/vms/show.html.erb index 7df9f8e9..3e958b75 100644 --- a/app/views/vms/show.html.erb +++ b/app/views/vms/show.html.erb @@ -75,7 +75,7 @@ end %>
Host: <%= link_to @vm.host_name, controller: "hosts", action: "show", id: @vm.host_name unless @vm.nil? %>
-
Project: <%= @vm.project.nil? ? 'No project found!' : @vm.project.name %>
+
Project: <%= @vm.project.nil? ? 'No project' : @vm.project.name %>
<% @@ -107,6 +107,15 @@ end %>

Description

<%= simple_format(@vm&.config&.description) %> +
+ VM created by HART: <%= t @vm_request.present? %> + <% if @vm_request.present? %> + + <% end %> +
@@ -122,8 +131,8 @@ end %> <%# Button that shows the Puppet Script modal %> <% if @vm.config.present? && current_user.admin? %> <% end %> @@ -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 %>
Generated Node Script
@@ -177,10 +185,16 @@ end %>
<%= Puppetscript.name_script @vm.name %>
<%# card %> - <%# Additonal content in the modal footer %> - <% content_for :footer do %> + <% 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 %> \ No newline at end of file