diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb index e2da5b0ed..8ea0093b6 100644 --- a/app/helpers/filters_helper.rb +++ b/app/helpers/filters_helper.rb @@ -26,6 +26,7 @@ module FiltersHelper filters["organisation"].present? || filters["managing_organisation"].present? || filters["status"]&.compact_blank&.any? || + filters["needstypes"]&.compact_blank&.any? || filters["years"]&.compact_blank&.any? || filters["bulk_upload_id"].present? end @@ -56,6 +57,13 @@ module FiltersHelper }.freeze end + def needstype_filters + { + "1" => "General needs", + "2" => "Supported housing", + }.freeze + end + def location_status_filters { "incomplete" => "Incomplete", @@ -126,7 +134,7 @@ private def filters_count(filters) filters.each.sum do |category, category_filters| - if %w[status years bulk_upload_id].include?(category) + if %w[status needstypes years bulk_upload_id].include?(category) category_filters.count(&:present?) elsif %w[user owning_organisation managing_organisation].include?(category) 1 diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index d9712ea52..1bcca5496 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -43,6 +43,13 @@ class LettingsLog < Log scope :filter_by_tenant_code, ->(tenant_code) { where("tenancycode ILIKE ?", "%#{tenant_code}%") } scope :filter_by_propcode, ->(propcode) { where("propcode ILIKE ?", "%#{propcode}%") } scope :filter_by_location_postcode, ->(postcode_full) { left_joins(:location).where("REPLACE(locations.postcode, ' ', '') ILIKE ?", "%#{postcode_full.delete(' ')}%") } + scope :filter_by_needstype, ->(needstype) { where(needstype:) } + scope :filter_by_needstypes, lambda { |needstypes, _user = nil| + first_needstype = needstypes.shift + query = filter_by_needstype(first_needstype) + needstypes.each { |needstype| query = query.or(filter_by_needstype(needstype)) } + query.all + } scope :search_by, lambda { |param| filter_by_location_postcode(param) .or(filter_by_tenant_code(param)) diff --git a/app/models/user.rb b/app/models/user.rb index c6deed8a1..fc26dc686 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -173,9 +173,9 @@ class User < ApplicationRecord def logs_filters(specific_org: false) if (support? && !specific_org) || organisation.has_managing_agents? || organisation.has_stock_owners? - %w[status years assigned_to user managing_organisation owning_organisation bulk_upload_id] + %w[years status needstypes assigned_to user managing_organisation owning_organisation bulk_upload_id] else - %w[status years assigned_to user bulk_upload_id] + %w[years status needstypes assigned_to user bulk_upload_id] end end diff --git a/app/views/logs/_log_filters.html.erb b/app/views/logs/_log_filters.html.erb index 1034379db..638d8ea5c 100644 --- a/app/views/logs/_log_filters.html.erb +++ b/app/views/logs/_log_filters.html.erb @@ -41,9 +41,17 @@ label: "Status", category: "status", } %> + + <%= render partial: "filters/checkbox_filter", + locals: { + f:, + options: needstype_filters, + label: "Needs type", + category: "needstypes", + } %> <% end %> - <%= render partial: "filters/radio_filter", + <%= render partial: "filters/radio_filter", locals: { f:, options: {