Class: Decidim::Meetings::MeetingSearch
- Inherits:
-
ResourceSearch
- Object
- ResourceSearch
- Decidim::Meetings::MeetingSearch
- Defined in:
- app/services/decidim/meetings/meeting_search.rb
Overview
This class handles search and filtering of meetings. Needs a ‘current_component` param with a `Decidim::Component` in order to find the meetings.
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ MeetingSearch
constructor
Public: Initializes the service.
- #results ⇒ Object
-
#search_activity ⇒ Object
Handle the activity filter.
-
#search_date ⇒ Object
Handle the date filter.
- #search_space ⇒ Object
-
#search_state ⇒ Object
Handle the state filter.
- #search_type ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ MeetingSearch
Public: Initializes the service. component - A Decidim::Component to get the meetings from. page - The page number to paginate the results. per_page - The number of meetings to return per page.
15 16 17 18 19 20 |
# File 'app/services/decidim/meetings/meeting_search.rb', line 15 def initialize( = {}) [:scope] = .fetch(:scope, Meeting.published) [:scope] = [:state] == "withdrawn" ? [:scope].withdrawn : [:scope].except_withdrawn [:scope] = [:scope].includes(:component, :attachments) super([:scope], ) end |
Instance Method Details
#results ⇒ Object
60 61 62 |
# File 'app/services/decidim/meetings/meeting_search.rb', line 60 def results super.includes(attachments: :file_attachment, component: { participatory_space: :organization }) end |
#search_activity ⇒ Object
Handle the activity filter
43 44 45 46 47 48 49 50 51 |
# File 'app/services/decidim/meetings/meeting_search.rb', line 43 def search_activity case activity when "my_meetings" query .where(decidim_author_id: user.id) else query end end |
#search_date ⇒ Object
Handle the date filter
23 24 25 |
# File 'app/services/decidim/meetings/meeting_search.rb', line 23 def search_date apply_scopes(%w(upcoming past), date) end |
#search_space ⇒ Object
27 28 29 30 31 |
# File 'app/services/decidim/meetings/meeting_search.rb', line 27 def search_space return query if [:space].blank? || [:space] == "all" query.joins(:component).where(decidim_components: { participatory_space_type: [:space].classify }) end |
#search_state ⇒ Object
Handle the state filter
54 55 56 57 58 |
# File 'app/services/decidim/meetings/meeting_search.rb', line 54 def search_state return query.withdrawn if state == "withdrawn" query.except_withdrawn end |
#search_type ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'app/services/decidim/meetings/meeting_search.rb', line 33 def search_type fields = Decidim::Meetings::Meeting::TYPE_OF_MEETING filtered = [] [:type].each do |inquiry| filtered.push(inquiry) if fields.include?(inquiry) end filtered.size.positive? ? query.where(decidim_meetings_meetings: { type_of_meeting: filtered }) : query end |