Sha256: 0083fbd9ab5dfddc2f12c4ecd035293d900a00768972a99a66f828667360d832

Contents?: true

Size: 800 Bytes

Versions: 2

Compression:

Stored size: 800 Bytes

Contents

# frozen_string_literal: true

require "chartkick"
require "chartkick/helper"

module Decidim
  module ComparativeStats
    class MetricPiechartsCell < Decidim::ViewModel
      include Chartkick::Helper

      def show
        return unless model

        render :show
      end

      def endpoints
        model
      end

      def title(name)
        return t "decidim.comparative_stats.metrics.users.title" if name == "users"

        t "decidim.metrics.#{name}.title"
      end

      def metrics
        metrics = {}
        endpoints.each do |endpoint|
          endpoint.api.fetch_global_metrics.data.metrics.each do |item|
            metrics[item.name] ||= {}
            metrics[item.name][endpoint.name] = item.count
          end
        end
        metrics
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
decidim-comparative_stats-1.1.0 app/cells/decidim/comparative_stats/metric_piecharts_cell.rb
decidim-comparative_stats-1.0.1 app/cells/decidim/comparative_stats/metric_piecharts_cell.rb