Class: Decidim::Elections::ElectionSearch

Inherits:
ResourceSearch
  • Object
show all
Defined in:
app/services/decidim/elections/election_search.rb

Overview

This class handles search and filtering of elections.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ElectionSearch

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.



11
12
13
# File 'app/services/decidim/elections/election_search.rb', line 11

def initialize(options = {})
  super(Election.all, options)
end

Instance Method Details

#search_search_textObject

Handle the search_text filter



16
17
18
19
20
# File 'app/services/decidim/elections/election_search.rb', line 16

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

#search_stateObject

Handle the state filter



23
24
25
26
27
28
29
30
31
32
# File 'app/services/decidim/elections/election_search.rb', line 23

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