diff --git a/app/controllers/lettings_logs_controller.rb b/app/controllers/lettings_logs_controller.rb index a3ad65170..696d9870f 100644 --- a/app/controllers/lettings_logs_controller.rb +++ b/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) diff --git a/app/models/logs_filter_manager.rb b/app/models/logs_filter_manager.rb new file mode 100644 index 000000000..3eba1dd18 --- /dev/null +++ b/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