diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb index 2b98e9346..962b32210 100644 --- a/app/helpers/filters_helper.rb +++ b/app/helpers/filters_helper.rb @@ -11,8 +11,8 @@ module FiltersHelper return true if !selected_filters.key?("owning_organisation") && filter == "owning_organisation_select" && value == :all return true if !selected_filters.key?("managing_organisation") && filter == "managing_organisation_select" && value == :all - return true if selected_filters["owning_organisation"].present? && filter == "owning_organisation_select" && value == :specific_org - return true if selected_filters["managing_organisation"].present? && filter == "managing_organisation_select" && value == :specific_org + return true if (selected_filters["owning_organisation"].present? || selected_filters["owning_organisation_text_search"].present?) && filter == "owning_organisation_select" && value == :specific_org + return true if (selected_filters["managing_organisation"].present? || selected_filters["managing_organisation_text_search"].present?) && filter == "managing_organisation_select" && value == :specific_org return false if selected_filters[filter].blank? @@ -242,7 +242,7 @@ private filters.each.sum do |category, category_filters| if %w[years status needstypes bulk_upload_id].include?(category) category_filters.count(&:present?) - elsif %w[user owning_organisation managing_organisation].include?(category) + elsif %w[user owning_organisation managing_organisation user_text_search owning_organisation_text_search managing_organisation_text_search].include?(category) 1 else 0 diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index ec4fb17be..04d6b9ff6 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -133,6 +133,8 @@ class LettingsLog < Log } 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)) } + scope :filter_by_owning_organisation_text_search, ->(param, _user) { where(owning_organisation: Organisation.search_by(param)) } + scope :filter_by_managing_organisation_text_search, ->(param, _user) { where(managing_organisation: Organisation.search_by(param)) } AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze OPTIONAL_FIELDS = %w[tenancycode propcode chcharge].freeze diff --git a/app/models/user.rb b/app/models/user.rb index 8aa42aa0f..6da8b8ba8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -210,7 +210,7 @@ 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 user_text_search] + %w[years status needstypes assigned_to user managing_organisation owning_organisation bulk_upload_id user_text_search owning_organisation_text_search managing_organisation_text_search] else %w[years status needstypes assigned_to user bulk_upload_id user_text_search] end diff --git a/app/services/filter_manager.rb b/app/services/filter_manager.rb index dc38ae47e..6406fd168 100644 --- a/app/services/filter_manager.rb +++ b/app/services/filter_manager.rb @@ -25,6 +25,8 @@ class FilterManager next if category == "managing_organisation" && all_orgs next if category == "assigned_to" next if category == "user_text_search" && filters["assigned_to"] != "specific_user" + next if category == "owning_organisation_text_search" && all_orgs + next if category == "managing_organisation_text_search" && all_orgs logs = logs.public_send("filter_by_#{category}", values, user) end @@ -101,6 +103,8 @@ 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" + new_filters = new_filters.except("owning_organisation_text_search") if params["owning_organisation_select"] == "all" + new_filters = new_filters.except("managing_organisation_text_search") if params["managing_organisation_select"] == "all" end if (filter_type.include?("schemes") || filter_type.include?("users") || filter_type.include?("scheme_locations")) && params["status"].present? diff --git a/app/views/filters/_radio_filter.html.erb b/app/views/filters/_radio_filter.html.erb index 6eb902dba..e4d23573c 100644 --- a/app/views/filters/_radio_filter.html.erb +++ b/app/views/filters/_radio_filter.html.erb @@ -10,6 +10,7 @@ collection: option[:conditional_filter][:options], category: option[:conditional_filter][:category], label: option[:conditional_filter][:label], + caption_text: option[:conditional_filter][:caption_text], secondary: true, hint_text: option[:conditional_filter][:hint_text], } %> diff --git a/app/views/filters/_select_filter.html.erb b/app/views/filters/_select_filter.html.erb index 0bb71bf73..0540ad3db 100644 --- a/app/views/filters/_select_filter.html.erb +++ b/app/views/filters/_select_filter.html.erb @@ -1,3 +1,10 @@ +<%= f.govuk_text_field "#{category}_text_search".to_sym, + label: { text: label, hidden: secondary }, + "data-controller": "search conditional-filter", + caption: { text: caption_text }, + "data-info": { search_url: filter_search_url(category.to_sym) }.to_json, + value: selected_option("#{category}_text_search", @filter_type) %> + <%= f.govuk_select(category.to_sym, label: { text: label, hidden: secondary }, "data-controller": "search conditional-filter", @@ -10,9 +17,3 @@ <%= answer.id == "" ? "disabled" : "" %>><%= answer.name %> <% 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) %> diff --git a/app/views/filters/assigned_to.html.erb b/app/views/filters/assigned_to.html.erb index 68ad6403e..3c6708586 100644 --- a/app/views/filters/assigned_to.html.erb +++ b/app/views/filters/assigned_to.html.erb @@ -11,6 +11,7 @@ type: "select", label: "User", category: "user", + caption_text: "User's name or email", }, }, }, diff --git a/app/views/filters/managed_by.html.erb b/app/views/filters/managed_by.html.erb index df3c04af7..98f88e65c 100644 --- a/app/views/filters/managed_by.html.erb +++ b/app/views/filters/managed_by.html.erb @@ -10,6 +10,7 @@ label: "Managed by", category: "managing_organisation", options: managing_organisation_filter_options(current_user, @filter_type), + caption_text: "Organisation name", }, }, }, diff --git a/app/views/filters/owned_by.html.erb b/app/views/filters/owned_by.html.erb index 43b61ec73..cb5fe696a 100644 --- a/app/views/filters/owned_by.html.erb +++ b/app/views/filters/owned_by.html.erb @@ -10,6 +10,7 @@ label: "Owning Organisation", category: "owning_organisation", options: owning_organisation_filter_options(current_user, @filter_type), + caption_text: "Organisation name", }, }, }, diff --git a/app/views/logs/_log_filters.html.erb b/app/views/logs/_log_filters.html.erb index fed0643d0..8663adf80 100644 --- a/app/views/logs/_log_filters.html.erb +++ b/app/views/logs/_log_filters.html.erb @@ -70,6 +70,7 @@ label: "User", category: "user", options: assigned_to_filter_options(@filter_type), + caption_text: "User's name or email", }, }, }, @@ -90,6 +91,7 @@ label: "Owning Organisation", category: "owning_organisation", options: owning_organisation_filter_options(current_user, @filter_type), + caption_text: "Organisation name", }, }, }, @@ -111,6 +113,7 @@ label: user_or_org_lettings_path? ? "Managed by" : "Reported by", category: "managing_organisation", options: managing_organisation_filter_options(current_user, @filter_type), + caption_text: "Organisation name", }, }, },