Module: HomeHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/home_helper.rb

Instance Method Summary collapse

Instance Method Details

#allowed_choices(choices, action = "index") ⇒ Object

filters out any non allowed actions from the setting menu.


105
106
107
108
109
110
111
# File 'app/helpers/home_helper.rb', line 105

def allowed_choices choices, action = "index"
  choices.map do |opt|
    name, kontroller = opt
    url = send("#{kontroller}_url")
    authorized_for(kontroller, action) ? [name, url] : nil
  end.compact.sort
end

#authorized_menu_actions(choices) ⇒ Object


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/helpers/home_helper.rb', line 57

def authorized_menu_actions(choices)
  last_item = nil
  choices = choices.map do |item|
    #prevent adjacent dividers
    if item == [:divider]
      if last_item
        last_item = nil
        item
      end
    elsif item.size == 2 && authorized_for(item[1], :index)
      last_item = item
      item
    elsif item.size == 3
      item[2] = item[2].map do |sub_item|
        sub_item if authorized_for(sub_item[1], :index)
      end.compact
      if item[2].size > 0
        last_item = item
        item
      end
    end
  end.compact
  choices.pop if (choices.last == [:divider])
  choices
end

#class_for_setting_pageObject


3
4
5
# File 'app/helpers/home_helper.rb', line 3

def class_for_setting_page
  setting_options.flatten.include?(controller_name.to_sym) ? "active" : ""
end

83
84
85
86
87
88
89
# File 'app/helpers/home_helper.rb', line 83

def menu(tab, label, path = nil)
  path ||= send("hash_for_#{tab}_path")
  return '' unless authorized_for(path[:controller], path[:action] )
  (:li, :class => "menu_tab_#{tab} ") do
    link_to_if_authorized(label, path)
  end
end

#org_switcher_titleObject


91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/helpers/home_helper.rb', line 91

def org_switcher_title
  title = if Organization.current && Location.current
    Organization.current.to_label + "@" + Location.current.to_label
  elsif Organization.current
    Organization.current.to_label
  elsif Location.current
    Location.current.to_label
  else
    _("Any Context")
  end
  title
end

#setting_optionsObject


7
8
9
# File 'app/helpers/home_helper.rb', line 7

def setting_options
  authorized_menu_actions(settings_menu_items)+[[_('About'), :about]]
end

#settings_menu_itemsObject


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/helpers/home_helper.rb', line 11

def settings_menu_items
  configuration_group =
      [[_('Environments'),          :environments],
      [_('Global Parameters'),      :common_parameters],
      [_('Host Groups'),            :hostgroups],
      [_('Puppet Classes'),         :puppetclasses],
      [_('Smart Variables'),        :lookup_keys],
      [_('Smart Proxies'),          :smart_proxies]]
  menu_items = [ [:group, _("Configuration"), configuration_group]]

  if SETTINGS[:unattended]
    provisioning_group =
        [[_('Architectures'),          :architectures],
        [_('Compute Resources'),      :compute_resources],
        [_('Domains'),                :domains],
        [_('Hardware Models'),        :models],
        [_('Installation Media'),     :media],
        [_('Operating Systems'),      :operatingsystems],
        [_('Partition Tables'),       :ptables],
        [_('Provisioning Templates'), :config_templates],
        [_('Subnets'),                :subnets]]
    menu_items += [[:divider], [:group, _("Provisioning"), provisioning_group]]
  end

  if (SETTINGS[:organizations_enabled] or SETTINGS[:locations_enabled])
    menu_items += [[:divider]]
    menu_items += [ [_('Locations'), :locations] ]         if SETTINGS[:locations_enabled]
    menu_items += [ [_('Organizations'), :organizations] ] if SETTINGS[:organizations_enabled]
  end

  users_group =
    [[_('LDAP Authentication'),    :auth_source_ldaps],
    [_('Users'),                  :users],
    [_('User Groups'),            :usergroups]]
  users_group += [[_('Roles'),     :roles]] if User.current && User.current.admin?

  menu_items += [[:divider], [:group, _("Users"), users_group] ] if SETTINGS[:login]

  menu_items += [
    [:divider],
    [_('Bookmarks'),              :bookmarks],
    [_('Settings'),               :settings]
  ]
  menu_items
end

#user_headerObject


113
114
115
116
117
# File 'app/helpers/home_helper.rb', line 113

def user_header
  summary = gravatar_image_tag(User.current.mail, :class=>'gravatar small', :alt=>_('Change your avatar at gravatar.com')) +
            "#{User.current.to_label} " + (:span, "", :class=>'caret')
  link_to(summary.html_safe, "#", :class => "dropdown-toggle", :'data-toggle'=>"dropdown")
end