-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I think this is everything for the refactor
- Loading branch information
Howard M. Miller
committed
Mar 19, 2021
1 parent
e2c2148
commit 8ce7722
Showing
11 changed files
with
101 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
# FilterOptionsBlueprint emits a structure that the browse Vue page can turn | ||
# into checkboxes or other form UI elements to filter a list of contributions | ||
# | ||
# We assume that there's a top level type of filter (e.g ContactMethodFilter) | ||
# that then references a series of these FilterOptionBlueprint objects for | ||
# each element (e.g. each available contact method) | ||
class FilterOptionsBlueprint < Blueprinter::Base | ||
# The identifier here needs to be in a format that the BrowseFilter can then | ||
# interpret and use to filter results | ||
identifier :id do |category, _options| | ||
"#{category.class.to_s}[#{category.id}]" | ||
"#{category.class}[#{category.id}]" | ||
end | ||
|
||
# This is currently used as a display name so people can understand | ||
# which each option represents | ||
field :name | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# This class has information about how we sort and filter categories | ||
# and is capable of accepting a model scope and adding additional | ||
# `where` clauses to it in order to filter the message | ||
|
||
# BasicFilter is more like an abstract parent class, but it also serves | ||
# as a NullObject version of the filter, if you want one | ||
class BasicFilter | ||
# This method should be overridden to return a hash with the following keys: | ||
# * :name => a short string that the user will see that describes what type of filters these are | ||
# * :filters => the output a call to FilterOptionsBlueprint.render_as_hash that represent each filter option to check or uncheck | ||
def self.options | ||
{} | ||
end | ||
|
||
attr_reader :parameters | ||
|
||
def initialize(parameters) | ||
@parameters = parameters | ||
end | ||
|
||
# By default, return the model scope unfiltered | ||
def filter(scope) | ||
scope | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
class ContactMethodFilter | ||
class ContactMethodFilter < BasicFilter | ||
def self.options | ||
{ | ||
name: 'Contact Methods', | ||
filters: FilterOptionsBlueprint.render_as_hash(ContactMethod.enabled.distinct(:name)) | ||
} | ||
end | ||
|
||
def self.filter(relation, _parameters) | ||
relation | ||
def filter(scope) | ||
return super unless parameters | ||
scope.joins(:person).where(people: { preferred_contact_method: parameters.keys }) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
class ServiceAreaFilter | ||
class ServiceAreaFilter < BasicFilter | ||
def self.options | ||
{ | ||
name: 'Service Areas', | ||
filters: FilterOptionsBlueprint.render_as_hash(ServiceArea.i18n) | ||
} | ||
end | ||
|
||
def self.filter(relation, _parameters) | ||
relation | ||
def filter(scope) | ||
return super unless parameters | ||
scope.where(service_area_id: parameters.keys) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters