Browse Source

feat: add to sales, use before_action

CLDC-2257-refactor-filters
natdeanlewissoftwire 2 years ago
parent
commit
30c35e23ca
  1. 4
      app/controllers/lettings_logs_controller.rb
  2. 11
      app/controllers/sales_logs_controller.rb

4
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 :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 :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 :authenticate_scope!, only: %i[download_csv email_csv]
before_action :extract_bulk_upload_from_session_filters, only: [:index] before_action :extract_bulk_upload_from_session_filters, only: [:index]
@ -13,7 +14,6 @@ class LettingsLogsController < LogsController
def index def index
respond_to do |format| respond_to do |format|
format.html do format.html do
@log_filter_manager = LogsFilterManager.new(@session_filters, current_user)
all_logs = current_user.lettings_logs.visible all_logs = current_user.lettings_logs.visible
unpaginated_filtered_logs = filtered_logs(all_logs, search_term, @log_filter_manager.applied_filters) unpaginated_filtered_logs = filtered_logs(all_logs, search_term, @log_filter_manager.applied_filters)
@ -87,7 +87,7 @@ class LettingsLogsController < LogsController
end end
def download_csv 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? } render "download_csv", locals: { search_term:, count: unpaginated_filtered_logs.size, post_path: email_csv_lettings_logs_path, codes_only: codes_only_export? }
end end

11
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 :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 :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 :authenticate_scope!, only: %i[download_csv email_csv]
before_action :extract_bulk_upload_from_session_filters, only: [:index] before_action :extract_bulk_upload_from_session_filters, only: [:index]
@ -16,7 +17,7 @@ class SalesLogsController < LogsController
respond_to do |format| respond_to do |format|
format.html do format.html do
all_logs = current_user.sales_logs.visible 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 @search_term = search_term
@pagy, @logs = pagy(unpaginated_filtered_logs) @pagy, @logs = pagy(unpaginated_filtered_logs)
@ -57,14 +58,14 @@ class SalesLogsController < LogsController
end end
def download_csv 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? } render "download_csv", locals: { search_term:, count: unpaginated_filtered_logs.size, post_path: email_csv_sales_logs_path, codes_only: codes_only_export? }
end end
def email_csv def email_csv
all_orgs = params["organisation_select"] == "all" 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 redirect_to csv_confirmation_sales_logs_path
end end
@ -80,6 +81,10 @@ class SalesLogsController < LogsController
private private
def log_filter_manager
@log_filter_manager = LogsFilterManager.new(@session_filters, current_user)
end
def extract_bulk_upload_from_session_filters def extract_bulk_upload_from_session_filters
filter_service = FilterService.new(current_user:, session:) filter_service = FilterService.new(current_user:, session:)
@bulk_upload = filter_service.bulk_upload @bulk_upload = filter_service.bulk_upload

Loading…
Cancel
Save