From 30c35e23cadceec3beac6a12cf6750912ec3a828 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 25 May 2023 15:47:16 +0100 Subject: [PATCH] feat: add to sales, use before_action --- app/controllers/lettings_logs_controller.rb | 4 ++-- app/controllers/sales_logs_controller.rb | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/controllers/lettings_logs_controller.rb b/app/controllers/lettings_logs_controller.rb index 861674de3..c4239bad4 100644 --- a/app/controllers/lettings_logs_controller.rb +++ b/app/controllers/lettings_logs_controller.rb @@ -5,6 +5,7 @@ class LettingsLogsController < LogsController before_action :session_filters, if: :current_user, only: %i[index email_csv download_csv] before_action :set_session_filters, if: :current_user, only: %i[index email_csv download_csv] + before_action :log_filter_manager, if: :current_user, only: %i[index email_csv download_csv] before_action :authenticate_scope!, only: %i[download_csv email_csv] before_action :extract_bulk_upload_from_session_filters, only: [:index] @@ -13,7 +14,6 @@ class LettingsLogsController < LogsController def index respond_to do |format| format.html do - @log_filter_manager = LogsFilterManager.new(@session_filters, current_user) all_logs = current_user.lettings_logs.visible unpaginated_filtered_logs = filtered_logs(all_logs, search_term, @log_filter_manager.applied_filters) @@ -87,7 +87,7 @@ class LettingsLogsController < LogsController end def download_csv - unpaginated_filtered_logs = filtered_logs(current_user.lettings_logs, search_term, @session_filters) + unpaginated_filtered_logs = filtered_logs(current_user.lettings_logs, search_term, @log_filter_manager.applied_filters) render "download_csv", locals: { search_term:, count: unpaginated_filtered_logs.size, post_path: email_csv_lettings_logs_path, codes_only: codes_only_export? } end diff --git a/app/controllers/sales_logs_controller.rb b/app/controllers/sales_logs_controller.rb index 7ed52be2d..20229a4d5 100644 --- a/app/controllers/sales_logs_controller.rb +++ b/app/controllers/sales_logs_controller.rb @@ -3,6 +3,7 @@ class SalesLogsController < LogsController before_action :session_filters, if: :current_user, only: %i[index email_csv download_csv] before_action :set_session_filters, if: :current_user, only: %i[index email_csv download_csv] + before_action :log_filter_manager, if: :current_user, only: %i[index email_csv download_csv] before_action :authenticate_scope!, only: %i[download_csv email_csv] before_action :extract_bulk_upload_from_session_filters, only: [:index] @@ -16,7 +17,7 @@ class SalesLogsController < LogsController respond_to do |format| format.html do all_logs = current_user.sales_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) @@ -57,14 +58,14 @@ class SalesLogsController < LogsController end def download_csv - unpaginated_filtered_logs = filtered_logs(current_user.sales_logs, search_term, @session_filters) + unpaginated_filtered_logs = filtered_logs(current_user.sales_logs, search_term, @log_filter_manager.applied_filters) render "download_csv", locals: { search_term:, count: unpaginated_filtered_logs.size, post_path: email_csv_sales_logs_path, codes_only: codes_only_export? } end def email_csv all_orgs = params["organisation_select"] == "all" - EmailCsvJob.perform_later(current_user, search_term, @session_filters, all_orgs, nil, codes_only_export?, "sales") + EmailCsvJob.perform_later(current_user, search_term, @log_filter_manager.applied_filters, all_orgs, nil, codes_only_export?, "sales") redirect_to csv_confirmation_sales_logs_path end @@ -80,6 +81,10 @@ class SalesLogsController < LogsController private + def log_filter_manager + @log_filter_manager = LogsFilterManager.new(@session_filters, current_user) + end + def extract_bulk_upload_from_session_filters filter_service = FilterService.new(current_user:, session:) @bulk_upload = filter_service.bulk_upload