Class: Decidim::HomeStatsPresenter

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
decidim-core/app/presenters/decidim/home_stats_presenter.rb

Overview

A presenter to render statistics in the homepage.

Instance Method Summary collapse

Instance Method Details

#highlightedObject

Public: Render a collection of primary stats.



11
12
13
14
15
16
17
18
19
20
21
# File 'decidim-core/app/presenters/decidim/home_stats_presenter.rb', line 11

def highlighted
  highlighted_stats = Decidim.stats.only([:users_count, :processes_count]).with_context(organization).map { |name, data| [name, data] }
  highlighted_stats.concat(global_stats(priority: StatsRegistry::HIGH_PRIORITY))
  highlighted_stats.concat(component_stats(priority: StatsRegistry::HIGH_PRIORITY))
  highlighted_stats = highlighted_stats.reject(&:empty?)
  highlighted_stats = highlighted_stats.reject { |_name, data| data.zero? }

  highlighted_stats.map do |name, data|
    { stat_title: name, stat_number: data }
  end
end

#not_highlightedObject

Public: Render a collection of stats that are not primary.



24
25
26
27
28
29
30
31
32
33
# File 'decidim-core/app/presenters/decidim/home_stats_presenter.rb', line 24

def not_highlighted
  not_highlighted_stats = global_stats(priority: StatsRegistry::MEDIUM_PRIORITY)
  not_highlighted_stats.concat(component_stats(priority: StatsRegistry::MEDIUM_PRIORITY))
  not_highlighted_stats = not_highlighted_stats.reject(&:empty?)
  not_highlighted_stats = not_highlighted_stats.reject { |_name, data| data.zero? }

  not_highlighted_stats.map do |name, data|
    { stat_title: name, stat_number: data }
  end
end

#organizationObject



6
7
8
# File 'decidim-core/app/presenters/decidim/home_stats_presenter.rb', line 6

def organization
  __getobj__.fetch(:organization)
end