Sha256: 5e5834d37ee44d043fe64b24ceb6cc12d9a35c817461377eda6a0d4446b8be27

Contents?: true

Size: 1.15 KB

Versions: 33

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Decidim
  module Elections
    # This class handles search and filtering of elections.
    class ElectionSearch < ResourceSearch
      # Public: Initializes the service.
      # component     - A Decidim::Component to get the election from.
      # page        - The page number to paginate the results.
      # per_page    - The number of proposals to return per page.
      def initialize(options = {})
        super(Election.all, options)
      end

      # Handle the search_text filter
      def search_search_text
        query
          .where("decidim_elections_elections.title::text ILIKE ?", "%#{search_text}%")
          .or(query.where("decidim_elections_elections.description::text ILIKE ?", "%#{search_text}%"))
      end

      # Handle the state filter
      def search_state
        active = state.member?("active") ? query.active : nil
        upcoming = state.member?("upcoming") ? query.upcoming : nil
        finished = state.member?("finished") ? query.finished : nil

        query
          .where(id: upcoming)
          .or(query.where(id: active))
          .or(query.where(id: finished))
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

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