Sha256: 2c32e8aaed240364d60ade0386d5a17fb8e2c2c32b59f8680381b90ee9088628

Contents?: true

Size: 1.58 KB

Versions: 3

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    # Exposes the project resource so users can view them
    class ProjectsController < Decidim::Budgets::ApplicationController
      include FilterResource
      include NeedsCurrentOrder
      include Decidim::Budgets::Orderable

      helper_method :projects, :project, :budget

      def index
        raise ActionController::RoutingError, "Not Found" unless budget
      end

      def show
        raise ActionController::RoutingError, "Not Found" unless budget
        raise ActionController::RoutingError, "Not Found" unless project
      end

      private

      def budget
        @budget ||= Budget.where(component: current_component).includes(:projects).find_by(id: params[:budget_id])
      end

      def projects
        return @projects if @projects

        @projects = reorder(search.results)
        @projects = @projects.page(params[:page]).per(current_component.settings.projects_per_page)
      end

      def project
        @project ||= Project.find_by(id: params[:id])
      end

      def search_klass
        ProjectSearch
      end

      def default_filter_params
        {
          search_text: "",
          status: default_filter_status_params,
          scope_id: default_filter_scope_params,
          category_id: default_filter_category_params
        }
      end

      def default_filter_status_params
        voting_finished? ? %w(selected) : %w(all)
      end

      def context_params
        { budget: budget, component: current_component, organization: current_organization }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-budgets-0.26.7 app/controllers/decidim/budgets/projects_controller.rb
decidim-budgets-0.26.5 app/controllers/decidim/budgets/projects_controller.rb
decidim-budgets-0.26.4 app/controllers/decidim/budgets/projects_controller.rb