Module: ForemanHostReports::ReportsDashboardHelper
- Defined in:
- app/helpers/foreman_host_reports/reports_dashboard_helper.rb
Instance Method Summary collapse
- #host_reports_get_overview(options = {}) ⇒ Object
- #host_reports_report_color ⇒ Object
- #host_reports_searchable_links(name, search, counter, format) ⇒ Object
- #host_reports_translated_header(shortname, longname) ⇒ Object
- #latest_reports ⇒ Object
- #latest_reports? ⇒ Boolean
Instance Method Details
#host_reports_get_overview(options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/helpers/foreman_host_reports/reports_dashboard_helper.rb', line 21 def host_reports_get_overview( = {}) format = [:format] state_labels = { change_hosts: _('Change'), failure_hosts: _('Failure'), nochange_hosts: _('No Change'), disabled_hosts: _('Disabled alerts'), } counter = {} total = 0 data = state_labels.map do |key, label| counter.store(key, send(key, format)) total = counter[key] + total [label, counter[key], host_reports_report_color[key]] end { data: data, searchUrl: hosts_path(search: '~VAL~'), title: { primary: _("#{(counter[:failure_hosts].fdiv(total) * 100).to_i}%"), secondary: state_labels[:failure_hosts] }, searchFilters: state_labels.each_with_object({}) do |(key, filter), filters| filters[filter] = counter[key] end, } end |
#host_reports_report_color ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'app/helpers/foreman_host_reports/reports_dashboard_helper.rb', line 12 def host_reports_report_color { :change_hosts => "#4572A7", :failure_hosts => "#AA4643", :nochange_hosts => "#DB843D", :disabled_hosts => "#92A8CD", } end |
#host_reports_searchable_links(name, search, counter, format) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'app/helpers/foreman_host_reports/reports_dashboard_helper.rb', line 3 def host_reports_searchable_links(name, search, counter, format) content_tag :li, :style => "margin-bottom: 5px" do content_tag(:span, sanitize(' '), :class => 'label', :style => "background-color: #{host_reports_report_color[counter]}") + sanitize(' ') + link_to(name, hosts_path(:search => search), :class => "dashboard-links") + content_tag(:span, send(counter, format), class: 'pull-right') end end |
#host_reports_translated_header(shortname, longname) ⇒ Object
57 58 59 |
# File 'app/helpers/foreman_host_reports/reports_dashboard_helper.rb', line 57 def host_reports_translated_header(shortname, longname) "<th style='width:85px; class='ca'><span class='small' title='' data-original-title='#{longname}'>#{shortname}</span></th>" end |
#latest_reports ⇒ Object
46 47 48 49 50 51 |
# File 'app/helpers/foreman_host_reports/reports_dashboard_helper.rb', line 46 def latest_reports HostReport.(:view_host_reports).my_reports .reorder(:reported_at => :desc) .limit(9) .preload(:host) end |
#latest_reports? ⇒ Boolean
53 54 55 |
# File 'app/helpers/foreman_host_reports/reports_dashboard_helper.rb', line 53 def latest_reports? latest_reports.limit(1).present? end |