foreman/app/helpers/dashboard_helper.rb @ bde92a1e
90b70658 | Ohad Levy | module DashboardHelper
|
|
a0c7b5ae | Tomer Brisker | def add_to_dashboard(widget)
|
|
button_to(_('Add to dashboard'), widgets_path(:widget => widget), :method => :post)
|
|||
end
|
|||
db6d37b9 | Amos Benari | def dashboard_actions
|
|
313979b9 | Stephen Benjamin | [
|
|
d738d2c0 | Marek Hulan | _("Generated at %s") % date_time_absolute(Time.zone.now),
|
|
313979b9 | Stephen Benjamin | select_action_button(
|
|
_('Manage'), {},
|
|||
2b81dfe4 | Tomer Brisker | link_to_function(_('Save positions'), "save_position('#{save_positions_widgets_path}')"),
|
|
313979b9 | Stephen Benjamin | link_to(_('Reset to default'), reset_default_widgets_path, :method => :put),
|
|
9d43fc71 | Michael Moll | content_tag(:li, '', :class => 'divider'),
|
|
content_tag(:li, _("Add widgets"), :class => 'nav-header'),
|
|||
content_tag(:li, '', :class => 'widget-add') do
|
|||
313979b9 | Stephen Benjamin | widgets_to_add
|
|
end
|
|||
),
|
|||
32a85509 | Shlomi Zadok | auto_refresh_button(:defaults_to => true),
|
|
documentation_button
|
|||
313979b9 | Stephen Benjamin | ]
|
|
db6d37b9 | Amos Benari | end
|
|
24fc15c5 | Daniel Lobato | def removed_widgets
|
|
348ec9c0 | Sebastian Gräßl | user_widgets = User.current.widgets.pluck(:name)
|
|
Dashboard::Manager.default_widgets.reject do |widget|
|
|||
user_widgets.include?(widget[:name])
|
|||
end
|
|||
24fc15c5 | Daniel Lobato | end
|
|
def widgets_to_add
|
|||
return link_to(_('Nothing to add'), '#') unless removed_widgets.present?
|
|||
348ec9c0 | Sebastian Gräßl | removed_widgets.sort_by {|w| w[:name] }.each do |removed_widget|
|
|
24fc15c5 | Daniel Lobato | concat(link_to_function(_(removed_widget[:name]),
|
|
"add_widget('#{removed_widget[:name]}')"))
|
|||
end
|
|||
end
|
|||
42117380 | Tomer Brisker | def widget_data(widget)
|
|
9d43fc71 | Michael Moll | { :data => { :id => widget.id, :name => _(widget.name), :row => widget.row, :col => widget.col,
|
|
2b81dfe4 | Tomer Brisker | :sizex => widget.sizex, :sizey => widget.sizey } }
|
|
db6d37b9 | Amos Benari | end
|
|
348ec9c0 | Sebastian Gräßl | def count_reports(hosts, options = {})
|
|
870e7fcc | Amos Benari | data = []
|
|
348ec9c0 | Sebastian Gräßl | interval_setting = report_origin_interval_setting(options[:origin])
|
|
interval = interval_setting / 10
|
|||
start = Time.zone.now - interval_setting.minutes
|
|||
870e7fcc | Amos Benari | (0..9).each do |i|
|
|
t = start + (interval.minutes * i)
|
|||
9d43fc71 | Michael Moll | data << [interval_setting - i * interval, hosts.run_distribution(t, t + interval.minutes).count]
|
|
3eecf845 | Amos Benari | end
|
|
870e7fcc | Amos Benari | data
|
|
3eecf845 | Amos Benari | end
|
|
45d1359a | matanw | def get_overview_json(report, options = {})
|
|
[
|
|||
[_('Active'), report[:active_hosts_ok_enabled], report_color[:active_hosts_ok_enabled]],
|
|||
[_('Error'), report[:bad_hosts_enabled], report_color[:bad_hosts_enabled]],
|
|||
[_('OK'), report[:ok_hosts_enabled], report_color[:ok_hosts_enabled]],
|
|||
[_('Pending changes'), report[:pending_hosts_enabled], report_color[:pending_hosts_enabled]],
|
|||
[_('Out of sync'), report[:out_of_sync_hosts_enabled], report_color[:out_of_sync_hosts_enabled]],
|
|||
[_('No report'), report[:reports_missing], report_color[:reports_missing]],
|
|||
[_('Notification disabled'), report[:disabled_hosts], report_color[:disabled_hosts]]
|
|||
].to_json
|
|||
3eecf845 | Amos Benari | end
|
|
5f029ed6 | Daniel Lobato | def render_run_distribution(hosts, options = {})
|
|
348ec9c0 | Sebastian Gräßl | data = count_reports(hosts, options)
|
|
3dfb6e4c | Dominic Cleal | flot_bar_chart("run_distribution", _("Minutes Ago"), _("Number Of Clients"), data, options)
|
|
3eecf845 | Amos Benari | end
|
|
017e1049 | Ohad Levy | ||
5f029ed6 | Daniel Lobato | def searchable_links(name, search, counter)
|
|
85021506 | Michael Moll | search += " and #{@data.filter}" if @data.filter.present?
|
|
3a124d99 | Amos Benari | content_tag :li do
|
|
9d43fc71 | Michael Moll | content_tag(:span, raw(' '), :class => 'label', :style => "background-color:" + report_color[counter]) +
|
|
raw(' ') +
|
|||
link_to(name, hosts_path(:search => search), :class => "dashboard-links") +
|
|||
1d551e51 | Tomer Brisker | content_tag(:h4, @data.report[counter])
|
|
3a124d99 | Amos Benari | end
|
|
017e1049 | Ohad Levy | end
|
|
2fc0a023 | Greg Sutcliffe | def translated_header(shortname, longname)
|
|
2ac8d7ba | Tomer Brisker | "<th class='ca'><span class='small' title='' data-original-title='#{longname}'>#{shortname}</span></th>"
|
|
2fc0a023 | Greg Sutcliffe | end
|
|
def latest_headers
|
|||
f4459c11 | David Davis | string = "<th>#{_('Host')}</th>"
|
|
2fc0a023 | Greg Sutcliffe | # TRANSLATORS: initial character of Applied
|
|
0ee000ea | Dominic Cleal | string += translated_header(s_('Applied|A'), _('Applied'))
|
|
2fc0a023 | Greg Sutcliffe | # TRANSLATORS: initial character of Restarted
|
|
0ee000ea | Dominic Cleal | string += translated_header(s_('Restarted|R'), _('Restarted'))
|
|
2fc0a023 | Greg Sutcliffe | # TRANSLATORS: initial character of Failed
|
|
0ee000ea | Dominic Cleal | string += translated_header(s_('Failed|F'), _('Failed'))
|
|
b88565ec | Dominic Cleal | # TRANSLATORS: initial characters of Failed Restarts
|
|
0ee000ea | Dominic Cleal | string += translated_header(s_('Failed Restarts|FR'), _('Failed Restarts'))
|
|
2fc0a023 | Greg Sutcliffe | # TRANSLATORS: initial character of Skipped
|
|
0ee000ea | Dominic Cleal | string += translated_header(s_('Skipped|S'), _('Skipped'))
|
|
2fc0a023 | Greg Sutcliffe | # TRANSLATORS: initial character of Pending
|
|
0ee000ea | Dominic Cleal | string += translated_header(s_('Pending|P'), _('Pending'))
|
|
2fc0a023 | Greg Sutcliffe | ||
string.html_safe
|
|||
end
|
|||
3a124d99 | Amos Benari | def report_color
|
|
{
|
|||
96144a47 | Daniel Lobato | :active_hosts_ok_enabled => "#4572A7",
|
|
:bad_hosts_enabled => "#AA4643",
|
|||
:ok_hosts_enabled => "#89A54E",
|
|||
:pending_hosts_enabled => "#80699B",
|
|||
:out_of_sync_hosts_enabled => "#3D96AE",
|
|||
:reports_missing => "#DB843D",
|
|||
:disabled_hosts => "#92A8CD"
|
|||
3a124d99 | Amos Benari | }
|
|
end
|
|||
3a555277 | Tom Caspy | ||
def auto_refresh_button(options = {})
|
|||
on = options[:defaults_to] ? "on" : "off"
|
|||
if params[:auto_refresh].present?
|
|||
da9865b8 | Michael Moll | on = (params[:auto_refresh] == "0") ? "off" : "on"
|
|
3a555277 | Tom Caspy | end
|
|
if on == "on"
|
|||
tooltip = _("Auto refresh on")
|
|||
else
|
|||
tooltip = _("Auto refresh off")
|
|||
end
|
|||
32a85509 | Shlomi Zadok | link_to(icon_text("refresh"),
|
|
da9865b8 | Michael Moll | {:auto_refresh => ((on == "on") ? "0" : "1")},
|
|
bb25ebe6 | Tomer Brisker | { :'data-original-title' => tooltip, :rel => 'twipsy', :class => "#{on} auto-refresh btn btn-group btn-default"})
|
|
3a555277 | Tom Caspy | end
|
|
348ec9c0 | Sebastian Gräßl | ||
def widget_class_name(widget)
|
|||
settings = widget.data[:settings]
|
|||
if settings && settings[:class_name]
|
|||
settings[:class_name]
|
|||
else
|
|||
widget.name
|
|||
end
|
|||
end
|
|||
c07e531e | Sebastian Gräßl | def search_filter_with_origin(filter, origin, within_interval = false)
|
|
interval_setting = report_origin_interval_setting(origin)
|
|||
additional_filters = []
|
|||
additional_filters << "origin = #{origin}" if origin
|
|||
additional_filters << "last_report #{within_interval ? '<' : '>'} \"#{interval_setting} minutes ago\"" if out_of_sync_enabled?(origin)
|
|||
(additional_filters + [filter]).join(' and ')
|
|||
348ec9c0 | Sebastian Gräßl | end
|
|
def report_origin_interval_setting(origin)
|
|||
if origin && origin != 'All'
|
|||
c07e531e | Sebastian Gräßl | interval_setting = origin_setting(origin, 'interval')
|
|
348ec9c0 | Sebastian Gräßl | end
|
|
interval_setting ||= Setting[:outofsync_interval]
|
|||
interval_setting.to_i
|
|||
end
|
|||
c07e531e | Sebastian Gräßl | ||
def out_of_sync_enabled?(origin)
|
|||
setting = origin_setting(origin, 'out_of_sync_disabled')
|
|||
setting.nil? ? true : !setting
|
|||
end
|
|||
bde92a1e | Timo Goebel | def host_build_status_icon(host)
|
|
if host.token_expired?
|
|||
icon = 'hourglass-o'
|
|||
icon_kind = 'fa'
|
|||
icon_class = 'text-danger'
|
|||
label = _('Token expired')
|
|||
elsif host.build_errors.present?
|
|||
icon = 'error-circle-o'
|
|||
icon_kind = 'pficon'
|
|||
icon_class = ''
|
|||
label = _('Build errors')
|
|||
else
|
|||
icon = 'in-progress'
|
|||
icon_kind = 'pficon'
|
|||
icon_class = ''
|
|||
label = _('Build in progress')
|
|||
end
|
|||
icon_text(icon, '', kind: icon_kind, title: label, class: icon_class)
|
|||
end
|
|||
c07e531e | Sebastian Gräßl | private
|
|
def origin_setting(origin, name)
|
|||
return nil unless origin
|
|||
Setting[:"#{origin.downcase}_#{name}"]
|
|||
end
|
|||
bfbf7ed8 | Lukas Zapletal | end
|