Class: Decidim::HomeActivitySearch
- Inherits:
-
Searchlight::Search
- Object
- Searchlight::Search
- Decidim::HomeActivitySearch
- Defined in:
- app/services/decidim/home_activity_search.rb
Overview
A class to search for recent activity performed in a Decidim Organization. It will only return the ‘Decidim::ActionLog` rows that have an action as `created` or `published`.
This class is thought to be used in the ‘LastActivityCell` uniquely.
Instance Method Summary collapse
-
#base_query ⇒ Object
Needed by Searchlight, this is the base query that will be used to append other criteria to the search.
-
#resource_types ⇒ Object
All the resource types that are eligible to be included as an activity.
-
#run ⇒ Object
Overwrites the default Searchlight run method since we want to return activities in an specific order but we need to set it at the end of the chain.
-
#search_resource_type ⇒ Object
Adds a constrain to filter by resource type(s).
Instance Method Details
#base_query ⇒ Object
Needed by Searchlight, this is the base query that will be used to append other criteria to the search.
12 13 14 15 16 |
# File 'app/services/decidim/home_activity_search.rb', line 12 def base_query ActionLog .where(visibility: %w(public-only all)) .where(organization: .fetch(:organization)) end |
#resource_types ⇒ Object
All the resource types that are eligible to be included as an activity.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/services/decidim/home_activity_search.rb', line 34 def resource_types @resource_types ||= %w( Decidim::Accountability::Result Decidim::Blogs::Post Decidim::Comments::Comment Decidim::Consultations::Question Decidim::Debates::Debate Decidim::Meetings::Meeting Decidim::Proposals::Proposal Decidim::Surveys::Survey Decidim::Assembly Decidim::Consultation Decidim::Initiative Decidim::ParticipatoryProcess ).select do |klass| klass.safe_constantize.present? end end |
#run ⇒ Object
Overwrites the default Searchlight run method since we want to return activities in an specific order but we need to set it at the end of the chain.
20 21 22 |
# File 'app/services/decidim/home_activity_search.rb', line 20 def run super.order(created_at: :desc) end |
#search_resource_type ⇒ Object
Adds a constrain to filter by resource type(s).
25 26 27 28 29 30 31 |
# File 'app/services/decidim/home_activity_search.rb', line 25 def search_resource_type if resource_types.include?(resource_type) scope_for(resource_type) else all_resources_scope end end |