Class: Decidim::MetricChartsPresenter

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

Overview

A presenter to render metrics in pages

Instance Method Summary collapse

Instance Method Details

#highlightedObject

Public: Render a collection of primary metrics.



13
14
15
# File 'decidim-core/app/presenters/decidim/metric_charts_presenter.rb', line 13

def highlighted
  render_metrics(highlighted_metrics)
end

#highlighted_metricsObject



22
23
24
# File 'decidim-core/app/presenters/decidim/metric_charts_presenter.rb', line 22

def highlighted_metrics
  Decidim.metrics_registry.filtered(highlight: true, scope: "home")
end

#not_highlightedObject

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



18
19
20
# File 'decidim-core/app/presenters/decidim/metric_charts_presenter.rb', line 18

def not_highlighted
  render_metrics(not_highlighted_metrics)
end

#not_highlighted_metricsObject



26
27
28
# File 'decidim-core/app/presenters/decidim/metric_charts_presenter.rb', line 26

def not_highlighted_metrics
  Decidim.metrics_registry.filtered(highlight: false, scope: "home")
end

#render_charts(charts) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'decidim-core/app/presenters/decidim/metric_charts_presenter.rb', line 30

def render_charts(charts)
  safe_join(
    charts.map do |metric_manifest|
      render_metric(metric_manifest.metric_name,
                    title: I18n.t("decidim.metrics.#{metric_manifest.metric_name}.title"),
                    description: I18n.t("decidim.metrics.#{metric_manifest.metric_name}.description"),
                    download: true,
                    data: { ratio: "11:4", axis: true }).html_safe
    end
  )
end

#render_metrics(metrics) ⇒ Object



42
43
44
45
46
47
48
# File 'decidim-core/app/presenters/decidim/metric_charts_presenter.rb', line 42

def render_metrics(metrics)
  safe_join(
    metrics.map do |metric|
      render_metric(metric.metric_name, klass: metrics_class)
    end
  )
end

#view_contextObject



8
9
10
# File 'decidim-core/app/presenters/decidim/metric_charts_presenter.rb', line 8

def view_context
  @view_context ||= __getobj__.fetch(:view_context, ActionController::Base.new.view_context)
end