Browse Source

Update scheme filters and log scopes

pull/2535/head
Kat 2 years ago committed by kosiakkatrina
parent
commit
b7b3a5077f
  1. 2
      app/helpers/filters_helper.rb
  2. 3
      app/models/log.rb
  3. 2
      app/views/filters/owned_by.html.erb
  4. 2
      app/views/schemes/_scheme_filters.html.erb

2
app/helpers/filters_helper.rb

@ -84,7 +84,7 @@ module FiltersHelper
JSON.parse(session[session_name_for(filter_type)])[filter] || "" JSON.parse(session[session_name_for(filter_type)])[filter] || ""
end end
def owning_organisation_csv_filter_options(user) def all_owning_organisation_filter_options(user)
organisation_options = user.support? ? Organisation.all : ([user.organisation] + user.organisation.stock_owners + user.organisation.absorbed_organisations).uniq 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) } [OpenStruct.new(id: "", name: "Select an option")] + organisation_options.map { |org| OpenStruct.new(id: org.id, name: org.name) }
end end

3
app/models/log.rb

@ -53,6 +53,9 @@ class Log < ApplicationRecord
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) } scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) }
scope :filter_by_owning_organisation, ->(owning_organisation, _user = nil) { where(owning_organisation:) } scope :filter_by_owning_organisation, ->(owning_organisation, _user = nil) { where(owning_organisation:) }
scope :filter_by_managing_organisation, ->(managing_organisation, _user = nil) { where(managing_organisation:) } scope :filter_by_managing_organisation, ->(managing_organisation, _user = nil) { where(managing_organisation:) }
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)) }
attr_accessor :skip_update_status, :skip_update_uprn_confirmed, :select_best_address_match, :skip_dpo_validation attr_accessor :skip_update_status, :skip_update_uprn_confirmed, :select_best_address_match, :skip_dpo_validation

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

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

2
app/views/schemes/_scheme_filters.html.erb

@ -35,7 +35,7 @@
type: "select", type: "select",
label: "Owning Organisation", label: "Owning Organisation",
category: "owning_organisation", category: "owning_organisation",
options: owning_organisation_filter_options(current_user, @filter_type), options: all_owning_organisation_filter_options(current_user),
}, },
}, },
}, },

Loading…
Cancel
Save