demarches-normaliennes/app/controllers/administrateurs/exports_controller.rb

53 lines
1.4 KiB
Ruby
Raw Normal View History

2022-07-04 16:13:15 +02:00
module Administrateurs
class ExportsController < AdministrateurController
before_action :retrieve_procedure
before_action :ensure_not_super_admin!
2022-07-04 16:13:15 +02:00
def download
export = Export.find_or_create_fresh_export(export_format, all_groupe_instructeurs, **export_options)
@dossiers_count = export.count
2022-07-04 16:13:15 +02:00
if export.available?
2022-07-04 16:13:15 +02:00
respond_to do |format|
format.turbo_stream do
flash.notice = t('administrateurs.exports.export_available_html', file_format: export.format, file_url: export.file.url)
2022-07-04 16:13:15 +02:00
end
format.html do
redirect_to url_from(export.file.url)
2022-07-04 16:13:15 +02:00
end
end
else
respond_to do |format|
format.turbo_stream do
if !params[:no_progress_notification]
flash.notice = t('administrateurs.exports.export_pending')
2022-07-04 16:13:15 +02:00
end
end
format.html do
redirect_to admin_procedure_archives_url(@procedure), notice: t('administrateurs.exports.export_pending')
2022-07-04 16:13:15 +02:00
end
end
end
end
private
def export_format
@export_format ||= params[:export_format]
end
def export_options
@export_options ||= {
time_span_type: params[:time_span_type],
statut: params[:statut],
procedure_presentation: nil
}.compact
end
def all_groupe_instructeurs
@procedure.groupe_instructeurs
end
end
end