Sha256: 8885cdbe85cafb44fcff558dd9da7745b7ac4e1d2c87037bae5e22eb6a481269

Contents?: true

Size: 1.21 KB

Versions: 19

Compression:

Stored size: 1.21 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

      def search_status
        return query if status.member?("all")

        apply_scopes(%w(selected not_selected), status)
      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

19 entries across 19 versions & 1 rubygems

Version Path
decidim-budgets-0.26.10 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.26.9 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.26.8 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.26.7 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.26.5 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.26.4 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.26.3 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.26.2 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.26.1 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.26.0 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.26.0.rc2 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.26.0.rc1 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.25.2 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.25.1 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.25.0 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.25.0.rc4 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.25.0.rc3 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.25.0.rc2 app/services/decidim/budgets/project_search.rb
decidim-budgets-0.25.0.rc1 app/services/decidim/budgets/project_search.rb