foreman/app/helpers/hosts_helper.rb @ c45a0014
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)
|
|
7767028b | Ohad Levy | return nil if record.last_report.nil?
|
|
time = time_ago_in_words(record.last_report.getlocal)
|
|||
7875667c | Ohad Levy | report_icon(record) +
|
|
c45a0014 | Ohad Levy | link_to_if_authorized(time, hash_for_host_report_path(:host_id => record.to_param, :id => "last"), :disabled => !@last_reports[record.id])
|
|
c439b058 | Ohad Levy | end
|
|
767bbf03 | Ohad Levy | ||
d5707b63 | Ohad Levy | # method that reformat the hostname column by adding the status icons
|
|
766e0f38 | Ohad Levy | def name_column(record)
|
|
2ce2046f | Ohad Levy | if record.build and not record.installed_at.nil?
|
|
image ="attention_required.png"
|
|||
title = "Pending Installation"
|
|||
9fd7478e | Paul Kelly | elsif (os = @fact_kernels.select{|h| h.host_id == record.id}.first.value rescue nil).nil?
|
|
2ce2046f | Ohad Levy | image = "warning.png"
|
|
title = "No Inventory Data"
|
|||
else
|
|||
image = "#{os}.jpg"
|
|||
title = os
|
|||
end
|
|||
3446abb6 | Ohad Levy | image_tag("hosts/#{image}", :size => "18x18", :title => title) +
|
|
72e65b31 | Ohad Levy | link_to(record.shortname, 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 = [
|
|||
['Change Group', select_multiple_hostgroup_hosts_path],
|
|||
['Change Environment', select_multiple_environment_hosts_path],
|
|||
['Edit Parameters', multiple_parameters_hosts_path],
|
|||
['Destroy Hosts', multiple_destroy_hosts_path],
|
|||
['Disable Notifications', multiple_disable_hosts_path],
|
|||
['Enable Notifications', multiple_enable_hosts_path],
|
|||
]
|
|||
actions << ['Build Hosts', multiple_build_hosts_path] if SETTINGS[:unattended]
|
|||
095c11d3 | Amos Benari | select_tag "Multiple Actions", options_for_select(actions.sort), :id => "Submit_multiple", :onchange => 'submit_multiple(this.value)'
|
|
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 = {}
|
|||
if t = @host.configTemplate(opts)
|
|||
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
|
|||
668d432f | Ohad Levy | def update_details_from_hostgroup
|
|
return nil unless @host.new_record?
|
|||
remote_function(:url => { :action => "process_hostgroup" },
|
|||
8ba2e00a | Ohad Levy | :method => :post, :loading => "$('#indicator1').show()",
|
|
:complete => "$('#indicator1').hide()",
|
|||
668d432f | Ohad Levy | :with => "'hostgroup_id=' + value")
|
|
end
|
|||
3eecf845 | Amos Benari | ||
def render_report_status_chart name, title, subtitle, data
|
|||
function = <<-EOF
|
|||
$(function() {
|
|||
1baed2e3 | Amos Benari | Highcharts.setOptions({
|
|
global: {
|
|||
useUTC: false
|
|||
}
|
|||
});
|
|||
3eecf845 | Amos Benari | chart = new Highcharts.Chart({
|
|
chart: {
|
|||
renderTo: '#{name}',
|
|||
defaultSeriesType: 'line',
|
|||
zoomType: 'x',
|
|||
margin: [ 50, 50, 90, 50],
|
|||
borderWidth: 2,
|
|||
backgroundColor: {
|
|||
linearGradient: [0, 0, 0, 300],
|
|||
stops: [
|
|||
[0, '#ffffff'],
|
|||
[1, '#EDF6FC']
|
|||
]}
|
|||
},
|
|||
title: {
|
|||
text: '#{title}',
|
|||
x: -20 //center
|
|||
},
|
|||
subtitle: {
|
|||
text: '#{subtitle}',
|
|||
x: -20
|
|||
},
|
|||
credits: {
|
|||
enabled: false,
|
|||
},
|
|||
xAxis: {
|
|||
type: 'datetime',
|
|||
labels: {
|
|||
rotation: -45,
|
|||
align: 'right',
|
|||
style: {
|
|||
font: 'normal 13px Verdana, sans-serif'
|
|||
}
|
|||
}
|
|||
},
|
|||
yAxis: {
|
|||
title: {
|
|||
text: 'Number of Events'
|
|||
},
|
|||
min: 0
|
|||
},
|
|||
tooltip: {
|
|||
formatter: function() {
|
|||
return '<b>'+ this.series.name + ': ' + this.y + '</b><br/>'+
|
|||
Highcharts.dateFormat('%e. %b %H:%M', this.x) ;
|
|||
}
|
|||
},
|
|||
legend: {
|
|||
layout: 'horizontal',
|
|||
align: 'bottom',
|
|||
verticalAlign: 'bottom',
|
|||
x: 10,
|
|||
y: -10,
|
|||
borderWidth: 0
|
|||
},
|
|||
259eb5cc | Amos Benari | colors: [
|
|
'#AA4643',
|
|||
'#AA4643',
|
|||
'#AA4643',
|
|||
'#89A54E',
|
|||
'#4572A7',
|
|||
'#80699B',
|
|||
'#3D96AE',
|
|||
'#DB843D',
|
|||
'#92A8CD',
|
|||
'#A47D7C',
|
|||
'#B5CA92'
|
|||
],
|
|||
3eecf845 | Amos Benari | series: [{
|
|
name: 'Failed',
|
|||
data: [ #{data[:failed].join(' ,')} ]
|
|||
}, {
|
|||
name: 'Failed restarts',
|
|||
data: [#{data[:failed_restarts].join(' ,')}]
|
|||
259eb5cc | Amos Benari | }, {
|
|
name: 'Skipped',
|
|||
data: [#{data[:skipped].join(' ,')}]
|
|||
3eecf845 | Amos Benari | }, {
|
|
name: 'Applied',
|
|||
data: [#{data[:applied].join(' ,')}]
|
|||
}, {
|
|||
name: 'Restarted',
|
|||
data: [#{data[:restarted].join(' ,')}]
|
|||
}]
|
|||
});
|
|||
});
|
|||
EOF
|
|||
javascript_tag(function)
|
|||
end
|
|||
def render_runtime_chart name, title, subtitle, data
|
|||
function = <<-EOF
|
|||
$(function() {
|
|||
chart = new Highcharts.Chart({
|
|||
chart: {
|
|||
renderTo: '#{name}',
|
|||
defaultSeriesType: 'area',
|
|||
zoomType: 'x',
|
|||
margin: [ 50, 50, 90, 50],
|
|||
borderWidth: 2,
|
|||
backgroundColor: {
|
|||
linearGradient: [0, 0, 0, 300],
|
|||
stops: [
|
|||
[0, '#ffffff'],
|
|||
[1, '#EDF6FC']
|
|||
]}
|
|||
},
|
|||
title: {
|
|||
text: '#{title}',
|
|||
x: -20 //center
|
|||
},
|
|||
subtitle: {
|
|||
text: '#{subtitle}',
|
|||
x: -20
|
|||
},
|
|||
credits: {
|
|||
enabled: false,
|
|||
},
|
|||
xAxis: {
|
|||
type: 'datetime',
|
|||
labels: {
|
|||
rotation: -45,
|
|||
align: 'right',
|
|||
style: {
|
|||
font: 'normal 13px Verdana, sans-serif'
|
|||
}
|
|||
}
|
|||
},
|
|||
yAxis: {
|
|||
title: {
|
|||
text: 'Time in Seconds'
|
|||
},
|
|||
min: 0
|
|||
},
|
|||
tooltip: {
|
|||
formatter: function() {
|
|||
return '<b>'+ this.series.name + ': ' + this.y + '</b><br/>'+
|
|||
Highcharts.dateFormat('%e. %b %H:%M', this.x) ;
|
|||
}
|
|||
},
|
|||
legend: {
|
|||
layout: 'horizontal',
|
|||
align: 'bottom',
|
|||
verticalAlign: 'bottom',
|
|||
x: 10,
|
|||
y: -10,
|
|||
borderWidth: 0
|
|||
},
|
|||
plotOptions: {
|
|||
area: {
|
|||
lineWidth: 1,
|
|||
stacking: 'normal',
|
|||
marker: {
|
|||
enabled: false,
|
|||
symbol: 'circle',
|
|||
radius: 2,
|
|||
states: {
|
|||
hover: {
|
|||
enabled: true
|
|||
}
|
|||
}
|
|||
}
|
|||
}
|
|||
},
|
|||
series: [{
|
|||
name: 'Runtime',
|
|||
data: [ #{data[:runtime].join(' ,')} ]
|
|||
}, {
|
|||
name: 'Config Retrieval',
|
|||
data: [#{data[:config].join(' ,')}]
|
|||
}]
|
|||
});
|
|||
});
|
|||
EOF
|
|||
javascript_tag(function)
|
|||
bf228dd6 | Paul Kelly | end
|
|
2f077f63 | Ohad Levy | end
|