2023-09-11 16:36:55 +02:00
|
|
|
class Dossiers::ExportDropdownComponent < ApplicationComponent
|
2023-06-08 11:25:39 +02:00
|
|
|
include ApplicationHelper
|
|
|
|
|
2024-03-13 13:51:22 +01:00
|
|
|
def initialize(procedure:, export_templates: nil, statut: nil, count: nil, class_btn: nil, export_url: nil)
|
2022-05-11 16:30:41 +02:00
|
|
|
@procedure = procedure
|
2024-03-13 13:51:22 +01:00
|
|
|
@export_templates = export_templates
|
2022-05-11 16:30:41 +02:00
|
|
|
@statut = statut
|
|
|
|
@count = count
|
2023-01-13 15:36:13 +01:00
|
|
|
@class_btn = class_btn
|
2022-07-04 16:13:15 +02:00
|
|
|
@export_url = export_url
|
2022-05-11 16:30:41 +02:00
|
|
|
end
|
|
|
|
|
2023-09-13 13:01:57 +02:00
|
|
|
def formats
|
2022-11-16 11:50:19 +01:00
|
|
|
if @statut
|
2023-09-13 13:01:57 +02:00
|
|
|
Export::FORMATS.filter(&method(:allowed_format?))
|
2022-11-16 11:50:19 +01:00
|
|
|
else
|
2023-09-13 13:01:57 +02:00
|
|
|
Export::FORMATS_WITH_TIME_SPAN
|
|
|
|
end.map { _1[:format] }
|
2022-11-16 11:50:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def allowed_format?(item)
|
|
|
|
item.fetch(:format) != :json || @procedure.active_revision.carte?
|
2022-05-11 16:30:41 +02:00
|
|
|
end
|
|
|
|
|
2024-03-08 17:15:47 +01:00
|
|
|
def download_export_path(export_format: nil, export_template_id: nil, no_progress_notification: nil)
|
2022-07-04 16:13:15 +02:00
|
|
|
@export_url.call(@procedure,
|
2024-03-08 17:15:47 +01:00
|
|
|
export_format:,
|
|
|
|
export_template_id:,
|
2022-05-11 16:30:41 +02:00
|
|
|
statut: @statut,
|
|
|
|
no_progress_notification: no_progress_notification)
|
|
|
|
end
|
2024-03-08 17:15:47 +01:00
|
|
|
|
|
|
|
def export_templates
|
|
|
|
@export_templates
|
|
|
|
end
|
2022-05-11 16:30:41 +02:00
|
|
|
end
|