From f780b6fbd2e2159f9c831d82cb932cc0025e5e04 Mon Sep 17 00:00:00 2001 From: Roman Blanco Date: Thu, 9 Mar 2017 14:45:40 +0100 Subject: [PATCH 1/2] Making the function for converting controller to model more readable --- app/helpers/application_helper.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ad90161e895..a239d4091fa 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -161,6 +161,7 @@ def role_allows?(**options) Rbac.role_allows?(options.merge(:user => User.current_user)) rescue false end + module_function :role_allows? public :role_allows? alias_method :role_allows, :role_allows? @@ -174,7 +175,10 @@ def model_to_controller(record) def controller_to_model case self.class.model.to_s - when "ManageIQ::Providers::CloudManager::Template", "ManageIQ::Providers::CloudManager::Vm", "ManageIQ::Providers::InfraManager::Template", "ManageIQ::Providers::InfraManager::Vm" + when "ManageIQ::Providers::CloudManager::Template", + "ManageIQ::Providers::CloudManager::Vm", + "ManageIQ::Providers::InfraManager::Template", + "ManageIQ::Providers::InfraManager::Vm" VmOrTemplate else self.class.model From 62a377c63660900c2293092c6082856917b7dd09 Mon Sep 17 00:00:00 2001 From: Roman Blanco Date: Thu, 9 Mar 2017 14:44:27 +0100 Subject: [PATCH 2/2] Making the function to decide hover class more readable --- app/helpers/application_helper.rb | 15 ++++++++------- app/views/shared/summary/_textual.html.haml | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a239d4091fa..9ecca2e0975 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -143,13 +143,14 @@ def hidden_tag_if(tag, condition, options = {}, &block) end end - def no_hover_class(item) - klass = if item[:link] - "" - elsif item.has_key?(:value) - "" if item[:value].kind_of?(Array) && item[:value].any? {|val| val[:link]} - end - klass.nil? ? 'no-hover' : '' + def hover_class(item) + if item.fetch_path(:link) || + item.fetch_path(:value).kind_of?(Array) && + item[:value].any? { |val| val[:link] } + 'no-hover' + else + '' + end end # Check role based authorization for a UI task diff --git a/app/views/shared/summary/_textual.html.haml b/app/views/shared/summary/_textual.html.haml index 932badc9243..fae55d06e62 100644 --- a/app/views/shared/summary/_textual.html.haml +++ b/app/views/shared/summary/_textual.html.haml @@ -15,7 +15,7 @@ - else - click = "DoNav('#{item[:link]}');" - %tr{:class => no_hover_class(item), + %tr{:class => hover_class(item), :title => item[:title] ? item[:title] : "", :onclick => item[:link] ? click : ""} %td.label