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

57 lines
1.6 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, current_administrateur, **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
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