Browse Source

feat: rest of assigned to filter behaviour

pull/1775/head
natdeanlewissoftwire 3 years ago
parent
commit
2399ce1372
  1. 2
      app/components/sales_log_summary_component.html.erb
  2. 2
      app/models/lettings_log.rb
  3. 10
      app/models/log.rb
  4. 2
      app/models/sales_log.rb
  5. 2
      app/services/filter_manager.rb

2
app/components/sales_log_summary_component.html.erb

@ -42,7 +42,7 @@
<p class="govuk-body">
Created <time datetime="<%= log.created_at.iso8601 %>"><%= log.created_at.to_formatted_s(:govuk_date) %></time>
<% if log.created_by %>
<span class="app-log-summary__footer--actor">by <%= log.created_by.name || log.created_by.email %></span>
<span class="app-log-summary__footer--actor">Assigned to <%= log.created_by.name || log.created_by.email %></span>
<% end %>
</p>
</footer>

2
app/models/lettings_log.rb

@ -52,7 +52,7 @@ class LettingsLog < Log
}
scope :filter_by_before_startdate, ->(date) { where("lettings_logs.startdate >= ?", date) }
scope :unresolved, -> { where(unresolved: true) }
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) }
scope :filter_by_organisation, ->(org) { where(owning_organisation: org).or(where(managing_organisation: org)) }
scope :duplicate_logs, lambda { |log|
visible
.where(log.slice(*DUPLICATE_LOG_ATTRIBUTES))

10
app/models/log.rb

@ -29,8 +29,8 @@ class Log < ApplicationRecord
scope :visible, -> { where(status: %w[not_started in_progress completed]) }
scope :exportable, -> { where(status: %w[not_started in_progress completed deleted]) }
scope :filter_by_status, ->(status, _user = nil) { where status: }
scope :filter_by_years, lambda { |years, _user = nil|
scope :filter_by_status, ->(status) { where status: }
scope :filter_by_years, lambda { |years|
first_year = years.shift
query = filter_by_year(first_year)
years.each { |year| query = query.or(filter_by_year(year)) }
@ -38,11 +38,7 @@ class Log < ApplicationRecord
}
scope :filter_by_postcode, ->(postcode_full) { where("REPLACE(postcode_full, ' ', '') ILIKE ?", "%#{postcode_full.delete(' ')}%") }
scope :filter_by_id, ->(id) { where(id:) }
scope :filter_by_user, lambda { |selected_user, user|
if !selected_user.include?("all") && user.present?
where(created_by: user)
end
}
scope :filter_by_user, ->(selected_user) { where(created_by: selected_user) }
scope :filter_by_bulk_upload_id, lambda { |bulk_upload_id, user|
joins(:bulk_upload)
.where(bulk_upload: { id: bulk_upload_id, user: })

2
app/models/sales_log.rb

@ -40,7 +40,7 @@ class SalesLog < Log
.or(filter_by_postcode(param))
.or(filter_by_id(param))
}
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org) }
scope :filter_by_organisation, ->(org) { where(owning_organisation: org) }
scope :duplicate_logs, lambda { |log|
visible.where(log.slice(*DUPLICATE_LOG_ATTRIBUTES))
.where.not(id: log.id)

2
app/services/filter_manager.rb

@ -24,7 +24,7 @@ class FilterManager
next if category == "organisation" && all_orgs
next if category == "assigned_to"
logs = logs.public_send("filter_by_#{category}", values, user)
logs = logs.public_send("filter_by_#{category}", values)
end
logs = logs.order(created_at: :desc)
if user.support?

Loading…
Cancel
Save