From 9e55b87e75f9bc0607a7bede8ff6dd0c1dcc2f1f Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 30 Jul 2024 12:25:10 +0100 Subject: [PATCH] Allow filtering by user without js --- app/helpers/filters_helper.rb | 2 +- app/models/lettings_log.rb | 2 ++ app/models/user.rb | 4 ++-- app/services/filter_manager.rb | 2 ++ app/views/filters/_select_filter.html.erb | 7 +++++++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb index 81a986ebf..2b98e9346 100644 --- a/app/helpers/filters_helper.rb +++ b/app/helpers/filters_helper.rb @@ -94,7 +94,7 @@ module FiltersHelper end def assigned_to_filter_options(filter_type) - if applied_filters(filter_type)["assigned_to"] == "specific_user" + if applied_filters(filter_type)["assigned_to"] == "specific_user" && applied_filters(filter_type)["user"].present? user = User.find(applied_filters(filter_type)["user"]) # make sure this doesn't expose anything weird [OpenStruct.new(id: user.id, name: user.name, hint: user.email)] else diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index e7a72350d..ec4fb17be 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -132,6 +132,8 @@ class LettingsLog < Log illness_type_10: false) } + scope :filter_by_user_text_search, ->(param, user) { where(assigned_to: user.support? ? User.search_by(param) : User.affiliated_users(user.organisation).search_by(param)) } + AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze OPTIONAL_FIELDS = %w[tenancycode propcode chcharge].freeze RENT_TYPE_MAPPING_LABELS = { 1 => "Social Rent", 2 => "Affordable Rent", 3 => "Intermediate Rent" }.freeze diff --git a/app/models/user.rb b/app/models/user.rb index 724c51409..8aa42aa0f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -210,9 +210,9 @@ class User < ApplicationRecord def logs_filters(specific_org: false) if (support? && !specific_org) || organisation.has_managing_agents? || organisation.has_stock_owners? - %w[years status needstypes assigned_to user managing_organisation owning_organisation bulk_upload_id] + %w[years status needstypes assigned_to user managing_organisation owning_organisation bulk_upload_id user_text_search] else - %w[years status needstypes assigned_to user bulk_upload_id] + %w[years status needstypes assigned_to user bulk_upload_id user_text_search] end end diff --git a/app/services/filter_manager.rb b/app/services/filter_manager.rb index 8d661b3fa..dc38ae47e 100644 --- a/app/services/filter_manager.rb +++ b/app/services/filter_manager.rb @@ -24,6 +24,7 @@ class FilterManager next if category == "owning_organisation" && all_orgs next if category == "managing_organisation" && all_orgs next if category == "assigned_to" + next if category == "user_text_search" && filters["assigned_to"] != "specific_user" logs = logs.public_send("filter_by_#{category}", values, user) end @@ -99,6 +100,7 @@ class FilterManager new_filters = new_filters.except("user") if params["assigned_to"] == "all" new_filters["user"] = current_user.id.to_s if params["assigned_to"] == "you" + new_filters = new_filters.except("user_text_search") if params["assigned_to"] == "all" || params["assigned_to"] == "you" end if (filter_type.include?("schemes") || filter_type.include?("users") || filter_type.include?("scheme_locations")) && params["status"].present? diff --git a/app/views/filters/_select_filter.html.erb b/app/views/filters/_select_filter.html.erb index 9e564bfb2..0bb71bf73 100644 --- a/app/views/filters/_select_filter.html.erb +++ b/app/views/filters/_select_filter.html.erb @@ -1,6 +1,7 @@ <%= f.govuk_select(category.to_sym, label: { text: label, hidden: secondary }, "data-controller": "search conditional-filter", + "hidden": true, "data-info": { search_url: filter_search_url(category.to_sym) }.to_json) do %> <% collection.each do |answer| %> <% end %> <% end %> + +<%= f.govuk_text_field "#{category}_text_search".to_sym, + label: { text: label, hidden: secondary }, + "data-controller": "search conditional-filter", + "data-info": { search_url: filter_search_url(category.to_sym) }.to_json, + value: selected_option("#{category}_text_search", @filter_type) %>