foreman/app/helpers/hosts_helper.rb @ 82e47ae0
2f077f63 | Ohad Levy | module HostsHelper
|
|
cdf02336 | Ohad Levy | include OperatingsystemsHelper
|
|
36f93e4d | Ohad Levy | include HostsAndHostgroupsHelper
|
|
cdf02336 | Ohad Levy | ||
eafaf5f1 | Ohad Levy | def last_report_column(record)
|
|
056baf6c | Amos Benari | time = record.last_report? ? time_ago_in_words(record.last_report.getlocal) +" ago": ""
|
|
link_to_if_authorized(time,
|
|||
717899c9 | Ohad Levy | hash_for_host_report_path(:host_id => record.to_param, :id => "last"),
|
|
056baf6c | Amos Benari | last_report_tooltip(record))
|
|
05ab4c16 | Ohad Levy | end
|
|
056baf6c | Amos Benari | def last_report_tooltip record
|
|
717899c9 | Ohad Levy | opts = { :rel => "twipsy" }
|
|
if @last_reports[record.id]
|
|||
16337605 | Steve Traylen | opts.merge!( "data-original-title" => "View last report details")
|
|
717899c9 | Ohad Levy | else
|
|
056baf6c | Amos Benari | opts.merge!(:disabled => true, :class => "disabled", :onclick => 'return false')
|
|
opts.merge!("data-original-title" => "Report Already Deleted") unless record.last_report.nil?
|
|||
717899c9 | Ohad Levy | end
|
|
056baf6c | Amos Benari | opts
|
|
c439b058 | Ohad Levy | end
|
|
767bbf03 | Ohad Levy | ||
3aea8c81 | Amos Benari | # method that reformat the hostname column by adding the status icons
|
|
766e0f38 | Ohad Levy | def name_column(record)
|
|
056baf6c | Amos Benari | if record.build
|
|
82e47ae0 | Amos Benari | style ="label-info"
|
|
056baf6c | Amos Benari | label = "Pending Installation"
|
|
short = "B"
|
|||
elsif record.respond_to?(:enabled) && !record.enabled
|
|||
label = "Alerts disabled"
|
|||
style = ""
|
|||
short = "D"
|
|||
elsif record.respond_to?(:last_report) && record.last_report.nil?
|
|||
label = "No reports"
|
|||
style = ""
|
|||
short = "N"
|
|||
elsif record.no_report
|
|||
label = "Out of sync"
|
|||
82e47ae0 | Amos Benari | style = "label-warning"
|
|
056baf6c | Amos Benari | short = "S"
|
|
16885835 | Tim Speetjens | elsif record.error?
|
|
label = "Error"
|
|||
82e47ae0 | Amos Benari | style = "lable-important"
|
|
16885835 | Tim Speetjens | short = "E"
|
|
056baf6c | Amos Benari | elsif record.changes?
|
|
label = "Active"
|
|||
82e47ae0 | Amos Benari | style = "label-info"
|
|
056baf6c | Amos Benari | short = "A"
|
|
9b41cf08 | Ohad Levy | elsif record.pending?
|
|
label = "Pending"
|
|||
82e47ae0 | Amos Benari | style = "label-warning"
|
|
9b41cf08 | Ohad Levy | short = "P"
|
|
2ce2046f | Ohad Levy | else
|
|
056baf6c | Amos Benari | label = "No changes"
|
|
82e47ae0 | Amos Benari | style = "label-success"
|
|
056baf6c | Amos Benari | short = "O"
|
|
2ce2046f | Ohad Levy | end
|
|
056baf6c | Amos Benari | content_tag(:span, short, {:rel => "twipsy", :class => "label " + style, :"data-original-title" => label} ) +
|
|
82e47ae0 | Amos Benari | link_to(trunc(" #{record}",32), host_path(record))
|
|
766e0f38 | Ohad Levy | end
|
|
c439b058 | Ohad Levy | ||
72e65b31 | Ohad Levy | def days_ago time
|
|
((Time.now - time) / 1.day).round.to_i
|
|||
end
|
|||
7c0c8e06 | Ohad Levy | ||
1a51088d | Ohad Levy | def authorized?
|
|
authorized_for(:hosts, :edit) or authorized_for(:hosts, :destroy)
|
|||
end
|
|||
b09b4515 | Ohad Levy | def searching?
|
|
params[:search].empty?
|
|||
end
|
|||
1a51088d | Ohad Levy | def multiple_actions_select
|
|
actions = [
|
|||
3aea8c81 | Amos Benari | ['Select Actions', ''],
|
|
['Change Group', select_multiple_hostgroup_hosts_path],
|
|||
['Change Environment', select_multiple_environment_hosts_path],
|
|||
['Edit Parameters', multiple_parameters_hosts_path],
|
|||
['Delete Hosts', multiple_destroy_hosts_path],
|
|||
['Disable Notifications', multiple_disable_hosts_path],
|
|||
['Enable Notifications', multiple_enable_hosts_path],
|
|||
1a51088d | Ohad Levy | ]
|
|
056baf6c | Amos Benari | actions.insert(1, ['Build Hosts', multiple_build_hosts_path]) if SETTINGS[:unattended]
|
|
0f9c9a06 | Ohad Levy | actions << ['Run Puppet', multiple_puppetrun_hosts_path] if Setting[:puppetrun]
|
|
1a51088d | Ohad Levy | ||
f2bfcf40 | Amos Benari | select_tag "Multiple Actions", options_for_select(actions), :id => "Submit_multiple",
|
|
:class => "medium", :title => "Perform Actions on multiple hosts"
|
|||
1a51088d | Ohad Levy | end
|
|
69f9cb82 | Ohad Levy | def date ts=nil
|
|
return "#{time_ago_in_words ts} ago" if ts
|
|||
"N/A"
|
|||
end
|
|||
def template_path opts = {}
|
|||
67799065 | Ohad Levy | if (t = @host.configTemplate(opts))
|
|
69f9cb82 | Ohad Levy | link_to t, edit_config_template_path(t)
|
|
else
|
|||
"N/A"
|
|||
end
|
|||
end
|
|||
1a51088d | Ohad Levy | ||
52538203 | Ohad Levy | def selected? host
|
|
return false if host.nil? or not host.is_a?(Host) or session[:selected].nil?
|
|||
session[:selected].include?(host.id.to_s)
|
|||
end
|
|||
3aea8c81 | Amos Benari | def report_status_chart name, title, subtitle, data, options = {}
|
|
content_tag(:div, nil,
|
|||
{ :id => name,
|
|||
82e47ae0 | Amos Benari | :class => 'span7 host_chart',
|
|
3aea8c81 | Amos Benari | :'chart-name' => name,
|
|
:'chart-title' => title,
|
|||
:'chart-subtitle' => subtitle,
|
|||
:'chart-data-failed' => data[:failed].to_a.to_json,
|
|||
:'chart-data-failed_restart' => data[:failed_restart].to_a.to_json,
|
|||
:'chart-data-skipped' => data[:skipped].to_a.to_json,
|
|||
:'chart-data-applied' => data[:applied].to_a.to_json,
|
|||
:'chart-data-restarted' => data[:restarted].to_a.to_json
|
|||
5f0e3715 | Amos Benari | }.merge(options))
|
|
3aea8c81 | Amos Benari | end
|
|
3eecf845 | Amos Benari | ||
3aea8c81 | Amos Benari | def runtime_chart name, title, subtitle, data, options = {}
|
|
content_tag(:div, nil,
|
|||
{ :id => name,
|
|||
82e47ae0 | Amos Benari | :class => 'span7 host_chart',
|
|
3aea8c81 | Amos Benari | :'chart-name' => name,
|
|
:'chart-title' => title,
|
|||
:'chart-subtitle' => subtitle,
|
|||
:'chart-data-runtime' => data[:runtime].to_a.to_json,
|
|||
:'chart-data-config' => data[:config].to_a.to_json
|
|||
5f0e3715 | Amos Benari | }.merge(options))
|
|
3eecf845 | Amos Benari | end
|
|
fb158de8 | Amos Benari | ||
def reports_show
|
|||
return unless @host.reports.size > 0
|
|||
form_tag @host, :id => 'days_filter', :method => :get do
|
|||
017e1049 | Ohad Levy | content_tag(:span, "Reports from the last ") +
|
|
select(nil, 'range', 1..days_ago(@host.reports.first.reported_at),
|
|||
82e47ae0 | Amos Benari | {:selected => @range}, {:class=>"span1", :onchange =>"$('#days_filter').submit();$(this).disabled();"}).html_safe +
|
|
017e1049 | Ohad Levy | " days - #{@host.reports.recent(@range.days.ago).count} reports found"
|
|
fb158de8 | Amos Benari | end
|
|
bf228dd6 | Paul Kelly | end
|
|
056baf6c | Amos Benari | ||
def name_field host
|
|||
(SETTINGS[:unattended] and host.managed?) ? host.shortname : host.name
|
|||
end
|
|||
23161409 | Amos Benari | def show_templates
|
|
return unless SETTINGS[:unattended]
|
|||
return if (templates = TemplateKind.all.map{|k| @host.configTemplate(:kind => k.name)}.compact).empty?
|
|||
options = templates.map do |t|
|
|||
next if t.template_kind.name == "PXELinux" # we can't render these for now
|
|||
[t.name, url_for({:controller => 'unattended', :action => t.template_kind.name, :spoof => @host.ip})]
|
|||
end.compact
|
|||
select(nil, 'templates',options,{:include_blank => true},
|
|||
{:onchange =>"if ($('#_templates').val() == '') {return false;}; window.open($('#_templates').val(), $('#_templates option:selected').text(),[width='300',height='400',scrollbars='yes']);"})
|
|||
end
|
|||
2f077f63 | Ohad Levy | end
|