Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/blueprints/contribution_type_filter_option_blueprint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class ContributionTypeFilterOptionBlueprint < Blueprinter::Base
identifier :id do |filter_option|
"ContributionType[#{filter_option}]"
end

field :name do |filter_option|
filter_option.titleize
end
end
13 changes: 13 additions & 0 deletions app/blueprints/filter_group_blueprint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class FilterGroupBlueprint < Blueprinter::Base
field :filter_grouping_name, name: :name

association :filter_options, blueprint: ->(filter_options) do
if filter_options == ContributionTypeFilter.filter_options
ContributionTypeFilterOptionBlueprint
else
FilterOptionBlueprint
end
end
end
12 changes: 6 additions & 6 deletions app/filters/category_filter.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class CategoryFilter < BaseFilter
def self.filter_grouping
{
name: "Categories",
# Currently only filtering by top-level categories
filter_options: FilterOptionBlueprint.render_as_hash(Category.roots)
}
def self.filter_grouping_name
'Categories'
end

def self.filter_options
Category.roots
end

def filter(scope)
Expand Down
11 changes: 6 additions & 5 deletions app/filters/contact_method_filter.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class ContactMethodFilter < BaseFilter
def self.filter_grouping
{
name: 'Contact Methods',
filter_options: FilterOptionBlueprint.render_as_hash(ContactMethod.enabled.distinct(:name))
}
def self.filter_grouping_name
'Contact Methods'
end

def self.filter_options
ContactMethod.enabled.distinct(:name)
end

def filter(scope)
Expand Down
13 changes: 7 additions & 6 deletions app/filters/contribution_type_filter.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class ContributionTypeFilter < BaseFilter
def self.filter_grouping
{name: 'Contribution Types', filter_options: [
{id: 'ContributionType[Ask]', name: 'Ask'},
{id: 'ContributionType[Offer]', name: 'Offer'},
{id: 'ContributionType[CommunityResource]', name: 'Community Resource'}
]}
def self.filter_grouping_name
'Contribution Types'
end

def self.filter_options
ALL_ALLOWED_TYPES
end

ALL_ALLOWED_TYPES = %w[Ask Offer CommunityResource].freeze

def filter(scope)
Expand Down
11 changes: 6 additions & 5 deletions app/filters/service_area_filter.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class ServiceAreaFilter < BaseFilter
def self.filter_grouping
{
name: 'Service Areas',
filter_options: FilterOptionBlueprint.render_as_hash(ServiceArea.i18n)
}
def self.filter_grouping_name
'Service Areas'
end

def self.filter_options
ServiceArea.i18n
end

def filter(scope)
Expand Down
2 changes: 1 addition & 1 deletion app/models/browse_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BrowseFilter
attr_reader :parameters

def self.filter_groupings_json
FILTER_CLASSES.map(&:filter_grouping).to_json
FilterGroupBlueprint.render(FILTER_CLASSES)
end

def initialize(parameters)
Expand Down