Browse Source

Allow filtering by org without js

pull/2535/head
Kat 2 years ago committed by kosiakkatrina
parent
commit
6a220950d0
  1. 6
      app/helpers/filters_helper.rb
  2. 2
      app/models/lettings_log.rb
  3. 2
      app/models/user.rb
  4. 4
      app/services/filter_manager.rb
  5. 1
      app/views/filters/_radio_filter.html.erb
  6. 13
      app/views/filters/_select_filter.html.erb
  7. 1
      app/views/filters/assigned_to.html.erb
  8. 1
      app/views/filters/managed_by.html.erb
  9. 1
      app/views/filters/owned_by.html.erb
  10. 3
      app/views/logs/_log_filters.html.erb

6
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

2
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

2
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

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

1
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],
} %>

13
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 %></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) %>

1
app/views/filters/assigned_to.html.erb

@ -11,6 +11,7 @@
type: "select",
label: "User",
category: "user",
caption_text: "User's name or email",
},
},
},

1
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",
},
},
},

1
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",
},
},
},

3
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",
},
},
},

Loading…
Cancel
Save