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
|
2022-11-15 18:53:23 +01:00
|
|
|
export = Export.find_or_create_export(export_format, all_groupe_instructeurs, force: force_export?, **export_options)
|
|
|
|
@dossiers_count = export.count
|
|
|
|
assign_exports
|
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
|
2022-11-15 18:53:23 +01:00
|
|
|
flash.notice = export.flash_message
|
2022-07-04 16:13:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
format.html do
|
|
|
|
redirect_to export.file.service_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
respond_to do |format|
|
|
|
|
format.turbo_stream do
|
|
|
|
if !params[:no_progress_notification]
|
2022-11-15 18:53:23 +01:00
|
|
|
flash.notice = export.flash_message
|
2022-07-04 16:13:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
format.html do
|
2022-11-15 18:53:23 +01:00
|
|
|
redirect_to admin_procedure_archives_url(@procedure), notice: export.flash_message
|
2022-07-04 16:13:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def export_format
|
|
|
|
@export_format ||= params[:export_format]
|
|
|
|
end
|
|
|
|
|
|
|
|
def force_export?
|
|
|
|
@force_export ||= params[:force_export].present?
|
|
|
|
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
|
|
|
|
|
|
|
|
def assign_exports
|
|
|
|
@exports = Export.find_for_groupe_instructeurs(all_groupe_instructeurs.map(&:id), nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|