diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb
index a43ccb120..7370e0d3b 100644
--- a/app/helpers/filters_helper.rb
+++ b/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"]
diff --git a/app/views/filters/_select_filter.html.erb b/app/views/filters/_select_filter.html.erb
index ecc997bba..e31326347 100644
--- a/app/views/filters/_select_filter.html.erb
+++ b/app/views/filters/_select_filter.html.erb
@@ -1,16 +1,6 @@
-
-<%= 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",
- "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| %>
+ <% end %>
+ <% end %>
diff --git a/app/views/filters/assigned_to.html.erb b/app/views/filters/assigned_to.html.erb
index 9018d76b8..778d63c8a 100644
--- a/app/views/filters/assigned_to.html.erb
+++ b/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),
},
},
},
diff --git a/app/views/filters/managed_by.html.erb b/app/views/filters/managed_by.html.erb
index 98f88e65c..5d4b684f3 100644
--- a/app/views/filters/managed_by.html.erb
+++ b/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",
},
},
diff --git a/app/views/filters/owned_by.html.erb b/app/views/filters/owned_by.html.erb
index cb5fe696a..b90643125 100644
--- a/app/views/filters/owned_by.html.erb
+++ b/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",
},
},
diff --git a/app/views/logs/_log_filters.html.erb b/app/views/logs/_log_filters.html.erb
index 8663adf80..3beab4b6b 100644
--- a/app/views/logs/_log_filters.html.erb
+++ b/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),