diff --git a/Gemfile.lock b/Gemfile.lock index a2af62ec2..e1c5812e9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) diff --git a/app/components/search_pills/component.html.slim b/app/components/search_pills/component.html.slim index c57175434..f5a5b4df5 100644 --- a/app/components/search_pills/component.html.slim +++ b/app/components/search_pills/component.html.slim @@ -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| diff --git a/app/controllers/searches_controller.rb b/app/controllers/searches_controller.rb index b22752ffd..1f8dd4a48 100644 --- a/app/controllers/searches_controller.rb +++ b/app/controllers/searches_controller.rb @@ -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 diff --git a/app/models/search.rb b/app/models/search.rb index 189e37a1f..e39f97bdd 100644 --- a/app/models/search.rb +++ b/app/models/search.rb @@ -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? @@ -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 diff --git a/app/queries/locations/filter_query.rb b/app/queries/locations/filter_query.rb index bdf040053..35c037b84 100644 --- a/app/queries/locations/filter_query.rb +++ b/app/queries/locations/filter_query.rb @@ -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 @@ -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]))