Sha256: 54e80a8a3e814bda0407b258e60ea50edcb31276256e2b37a2bf165b50701d45

Contents?: true

Size: 1.58 KB

Versions: 27

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 = search.results.page(params[:page]).per(current_component.settings.projects_per_page)
        @projects = reorder(@projects)
      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

27 entries across 27 versions & 1 rubygems

Version Path
decidim-budgets-0.23.4 app/controllers/decidim/budgets/projects_controller.rb
decidim-budgets-0.24.0.rc1 app/controllers/decidim/budgets/projects_controller.rb
decidim-budgets-0.23.3 app/controllers/decidim/budgets/projects_controller.rb
decidim-budgets-0.23.2 app/controllers/decidim/budgets/projects_controller.rb
decidim-budgets-0.23.1 app/controllers/decidim/budgets/projects_controller.rb
decidim-budgets-0.23.1.rc1 app/controllers/decidim/budgets/projects_controller.rb
decidim-budgets-0.23.0 app/controllers/decidim/budgets/projects_controller.rb