Project

General

Profile

Download (4.85 KB) Statistics
| Branch: | Tag: | Revision:
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
ad998ce7 Shlomi Zadok
[_("Generated at %s") % Time.zone.now.to_s(:short),
c1a8ccf1 Daniel Lobato
select_action_button(
_("Manage dashboard"), {},
link_to_function(_("Save dashboard"), "save_position('#{save_positions_widgets_path}')"),
link_to(_("Reset to default"), reset_default_widgets_path, :method => :put),
content_tag(:li, '', :class=>'divider'),
content_tag(:li, _("Restore widgets"), :class=>'nav-header', :id=>'restore_list'),
content_tag(:li, '', :class=>'divider'),
content_tag(:li, _("Add widgets"), :class=>'nav-header'),
content_tag(:li, '', :class=>'widget-add') do
widgets_to_add
end
db6d37b9 Amos Benari
)]
end

c1a8ccf1 Daniel Lobato
def removed_widgets
Dashboard::Manager.default_widgets - User.current.widgets.map(&:to_hash)
end

def widgets_to_add
return link_to(_('Nothing to add'), '#') unless removed_widgets.present?
removed_widgets.each do |removed_widget|
concat(link_to_function(_(removed_widget[:name]),
"add_widget('#{removed_widget[:name]}')"))
end
end

42117380 Tomer Brisker
def render_widget(widget)
render(:partial => widget.template, :locals => widget.data)
end

def widget_data(widget)
ae4d968e Daniel Lobato
{ :data => { :id => widget.id, :name => _(widget.name), :row => widget.row, :col => widget.col,
:sizex => widget.sizex, :sizey => widget.sizey, :hide => widget.hide } }
db6d37b9 Amos Benari
end

bfcbdbd8 Tim Speetjens
def count_reports(hosts)
870e7fcc Amos Benari
data = []
76607ed5 Ohad Levy
interval = Setting[:puppet_interval] / 10
ad998ce7 Shlomi Zadok
start = Time.zone.now - Setting[:puppet_interval].minutes
870e7fcc Amos Benari
(0..9).each do |i|
t = start + (interval.minutes * i)
4f7a4d0b David Davis
data << [Setting[:puppet_interval] - i*interval, hosts.run_distribution(t, t + interval.minutes).count]
3eecf845 Amos Benari
end
870e7fcc Amos Benari
data
3eecf845 Amos Benari
end

5f029ed6 Daniel Lobato
def render_overview(report, options = {})
3a124d99 Amos Benari
data = [{:label=>_('Active'), :data => report[:active_hosts_ok_enabled],:color => report_color[:active_hosts_ok_enabled]},
{:label=>_('Error'), :data =>report[:bad_hosts_enabled], :color => report_color[:bad_hosts_enabled]},
{:label=>_('OK'), :data =>report[:ok_hosts_enabled],:color => report_color[:ok_hosts_enabled]},
{:label=>_('Pending changes'), :data =>report[:pending_hosts_enabled],:color => report_color[:pending_hosts_enabled]},
{:label=>_('Out of sync'), :data =>report[:out_of_sync_hosts_enabled],:color => report_color[:out_of_sync_hosts_enabled]},
{:label=>_('No report'), :data =>report[:reports_missing],:color => report_color[:reports_missing]},
{:label=>_('Notification disabled'), :data =>report[:disabled_hosts],:color => report_color[:disabled_hosts]}]
2af890f2 Amos Benari
flot_pie_chart 'overview', _('Host Configuration Status'), data, options.merge(:search => "search_by_legend")
3eecf845 Amos Benari
end

5f029ed6 Daniel Lobato
def render_run_distribution(hosts, options = {})
870e7fcc Amos Benari
data = count_reports(hosts)
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)
017e1049 Ohad Levy
search += " and #{params[:search]}" unless params[:search].blank?
3a124d99 Amos Benari
content_tag :li do
content_tag(:i, raw('&nbsp;'), :class=>'label', :style => "background-color:" + report_color[counter]) +
raw('&nbsp;')+
link_to(name, hosts_path(:search => search),:class=>"dashboard-links") +
content_tag(:h4,@report[counter])
end
017e1049 Ohad Levy
end

2fc0a023 Greg Sutcliffe
def latest_events
40b834e3 Amos Benari
# 6 reports + header fits the events box nicely...
9f1c910a Ohad Levy
Report.authorized(:view_reports).my_reports.interesting.search_for('reported > "7 days ago"').limit(6).includes(:host)
2fc0a023 Greg Sutcliffe
end

def translated_header(shortname, longname)
"<th><span class='small' title='' data-original-title='#{longname}'>#{shortname}</span></th>"
end

def latest_headers
string = "<th>#{_("Host")}</th>"
# 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
bfbf7ed8 Lukas Zapletal
end