Browse Source

Keep csv filters the same

pull/2535/head
Kat 2 years ago committed by kosiakkatrina
parent
commit
a839232e18
  1. 15
      app/helpers/filters_helper.rb
  2. 12
      app/views/filters/_select_filter.html.erb
  3. 20
      app/views/filters/_text_select_filter.html.erb
  4. 2
      app/views/filters/assigned_to.html.erb
  5. 2
      app/views/filters/managed_by.html.erb
  6. 2
      app/views/filters/owned_by.html.erb
  7. 6
      app/views/logs/_log_filters.html.erb

15
app/helpers/filters_helper.rb

@ -84,6 +84,11 @@ module FiltersHelper
JSON.parse(session[session_name_for(filter_type)])[filter] || ""
end
def owning_organisation_csv_filter_options(user)
organisation_options = user.support? ? Organisation.all : ([user.organisation] + user.organisation.stock_owners + user.organisation.absorbed_organisations).uniq
[OpenStruct.new(id: "", name: "Select an option")] + organisation_options.map { |org| OpenStruct.new(id: org.id, name: org.name) }
end
def owning_organisation_filter_options(user, filter_type)
if applied_filters(filter_type)["owning_organisation"].present?
organisation_id = applied_filters(filter_type)["owning_organisation"]
@ -99,6 +104,11 @@ module FiltersHelper
[OpenStruct.new(id: "", name: "Select an option")]
end
def assigned_to_csv_filter_options(user)
user_options = user.support? ? User.all : (user.organisation.users + user.organisation.managing_agents.flat_map(&:users) + user.organisation.stock_owners.flat_map(&:users)).uniq
[OpenStruct.new(id: "", name: "Select an option", hint: "")] + user_options.map { |user_option| OpenStruct.new(id: user_option.id, name: user_option.name, hint: user_option.email) }
end
def assigned_to_filter_options(filter_type)
if applied_filters(filter_type)["assigned_to"] == "specific_user" && applied_filters(filter_type)["user"].present?
user_id = applied_filters(filter_type)["user"]
@ -153,6 +163,11 @@ module FiltersHelper
end
end
def managing_organisation_csv_filter_options(user)
organisation_options = user.support? ? Organisation.all : ([user.organisation] + user.organisation.managing_agents + user.organisation.absorbed_organisations).uniq
[OpenStruct.new(id: "", name: "Select an option")] + organisation_options.map { |org| OpenStruct.new(id: org.id, name: org.name) }
end
def managing_organisation_filter_options(user, filter_type)
if applied_filters(filter_type)["managing_organisation"].present?
organisation_id = applied_filters(filter_type)["managing_organisation"]

12
app/views/filters/_select_filter.html.erb

@ -1,16 +1,6 @@
<span class="non-js-text-search-input-field">
<%= 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) %>
</span>
<%= 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 %>
"data-controller": "accessible-autocomplete conditional-filter") do %>
<% collection.each do |answer| %>
<option value="<%= answer.id %>"
data-hint="<%= answer.hint %>"

20
app/views/filters/_text_select_filter.html.erb

@ -0,0 +1,20 @@
<span class="non-js-text-search-input-field">
<%= 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) %>
</span>
<%= 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 %>"
data-hint="<%= answer.hint %>"
<%= answer.id.to_s == selected_option(category, @filter_type).to_s ? "selected" : "" %>
<%= answer.id == "" ? "disabled" : "" %>><%= answer.name %></option>
<% end %>
<% end %>

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

@ -12,7 +12,7 @@
label: "User",
category: "user",
caption_text: "User's name or email",
options: assigned_to_filter_options(@filter_type),
options: assigned_to_csv_filter_options(current_user),
},
},
},

2
app/views/filters/managed_by.html.erb

@ -9,7 +9,7 @@
type: "select",
label: "Managed by",
category: "managing_organisation",
options: managing_organisation_filter_options(current_user, @filter_type),
options: managing_organisation_csv_filter_options(current_user),
caption_text: "Organisation name",
},
},

2
app/views/filters/owned_by.html.erb

@ -9,7 +9,7 @@
type: "select",
label: "Owning Organisation",
category: "owning_organisation",
options: owning_organisation_filter_options(current_user, @filter_type),
options: owning_organisation_csv_filter_options(current_user),
caption_text: "Organisation name",
},
},

6
app/views/logs/_log_filters.html.erb

@ -66,7 +66,7 @@
"specific_user": {
label: "Specific user",
conditional_filter: {
type: "select",
type: "text_select",
label: "User",
category: "user",
options: assigned_to_filter_options(@filter_type),
@ -87,7 +87,7 @@
"specific_org": {
label: "Specific owning organisation",
conditional_filter: {
type: "select",
type: "text_select",
label: "Owning Organisation",
category: "owning_organisation",
options: owning_organisation_filter_options(current_user, @filter_type),
@ -109,7 +109,7 @@
"specific_org": {
label: "Specific managing organisation",
conditional_filter: {
type: "select",
type: "text_select",
label: user_or_org_lettings_path? ? "Managed by" : "Reported by",
category: "managing_organisation",
options: managing_organisation_filter_options(current_user, @filter_type),

Loading…
Cancel
Save