Skip to content

Commit

Permalink
Merge pull request #638 from romanblanco/application_controller_cleanup
Browse files Browse the repository at this point in the history
Making application helper methods more readable
  • Loading branch information
mzazrivec authored Mar 9, 2017
2 parents e021f92 + 62a377c commit 61f45aa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -161,6 +162,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?
Expand All @@ -174,7 +176,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
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/summary/_textual.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 61f45aa

Please sign in to comment.