Module: SmartProxiesHelper

Defined in:
app/helpers/smart_proxies_helper.rb

Constant Summary collapse

TABBED_FEATURES =
["Puppet", "Puppet CA", "Logs"]

Instance Method Summary collapse

Instance Method Details

#feature_actions(proxy, authorizer) ⇒ Object


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
# File 'app/helpers/smart_proxies_helper.rb', line 13

def feature_actions(proxy, authorizer)
  actions = []

  actions << display_link_if_authorized(_("Refresh"), hash_for_refresh_smart_proxy_path(:id => proxy).
                                                               merge(:auth_object => proxy, :permission => 'edit_smart_proxies', :authorizer => authorizer), :method => :put)

  if proxy.has_feature?('Puppet CA')
    actions << display_link_if_authorized(_("Certificates"), hash_for_smart_proxy_path(:id => proxy).
                                                             merge(:auth_object => proxy, :permission => 'view_smart_proxies_puppetca', :authorizer => authorizer, :anchor => 'certificates'))

    actions << display_link_if_authorized(_("Autosign"), hash_for_smart_proxy_path(:id => proxy).
                                                         merge(:auth_object => proxy, :permission => 'view_smart_proxies_autosign', :authorizer => authorizer, :anchor => 'autosign'))
  end

  if SETTINGS[:unattended] && proxy.has_feature?('DHCP')
    actions << display_link_if_authorized(_("Import IPv4 subnets"), hash_for_import_subnets_path(:smart_proxy_id => proxy))
  end

  if proxy.has_feature?('Logs')
    actions << link_to_function_if_authorized(_('Expire logs'), "expireLogs(this, (new Date).getTime() / 1000);",
      hash_for_expire_logs_smart_proxy_path(:id => proxy), {
        :data => {
          :url => expire_logs_smart_proxy_path(:id => proxy),
          :"url-errors" => errors_card_smart_proxy_path(:id => proxy),
          :"url-modules" => modules_card_smart_proxy_path(:id => proxy),
        },
      })
  end

  actions << render_pagelets_for(:smart_proxy_title_actions, :subject => proxy)

  actions
end

#logs_color_mapObject


77
78
79
80
81
82
83
84
85
# File 'app/helpers/smart_proxies_helper.rb', line 77

def logs_color_map
  {
    'DEBUG' => 'success',
    'INFO' => 'info',
    'WARN' => 'warning',
    'ERROR' => 'danger',
    'FATAL' => 'danger',
  }
end

#logs_filter_tagObject


87
88
89
90
91
92
93
# File 'app/helpers/smart_proxies_helper.rb', line 87

def logs_filter_tag
  select_tag "Filter", options_for_select(
    [[_('All'), '']] +
    [[_('ERROR or FATAL'), 'ERROR|FATAL']] +
    [[_('WARNING'), 'WARN']] +
    [[_('INFO or DEBUG'), 'INFO|DEBUG']]), :class => "datatable-filter", :id => "logs-filter"
end

#proxy_actions(proxy, authorizer) ⇒ Object


4
5
6
7
8
9
10
11
# File 'app/helpers/smart_proxies_helper.rb', line 4

def proxy_actions(proxy, authorizer)
  actions = []
  actions << display_link_if_authorized(_("Edit"), hash_for_edit_smart_proxy_path(:id => proxy))
  actions << display_delete_if_authorized(hash_for_smart_proxy_path(:id => proxy).merge(:auth_object => proxy, :authorizer => authorizer),
    :data => {:confirm => _("Delete %s?") % proxy.name}, :class => 'delete')
  actions << feature_actions(proxy, authorizer)
  actions
end

#refresh_proxy_button(proxy, authorizer) ⇒ Object


60
61
62
63
# File 'app/helpers/smart_proxies_helper.rb', line 60

def refresh_proxy_button(proxy, authorizer)
  display_link_if_authorized(_('Refresh features'), hash_for_refresh_smart_proxy_path(:id => proxy).
                                                   merge(:auth_object => proxy, :permission => 'edit_smart_proxies', :authorizer => authorizer), :method => :put, :class => 'btn btn-default')
end

#services_tab_features(proxy) ⇒ Object


65
66
67
# File 'app/helpers/smart_proxies_helper.rb', line 65

def services_tab_features(proxy)
  proxy.features.where.not(name: TABBED_FEATURES).distinct.pluck("name").sort
end

#show_feature_version(feature) ⇒ Object


73
74
75
# File 'app/helpers/smart_proxies_helper.rb', line 73

def show_feature_version(feature)
  render :partial => 'smart_proxies/plugins/plugin_version', :locals => { :feature => feature }
end

#smart_proxy_title_actions(proxy, authorizer) ⇒ Object


47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/helpers/smart_proxies_helper.rb', line 47

def smart_proxy_title_actions(proxy, authorizer)
  title_actions(
    select_action_button(_("Actions"), {}, feature_actions(proxy, authorizer)),
    button_group(
      display_link_if_authorized(_("Edit"), hash_for_edit_smart_proxy_path(:id => proxy), :class => 'btn btn-default')
    ),
    button_group(
      display_delete_if_authorized(hash_for_smart_proxy_path(:id => proxy).merge(:auth_object => proxy, :authorizer => authorizer),
        :data => {:confirm => _("Delete %s?") % proxy.name}, :class => 'btn btn-default')
    )
  )
end

#tabbed_features(proxy) ⇒ Object


69
70
71
# File 'app/helpers/smart_proxies_helper.rb', line 69

def tabbed_features(proxy)
  proxy.features.where(name: TABBED_FEATURES).distinct.pluck("name").sort
end