Class: Decidim::Sortitions::SortitionSearch
- Inherits:
-
ResourceSearch
- Object
- ResourceSearch
- Decidim::Sortitions::SortitionSearch
- Defined in:
- app/services/decidim/sortitions/sortition_search.rb
Overview
A service to encapsualte all the logic when searching and filtering sortitions in a participatory process.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ SortitionSearch
constructor
Public: Initializes the service.
-
#search_search_text ⇒ Object
Handle the search_text filter.
-
#search_state ⇒ Object
Handle the state filter.
Constructor Details
#initialize(options = {}) ⇒ SortitionSearch
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.
12 13 14 |
# File 'app/services/decidim/sortitions/sortition_search.rb', line 12 def initialize( = {}) super(Sortition.all, ) end |
Instance Method Details
#search_search_text ⇒ Object
Handle the search_text filter
17 18 19 20 21 22 23 24 25 26 |
# File 'app/services/decidim/sortitions/sortition_search.rb', line 17 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 |
#search_state ⇒ Object
Handle the state filter
29 30 31 32 33 34 35 36 37 38 |
# File 'app/services/decidim/sortitions/sortition_search.rb', line 29 def search_state case state when "active" query.active when "cancelled" query.cancelled else # Assume 'all' query end end |