Sha256: c3361d22cc82f0496905c0b9b91b63da81e69a15e06f351e0b2dafbfd84a0303

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true

module Decidim
  module Consultations
    # A controller that holds the logic to show consultations in a
    # public layout.
    class ConsultationsController < Decidim::ApplicationController
      layout "layouts/decidim/consultation", only: :show

      include NeedsConsultation
      include FilterResource
      include Paginable
      include Orderable

      helper_method :collection, :consultations, :finished_consultations, :active_consultations, :filter

      helper Decidim::FiltersHelper
      helper Decidim::OrdersHelper
      helper Decidim::SanitizeHelper
      helper Decidim::PaginateHelper
      helper Decidim::IconHelper
      helper Decidim::WidgetUrlsHelper

      def index
        authorize! :read, Consultation
        redirect_to consultation_path(active_consultations.first) if active_consultations.count == 1
      end

      def show
        authorize! :read, current_consultation
      end

      def finished
        authorize! :read, Consultation
        render layout: "layouts/decidim/consultation_choose"
      end

      private

      def finished_consultations
        @finished_consultations ||= OrganizationConsultations.for(current_organization).finished.published
      end

      def active_consultations
        @active_consultations ||= OrganizationConsultations.for(current_organization).active.published
      end

      def consultations
        @consultations = search.results
        @consultations = reorder(@consultations)
        @consultations = paginate(@consultations)
      end

      alias collection consultations

      def search_klass
        ConsultationSearch
      end

      def default_filter_params
        {
          search_text: "",
          state: "all"
        }
      end

      def context_params
        {
          organization: current_organization,
          current_user: current_user
        }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-consultations-0.11.2 app/controllers/decidim/consultations/consultations_controller.rb
decidim-consultations-0.11.1 app/controllers/decidim/consultations/consultations_controller.rb
decidim-consultations-0.11.0.pre1 app/controllers/decidim/consultations/consultations_controller.rb