Skip to content

Commit

Permalink
Add scope of work filter (#628)
Browse files Browse the repository at this point in the history
* Add scope of work filter

* Fix bundle audit check
  • Loading branch information
aliciapaz authored Dec 9, 2024
1 parent e5edbd4 commit 6b1debc
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
14 changes: 7 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ GEM
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.1)
loofah (2.22.0)
loofah (2.23.1)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
lumberjack (1.2.10)
Expand Down Expand Up @@ -326,13 +326,13 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.3)
nokogiri (1.16.7-aarch64-linux)
nokogiri (1.16.8-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.7-arm64-darwin)
nokogiri (1.16.8-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-darwin)
nokogiri (1.16.8-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
nokogiri (1.16.8-x86_64-linux)
racc (~> 1.4)
notiffany (0.1.3)
nenv (~> 0.1)
Expand Down Expand Up @@ -388,9 +388,9 @@ GEM
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
rails-html-sanitizer (1.6.1)
loofah (~> 2.21)
nokogiri (~> 1.14)
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
railties (7.0.8.5)
actionpack (= 7.0.8.5)
activesupport (= 7.0.8.5)
Expand Down
3 changes: 3 additions & 0 deletions app/components/search_pills/component.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ div class="w-full bg-gray-9"
div class="flex w-full md:w-auto md:py-3.5 md:pl-7"
- @radii_in_miles.each do |radius|
= render SearchPills::Button::Component.new(name: "search[distance]", value: miles_to_km(radius), checked: @params.dig(:search, :distance) == miles_to_km(radius).to_s, copy: radius == "Any" ? radius : "#{radius} mi")
div class="flex gap-2 ml-2 w-full md:w-auto md:py-3.5 md:pl-7"
- Organizations::Constants::SCOPE.each do |scope|
= render SearchPills::Pill::Component.new(name: "search[scope_of_work]", value: scope, checked: @params.dig(:search, :scope_of_work)&.include?(scope)), options: { multiple: true }, copy: scope
/ Services
div class="flex hidden overflow-y-auto flex-wrap gap-x-2 gap-y-3 px-6 py-4 max-h-28 border-r border-b border-l" data-tabs-target="panel"
- @services.each do |service|
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/searches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def show

def create_params
params.require(:search).permit(:distance, :city, :state, :lat, :lon,
:open_now, :open_weekends, :keyword,
:open_now, :open_weekends, :keyword, :scope_of_work,
:zipcode, causes: [], services: {}, beneficiary_groups: {})
end

Expand Down
5 changes: 3 additions & 2 deletions app/models/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Search

attr_accessor :keyword, :results, :distance, :city, :state, :zipcode,
:beneficiary_groups, :services, :causes, :open_now, :open_weekends,
:lat, :lon
:scope_of_work, :lat, :lon

def save
raise ActiveRecord::RecordInvalid unless valid?
Expand Down Expand Up @@ -43,7 +43,8 @@ def filters
open_weekends: ActiveModel::Type::Boolean.new.cast(open_weekends),
beneficiary_groups: beneficiary_groups&.transform_values { |value| value.uniq },
services: services&.transform_values { |value| value.uniq },
causes: causes&.uniq
causes: causes&.uniq,
scope_of_work: scope_of_work
}
end

Expand Down
9 changes: 9 additions & 0 deletions app/queries/locations/filter_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def call(params = {}, locations = Location.active)
scope = by_cause(scope, params[:causes])
scope = by_service(scope, params[:services])
scope = by_beneficiary_groups_served(scope, params[:beneficiary_groups])
scope = by_scope_of_work(scope, params[:scope_of_work])
scope = opened_now(scope, params[:open_now])
opened_on_weekends(scope, params[:open_weekends])
end
Expand Down Expand Up @@ -90,6 +91,14 @@ def by_beneficiary_groups_served(scope, beneficiary_groups_filters)
.having("count(locations.id) >= ?", complex_query.size) # multiple filters add up with AND behavior
end

def by_scope_of_work(scope, scope_of_work)
return scope if scope_of_work.blank? || scope.empty?

Location.joins(:organization)
.where("locations.id IN (?)", scope.ids)
.where("organizations.scope_of_work = ?", scope_of_work)
end

def starting_coordinates(lat, lon)
if lat.nil? || lon.nil?
Geo.to_wkt(Geo.point(DEFAULT_LOCATION[:longitude], DEFAULT_LOCATION[:latitude]))
Expand Down

0 comments on commit 6b1debc

Please sign in to comment.