diff --git a/app/controllers/admin/statistics/nominations_controller.rb b/app/controllers/admin/statistics/nominations_controller.rb index 667dccd21..fc0e67529 100644 --- a/app/controllers/admin/statistics/nominations_controller.rb +++ b/app/controllers/admin/statistics/nominations_controller.rb @@ -9,6 +9,11 @@ def create authorize :statistics, :send? @search = NominationStatsSearch.new(FormAnswer.all).search(permitted_params) + + data = generate_csv(@search.results) + file = current_admin.protected_files.create_from_raw_data(data, "nomination-statistics-export.csv") + + Admin::Statistics::NominationMailer.notify(current_admin.id, file.id).deliver_now redirect_to admin_statistics_nominations_path(search: permitted_params), success: "CSV with nomination statistics has been sent to #{current_admin.email}." end diff --git a/app/mailers/admin/statistics/nomination_mailer.rb b/app/mailers/admin/statistics/nomination_mailer.rb new file mode 100644 index 000000000..0477cf90c --- /dev/null +++ b/app/mailers/admin/statistics/nomination_mailer.rb @@ -0,0 +1,12 @@ +class Admin::Statistics::NominationMailer < ApplicationMailer + layout "mailer" + + def notify(identifier, file_identifier) + @admin = Admin.find(identifier) + @file = @admin.protected_files.find(file_identifier) + + subject = "Nomination statistics export - King's Award for Voluntary Service" + + view_mail ENV["GOV_UK_NOTIFY_API_TEMPLATE_ID"], to: @admin.email, subject: subject_with_env_prefix(subject) + end +end diff --git a/app/views/admin/statistics/nomination_mailer/notify.html.slim b/app/views/admin/statistics/nomination_mailer/notify.html.slim new file mode 100644 index 000000000..08c162ba1 --- /dev/null +++ b/app/views/admin/statistics/nomination_mailer/notify.html.slim @@ -0,0 +1,18 @@ +p.govuk-body + = "Dear #{@admin.first_name}," + +p.govuk-body + ' You requested an export of nomination statistics. + +p.govuk-body + ' Please find this report on the link below: + +p.govuk-body + = link_to admin_protected_file_url(@file), admin_protected_file_url(@file) + +p.govuk-body + ' Kind Regards, + + br + + ' The King's Awards Office