foreman/app/helpers/home_helper.rb @ 18118f5a
6e50fa1d | Ohad Levy | module HomeHelper
|
|
9161008b | Amos Benari | ||
def class_for_current_page(tab)
|
|||
05ab4c16 | Ohad Levy | controller_name.gsub(/_.*/,"s") == tab ? "active" : ""
|
|
9161008b | Amos Benari | end
|
|
05ab4c16 | Ohad Levy | def class_for_setting_page
|
|
67622087 | Amos Benari | if setting_options.map{|o| o[1]}.include? controller_name.to_sym
|
|
05ab4c16 | Ohad Levy | "active"
|
|
end
|
|||
end
|
|||
def setting_options
|
|||
choices = [
|
|||
['Environments', :environments],
|
|||
['Global Parameters', :common_parameters],
|
|||
['Host Groups', :hostgroups],
|
|||
['Puppet Classes', :puppetclasses],
|
|||
384823b2 | Amos Benari | ['Smart Variables', :lookup_keys],
|
|
05ab4c16 | Ohad Levy | ['Smart Proxies', :smart_proxies]
|
|
]
|
|||
0f35c707 | Brian Gupta | if SETTINGS[:unattended]
|
|
choices += [
|
|||
[:divider],
|
|||
['Compute Resources', :compute_resources]
|
|||
]
|
|||
82e47ae0 | Amos Benari | ||
0f35c707 | Brian Gupta | choices += [ ['Hypervisors', :hypervisors ] ] if SETTINGS[:libvirt]
|
|
choices += [
|
|||
[:divider],
|
|||
['Architectures', :architectures],
|
|||
['Domains', :domains],
|
|||
['Hardware Models', :models],
|
|||
['Installation Media', :media],
|
|||
['Operating Systems', :operatingsystems],
|
|||
['Partition Tables', :ptables],
|
|||
['Provisioning Templates', :config_templates],
|
|||
['Subnets', :subnets]
|
|||
]
|
|||
end
|
|||
05ab4c16 | Ohad Levy | ||
choices += [
|
|||
82e47ae0 | Amos Benari | [:divider],
|
|
['LDAP Authentication', :auth_source_ldaps],
|
|||
05ab4c16 | Ohad Levy | ['Users', :users],
|
|
cddf6add | Ohad Levy | ['User Groups', :usergroups],
|
|
05ab4c16 | Ohad Levy | ] if SETTINGS[:login]
|
|
82e47ae0 | Amos Benari | ||
05ab4c16 | Ohad Levy | choices += [
|
|
['Roles', :roles]
|
|||
] if SETTINGS[:login] and User.current.admin?
|
|||
82e47ae0 | Amos Benari | choices += [
|
|
[:divider],
|
|||
['Bookmarks', :bookmarks],
|
|||
['Settings', :settings]
|
|||
]
|
|||
1d0bc0b0 | Amos Benari | #prevent adjacent dividers
|
|
last_item = nil
|
|||
18118f5a | Ohad Levy | choices = choices.map do |item|
|
|
1d0bc0b0 | Amos Benari | if item == [:divider]
|
|
if last_item
|
|||
last_item = nil
|
|||
180a48c8 | Amos Benari | item
|
|
1d0bc0b0 | Amos Benari | end
|
|
933c8a83 | Amos Benari | elsif authorized_for(item[1], :index)
|
|
1d0bc0b0 | Amos Benari | last_item = item
|
|
180a48c8 | Amos Benari | item
|
|
1d0bc0b0 | Amos Benari | end
|
|
end.compact
|
|||
180a48c8 | Amos Benari | choices.pop if (choices.last == [:divider])
|
|
933c8a83 | Amos Benari | choices
|
|
05ab4c16 | Ohad Levy | end
|
|
9161008b | Amos Benari | def menu(tab, myBookmarks ,path = nil)
|
|
path ||= eval("hash_for_#{tab}_path")
|
|||
05ab4c16 | Ohad Levy | return '' unless authorized_for(path[:controller], path[:action] )
|
|
9161008b | Amos Benari | b = myBookmarks.map{|b| b if b.controller == path[:controller]}.compact
|
|
05ab4c16 | Ohad Levy | out = content_tag :li, :class => class_for_current_page(tab) do
|
|
link_to_if_authorized(tab.capitalize, path, :class => b.empty? ? "" : "narrow-right")
|
|||
9161008b | Amos Benari | end
|
|
a7961050 | Amos Benari | out += content_tag :li, :class => "dropdown hidden-tablet hidden-phone " + class_for_current_page(tab) do
|
|
link_to(content_tag(:span,'', :'data-toggle'=> 'dropdown', :class=>'caret hidden-phone hidden-tablet'), "#", :class => "dropdown-toggle narrow-left hidden-phone hidden-tablet") + menu_dropdown(b)
|
|||
05ab4c16 | Ohad Levy | end unless b.empty?
|
|
out
|
|||
end
|
|||
def menu_dropdown bookmark
|
|||
return "" if bookmark.empty?
|
|||
render("bookmarks/list", :bookmarks => bookmark)
|
|||
9161008b | Amos Benari | end
|
|
01984fb7 | Amos Benari | ||
# filters out any non allowed actions from the setting menu.
|
|||
def allowed_choices choices, action = "index"
|
|||
choices.map do |opt|
|
|||
name, kontroller = opt
|
|||
url = eval("#{kontroller}_url")
|
|||
authorized_for(kontroller, action) ? [name, url] : nil
|
|||
end.compact.sort
|
|||
end
|
|||
6e50fa1d | Ohad Levy | end
|