Sha256: c6911448280374e2f523cd70645800538bd3217e6004c2b623cc6b326cc46997

Contents?: true

Size: 1.07 KB

Versions: 14

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    # This class handles search and filtering of projects. Needs a
    # `current_component` param with a `Decidim::Component` in order to
    # find the projects.
    class ProjectSearch < ResourceSearch
      text_search_fields :title, :description

      # Public: Initializes the service.
      # component     - A Decidim::Component to get the projects from.
      def initialize(options = {})
        super(Project.all, options)
      end

      # Creates the SearchLight base query.
      def base_query
        raise "Missing budget" unless budget
        raise "Missing component" unless component

        @scope.where(budget: budget)
      end

      # Returns the random projects for the current page.
      def results
        Project.where(id: super.pluck(:id)).includes([:scope, :component, :attachments, :category])
      end

      private

      # Private: Since budget is not used by a search method we need
      # to define the method manually.
      def budget
        options[:budget]
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
decidim-budgets-0.24.3 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.23.6 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.24.2 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.23.5 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.24.1 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.24.0 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.24.0.rc2 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.23.4 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.24.0.rc1 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.23.3 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.23.2 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.23.1 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.23.1.rc1 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.23.0 app/services/decidim/budgets/project_search.rb