2023-09-11 16:36:55 +02:00
|
|
|
class Dossiers::ExportDropdownComponent < ApplicationComponent
|
2023-06-08 11:25:39 +02:00
|
|
|
include ApplicationHelper
|
|
|
|
|
2023-09-13 13:01:57 +02:00
|
|
|
def initialize(procedure:, statut: nil, count: nil, class_btn: nil, export_url: nil)
|
2022-05-11 16:30:41 +02:00
|
|
|
@procedure = procedure
|
|
|
|
@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
|
|
|
|
|
2023-09-28 12:41:19 +02:00
|
|
|
def download_export_path(export_format:, no_progress_notification: nil)
|
2022-07-04 16:13:15 +02:00
|
|
|
@export_url.call(@procedure,
|
2022-05-11 16:30:41 +02:00
|
|
|
export_format: export_format,
|
|
|
|
statut: @statut,
|
|
|
|
no_progress_notification: no_progress_notification)
|
|
|
|
end
|
|
|
|
end
|