Browse Source

feat: add needstype filter

pull/1998/head
natdeanlewissoftwire 3 years ago
parent
commit
6ed84c1637
  1. 10
      app/helpers/filters_helper.rb
  2. 7
      app/models/lettings_log.rb
  3. 4
      app/models/user.rb
  4. 8
      app/views/logs/_log_filters.html.erb

10
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

7
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))

4
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

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

@ -41,6 +41,14 @@
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",

Loading…
Cancel
Save