Module: DiscoveredHostsHelper
- Defined in:
- app/helpers/discovered_hosts_helper.rb
Instance Method Summary collapse
- #attach_flags(interface) ⇒ Object
- #authorized_for_edit_destroy? ⇒ Boolean
- #disc_report_column(record) ⇒ Object
- #discovered_hosts_title_actions(host) ⇒ Object
- #discovery_attribute(host, attr, default_value = _('N/A')) ⇒ Object
- #discovery_doc_version ⇒ Object
- #discovery_status_icon(host) ⇒ Object
- #host_path(host) ⇒ Object
- #host_taxonomy_select(f, taxonomy) ⇒ Object
- #multiple_discovered_hosts_actions_select ⇒ Object
- #provision_button(host, authorization_options) ⇒ Object
- #turn_zero_to_not_available(value) ⇒ Object
Instance Method Details
#attach_flags(interface) ⇒ Object
2 3 4 5 6 7 |
# File 'app/helpers/discovered_hosts_helper.rb', line 2 def attach_flags(interface) flags = "" flags += "flag-primary " if interface[:primary] flags += "flag-provision" if interface[:provision] flags end |
#authorized_for_edit_destroy? ⇒ Boolean
50 51 52 53 |
# File 'app/helpers/discovered_hosts_helper.rb', line 50 def (:controller => :discovered_hosts, :action => :edit) or (:controller => :discovered_hosts, :action => :destroy) end |
#disc_report_column(record) ⇒ Object
9 10 11 |
# File 'app/helpers/discovered_hosts_helper.rb', line 9 def disc_report_column(record) record.last_report? ? date_time_relative(record.last_report.getlocal) : "" end |
#discovered_hosts_title_actions(host) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/helpers/discovered_hosts_helper.rb', line 13 def discovered_hosts_title_actions(host) actions = [[_('Auto Provision'), hash_for_auto_provision_discovered_host_path(:id => host).merge(:auth_object => host, :permission => :auto_provision_discovered_hosts), :method => :post]] actions << [_('Refresh facts') ,hash_for_refresh_facts_discovered_host_path(:id => host).merge(:auth_object => host, :permission => :edit_discovered_hosts)] actions << [_('Reboot') ,hash_for_reboot_discovered_host_path(:id => host).merge(:auth_object => host, :permission => :edit_discovered_hosts), :method => :put] title_actions( ( link_to(_("Back"), :back, :class => "btn btn-default") ), ( _("Select Action"), {}, (host, hash_for_edit_discovered_host_path(:id => host)), actions.map { |action| (action[0] , action[1], action[2] || {}) }.flatten ), ( (hash_for_discovered_host_path(:id => host).merge(:auth_object => host, :permission => :destroy_discovered_hosts), :class => "btn btn-default", :data => { :confirm => _('Delete %s?') % host.name }) ) ) end |
#discovery_attribute(host, attr, default_value = _('N/A')) ⇒ Object
46 47 48 |
# File 'app/helpers/discovered_hosts_helper.rb', line 46 def discovery_attribute(host, attr, default_value = _('N/A')) host.try(:discovery_attribute_set).try(attr) || default_value end |
#discovery_doc_version ⇒ Object
108 109 110 |
# File 'app/helpers/discovered_hosts_helper.rb', line 108 def discovery_doc_version Foreman::Plugin.find(:foreman_discovery).version.scan(/\d+\.\d+/).first end |
#discovery_status_icon(host) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/helpers/discovered_hosts_helper.rb', line 55 def discovery_status_icon(host) if host.created_at > 1.day.ago status_glyph = 'pficon-on-running' = _('New in the last 24 hours') status_color = '#0088ce' elsif host.last_report.present? && host.last_report < 7.days.ago status_glyph = 'pficon-paused' = _('Not reported in more than 7 days') status_color = '#ec7a08' else status_glyph = 'pficon-on' = _('Reported in the last 7 days') status_color = '#72767b' end "<span class='glyphicon #{status_glyph}' style='color: #{status_color}' title='#{}'></span>".html_safe end |
#host_path(host) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/helpers/discovered_hosts_helper.rb', line 96 def host_path(host) return discovered_host_path(host) if controller_name == 'discovered_hosts' # This is a hack to fix the hostgroup selection on the discovered host edit page # The hostgroup onChange action is replacing the form url from `/discovered_hosts/:id` # to `/hosts/:id``, which is not correct (in this case) and it breaks the form submission return discovered_host_path(host) if controller_name == 'hosts' && action_name == 'process_hostgroup' && Host::Discovered.find_by(id: host[:id]) super end |
#host_taxonomy_select(f, taxonomy) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/helpers/discovered_hosts_helper.rb', line 74 def host_taxonomy_select(f, taxonomy) # Add hidden field with taxonomy value to be updated by the form on submit tax_html = super tax_id = "#{taxonomy.to_s.downcase}_id" selected_taxonomy = params[:host][tax_id] if params[:host] if @override_taxonomy && selected_taxonomy hidden_tax = f.hidden_field tax_id.to_sym, :value => selected_taxonomy tax_html += hidden_tax end tax_html end |
#multiple_discovered_hosts_actions_select ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/helpers/discovered_hosts_helper.rb', line 28 def multiple_discovered_hosts_actions_select actions = [[_('Auto Provision'), multiple_auto_provision_discovered_hosts_path, hash_for_multiple_auto_provision_discovered_hosts_path]] actions << [_('Reboot'), multiple_reboot_discovered_hosts_path, hash_for_multiple_reboot_discovered_hosts_path] actions << [_('Assign Organization'), select_multiple_organization_discovered_hosts_path, hash_for_select_multiple_organization_discovered_hosts_path] actions << [_('Assign Location'), select_multiple_location_discovered_hosts_path, hash_for_select_multiple_location_discovered_hosts_path] actions << [_('Delete'), multiple_destroy_discovered_hosts_path, hash_for_multiple_destroy_discovered_hosts_path] ( _("Select Action"), {:id => 'submit_multiple'}, actions.map do |action| link_to_function(action[0], "tfm.hosts.table.buildModal(this, '#{action[1]}')", :'data-dialog-title' => _("%s - The following hosts are about to be changed") % action[0]) if (action[2]) end.flatten ) end |
#provision_button(host, authorization_options) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'app/helpers/discovered_hosts_helper.rb', line 86 def (host, ) return '' unless () link_to( _('Provision'), "#", :data => { :toggle => 'modal', :target => "#fixedPropertiesSelector-#{host.id}"}) end |
#turn_zero_to_not_available(value) ⇒ Object
42 43 44 |
# File 'app/helpers/discovered_hosts_helper.rb', line 42 def turn_zero_to_not_available(value) (value == 0) ? 'N/A' : value end |