From 31866e1dea0e2d5e0c2017a3be25eb4e4f858969 Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Fri, 17 Jan 2020 16:59:18 +0100 Subject: [PATCH] Refactor resource_pool controller, make Edit VM thru Resource Pool work Issue: https://github.com/ManageIQ/manageiq-ui-classic/issues/6617 --- .../mixins/generic_button_mixin.rb | 7 +-- app/controllers/resource_pool_controller.rb | 51 +++++-------------- 2 files changed, 16 insertions(+), 42 deletions(-) diff --git a/app/controllers/mixins/generic_button_mixin.rb b/app/controllers/mixins/generic_button_mixin.rb index 7906938fd796..3b25b215cd9d 100644 --- a/app/controllers/mixins/generic_button_mixin.rb +++ b/app/controllers/mixins/generic_button_mixin.rb @@ -12,7 +12,7 @@ def handle_vm_buttons(pressed) return [:finished, pfx] if vm_button_redirected?(pfx, pressed) unless ["#{pfx}_edit", "#{pfx}_miq_request_new", "#{pfx}_clone", - "#{pfx}_migrate", "#{pfx}_publish"].include?(pressed) + "#{pfx}_migrate", "#{pfx}_publish", 'vm_rename'].include?(pressed) @refresh_div = "main_div" @refresh_partial = "layouts/gtl" show # Handle VMs buttons @@ -79,8 +79,9 @@ def button return end - if params[:pressed].ends_with?("_edit") || ["#{pfx}_miq_request_new", "#{pfx}_clone", - "#{pfx}_migrate", "#{pfx}_publish"].include?(params[:pressed]) + if params[:pressed].ends_with?("_edit") || + ["#{pfx}_miq_request_new", "#{pfx}_clone", "#{pfx}_migrate", "#{pfx}_publish"].include?(params[:pressed]) || + params[:pressed] == 'vm_rename' && @flash_array.nil? render_or_redirect_partial(pfx) elsif @refresh_div == "main_div" && @lastaction == "show_list" replace_gtl_main_div diff --git a/app/controllers/resource_pool_controller.rb b/app/controllers/resource_pool_controller.rb index ba1359609a70..af5839a59ff5 100644 --- a/app/controllers/resource_pool_controller.rb +++ b/app/controllers/resource_pool_controller.rb @@ -4,6 +4,7 @@ class ResourcePoolController < ApplicationController after_action :cleanup_action after_action :set_session_data + include Mixins::GenericButtonMixin include Mixins::GenericListMixin include Mixins::GenericSessionMixin include Mixins::GenericShowMixin @@ -17,48 +18,20 @@ def self.display_methods def button @edit = session[:edit] # Restore @edit for adv search box params[:display] = @display if %w[all_vms vms resource_pools].include?(@display) # Were we displaying sub-items - if %w[all_vms vms resource_pools].include?(@display) # Need to check, since RPs contain RPs - if params[:pressed].starts_with?("vm_", # Handle buttons from sub-items screen - "miq_template_", - "guest_") - - pfx = pfx_for_vm_button_pressed(params[:pressed]) - process_vm_buttons(pfx) - - return if ["#{pfx}_policy_sim", "#{pfx}_compare", "#{pfx}_tag", "#{pfx}_protect", - "#{pfx}_retire", "#{pfx}_right_size", "#{pfx}_ownership", - "#{pfx}_reconfigure"].include?(params[:pressed]) && - @flash_array.nil? # Some other screen is showing, so return - - unless ["#{pfx}_edit", "#{pfx}_miq_request_new", "#{pfx}_clone", - "#{pfx}_migrate", "#{pfx}_publish", 'vm_rename'].include?(params[:pressed]) - @refresh_div = "main_div" - @refresh_partial = "layouts/gtl" - show - end + @refresh_div = "main_div" unless @display # Default div for button.rjs to refresh + case params[:pressed] + when 'resource_pool_delete' + deleteresourcepools + if @refresh_div == "main_div" && @lastaction == "show_list" + replace_gtl_main_div + else + render_flash unless performed? end + when 'resource_pool_protect' + assign_policies(ResourcePool) else - @refresh_div = "main_div" # Default div for button.rjs to refresh - tag(ResourcePool) if params[:pressed] == "resource_pool_tag" - deleteresourcepools if params[:pressed] == "resource_pool_delete" - assign_policies(ResourcePool) if params[:pressed] == "resource_pool_protect" - end - - return if %w[resource_pool_tag resource_pool_protect].include?(params[:pressed]) && @flash_array.nil? # Tag screen showing, so return - - check_if_button_is_implemented - - if single_delete_test - single_delete_redirect - elsif ["#{pfx}_miq_request_new", "#{pfx}_migrate", "#{pfx}_clone", - "#{pfx}_migrate", "#{pfx}_publish"].include?(params[:pressed]) || - params[:pressed] == 'vm_rename' && @flash_array.nil? - render_or_redirect_partial(pfx) - elsif @refresh_div == "main_div" && @lastaction == "show_list" - replace_gtl_main_div - else - render_flash unless performed? + super end end