Module: Workarea::Admin::InsightsHelper

Defined in:
app/helpers/workarea/admin/insights_helper.rb

Instance Method Summary collapse

Instance Method Details



30
31
32
# File 'app/helpers/workarea/admin/insights_helper.rb', line 30

def current_popular_searches
  @current_popular_searches ||= Workarea::Insights::PopularSearches.current.results.take(5)
end

#insights_number_to_percentage(number, options = {}) ⇒ Object



13
14
15
16
17
18
# File 'app/helpers/workarea/admin/insights_helper.rb', line 13

def insights_number_to_percentage(number, options = {})
  number_to_percentage(
    number,
    options.reverse_merge(precision: number.zero? || number.abs > 5 ? 0 : 2)
  )
end

#insights_path_for(model) ⇒ Object



4
5
6
7
8
9
10
11
# File 'app/helpers/workarea/admin/insights_helper.rb', line 4

def insights_path_for(model)
  url_for(
    action: 'insights',
    controller: model.model_name.route_key,
    id: model,
    only_path: true
  )
end

#insights_trend_icon(number) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'app/helpers/workarea/admin/insights_helper.rb', line 20

def insights_trend_icon(number)
  return nil if number.blank? || number.zero?

  if number > 0
    (:span, '⬆', style: 'color: green;') # TODO FIXME
  else
    (:span, '⬇', style: 'color: red;') # TODO FIXME
  end
end

#sparkline_analytics_data_for(data) ⇒ Object



34
35
36
37
38
39
# File 'app/helpers/workarea/admin/insights_helper.rb', line 34

def sparkline_analytics_data_for(data)
  return [0] if data.blank?
  return Array.new(data.size, 0) if data.max.zero?

  data.map { |p| [(p / data.max.to_f * 10).round - 1, 0].max }
end