Browse Source

Allow filtering by user without js

pull/2535/head
Kat 2 years ago committed by kosiakkatrina
parent
commit
9e55b87e75
  1. 2
      app/helpers/filters_helper.rb
  2. 2
      app/models/lettings_log.rb
  3. 4
      app/models/user.rb
  4. 2
      app/services/filter_manager.rb
  5. 7
      app/views/filters/_select_filter.html.erb

2
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

2
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

4
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

2
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?

7
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| %>
<option value="<%= answer.id %>"
@ -9,3 +10,9 @@
<%= answer.id == "" ? "disabled" : "" %>><%= answer.name %></option>
<% 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) %>

Loading…
Cancel
Save