Sha256: eae49de21f6ddd3c0678ddc2e7b341a66813db76b006fcb8d95ae03b4065b6b8

Contents?: true

Size: 1.26 KB

Versions: 30

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module Decidim
  module Sortitions
    # A service to encapsualte all the logic when searching and filtering
    # sortitions in a participatory process.
    class SortitionSearch < ResourceSearch
      # Public: Initializes the service.
      # component     - A Decidim::Component to get the proposals from.
      # page        - The page number to paginate the results.
      # per_page    - The number of proposals to return per page.
      def initialize(options = {})
        super(Sortition.all, options)
      end

      # Handle the search_text filter
      def search_search_text
        query
          .where("title->>'#{current_locale}' ILIKE ?", "%#{search_text}%")
          .or(
            query.where("additional_info->>'#{current_locale}' ILIKE ?", "%#{search_text}%")
          )
          .or(
            query.where("witnesses->>'#{current_locale}' ILIKE ?", "%#{search_text}%")
          )
      end

      # Handle the state filter
      def search_state
        case state
        when "active"
          query.active
        when "cancelled"
          query.cancelled
        else # Assume 'all'
          query
        end
      end

      private

      def current_locale
        I18n.locale.to_s
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
decidim-sortitions-0.22.0 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.21.0 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.20.1 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.20.0 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.19.1 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.18.1 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.19.0 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.17.2 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.18.0 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.17.1 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.16.1 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.17.0 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.16.0 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.15.2 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.15.1 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.15.0 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.14.4 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.14.3 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.14.2 app/services/decidim/sortitions/sortition_search.rb
decidim-sortitions-0.14.1 app/services/decidim/sortitions/sortition_search.rb