Sha256: efc9bf73d9dc3ee7886558b5796c2c3d31da0d20b85628d2098cf60e5b204cfb

Contents?: true

Size: 1.87 KB

Versions: 4

Compression:

Stored size: 1.87 KB

Contents

# frozen_string_literal: true

module Decidim
  module Accountability
    # Exposes the result resource so users can view them
    class ResultsController < Decidim::Accountability::ApplicationController
      include FilterResource
      helper Decidim::WidgetUrlsHelper

      helper_method :results, :result, :stats_calculator, :first_class_categories, :category, :progress_calculator, :count_calculator, :current_scope

      private

      def results
        parent_id = params[:parent_id].presence
        @results ||= search.results.where(parent_id: parent_id).page(params[:page]).per(12)
      end

      def result
        @result ||= Result.includes(:timeline_entries).where(feature: current_feature).find(params[:id])
      end

      def stats_calculator
        @stats_calculator ||= ResultStatsCalculator.new(result)
      end

      def search_klass
        ResultSearch
      end

      def default_filter_params
        {
          search_text: "",
          scope_id: "",
          category_id: ""
        }
      end

      def context_params
        { feature: current_feature, organization: current_organization }
      end

      def first_class_categories
        @first_class_categories ||= current_participatory_process.categories.first_class
      end

      def category
        if params[:filter] && params[:filter][:category_id].present?
          current_participatory_process.categories.find(params[:filter][:category_id])
        end
      end

      def progress_calculator(scope_id, category_id)
        Decidim::Accountability::ResultsCalculator.new(current_feature, scope_id, category_id).progress
      end

      def count_calculator(scope_id, category_id)
        Decidim::Accountability::ResultsCalculator.new(current_feature, scope_id, category_id).count
      end

      def current_scope
        params[:filter][:scope_id] if params[:filter]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
decidim-accountability-0.7.3 app/controllers/decidim/accountability/results_controller.rb
decidim-accountability-0.7.2 app/controllers/decidim/accountability/results_controller.rb
decidim-accountability-0.7.1 app/controllers/decidim/accountability/results_controller.rb
decidim-accountability-0.7.0 app/controllers/decidim/accountability/results_controller.rb