Browse Source

feat: wip filter commit

CLDC-2257-refactor-filters
natdeanlewissoftwire 1 year ago
parent
commit
b1ae9bbeee
  1. 3
      app/controllers/lettings_logs_controller.rb
  2. 18
      app/models/logs_filter_manager.rb

3
app/controllers/lettings_logs_controller.rb

@ -11,10 +11,11 @@ class LettingsLogsController < LogsController
before_action :redirect_if_bulk_upload_resolved, only: [:index]
def index
@log_filter_manager = LogsFilterManager.new(@session_filters, current_user)
respond_to do |format|
format.html do
all_logs = current_user.lettings_logs.visible
unpaginated_filtered_logs = filtered_logs(all_logs, search_term, @session_filters)
unpaginated_filtered_logs = filtered_logs(all_logs, search_term, @log_filter_manager.applied_filters)
@search_term = search_term
@pagy, @logs = pagy(unpaginated_filtered_logs)

18
app/models/logs_filter_manager.rb

@ -0,0 +1,18 @@
class LogsFilterManager
attr_accessor :applied_filters, :current_user
def initialize(applied_filters = {}, current_user = nil)
@applied_filters = applied_filters
@current_user = current_user
end
def applied_filters_count
applied_filters.values.sum do |category|
if category.is_a?(String)
category != "all" ? 1 : 0
else
category.count(&:present?)
end
end
end
end
Loading…
Cancel
Save