2022-07-04 16:13:15 +02:00
|
|
|
module Administrateurs
|
|
|
|
class ExportsController < AdministrateurController
|
2022-07-21 15:23:49 +02:00
|
|
|
before_action :retrieve_procedure
|
|
|
|
before_action :ensure_not_super_admin!
|
2022-07-04 16:13:15 +02:00
|
|
|
|
|
|
|
def download
|
2024-02-07 17:19:50 +01:00
|
|
|
export = Export.find_or_create_fresh_export(export_format, all_groupe_instructeurs, current_administrateur, **export_options)
|
2022-11-15 18:53:23 +01:00
|
|
|
@dossiers_count = export.count
|
2022-07-04 16:13:15 +02:00
|
|
|
|
2022-07-07 18:15:48 +02:00
|
|
|
if export.available?
|
2022-07-04 16:13:15 +02:00
|
|
|
respond_to do |format|
|
|
|
|
format.turbo_stream do
|
2023-09-18 17:06:18 +02:00
|
|
|
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
|
2023-03-16 10:02:35 +01:00
|
|
|
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]
|
2023-09-18 17:06:18 +02:00
|
|
|
flash.notice = t('administrateurs.exports.export_pending')
|
2022-07-04 16:13:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
format.html do
|
2023-09-18 17:06:18 +02:00
|
|
|
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
|
2024-03-12 15:39:29 +01:00
|
|
|
@export_format ||= params[:export_format].presence || export_template&.kind
|
|
|
|
end
|
|
|
|
|
|
|
|
def export_template
|
|
|
|
@export_template ||= ExportTemplate.find(params[:export_template_id]) if params[:export_template_id].present?
|
2022-07-04 16:13:15 +02:00
|
|
|
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
|