2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-09-11 16:36:55 +02:00
|
|
|
class Dossiers::ExportDropdownComponent < ApplicationComponent
|
2023-06-08 11:25:39 +02:00
|
|
|
include ApplicationHelper
|
|
|
|
|
2024-11-12 18:14:26 +01:00
|
|
|
attr_reader :wrapper
|
2024-11-13 18:07:01 +01:00
|
|
|
attr_reader :export_templates
|
2024-11-12 18:14:26 +01:00
|
|
|
|
|
|
|
def initialize(procedure:, export_templates: nil, statut: nil, count: nil, class_btn: nil, export_url: nil, show_export_template_tab: true, wrapper: :div)
|
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
|
2024-10-25 15:00:27 +02:00
|
|
|
@show_export_template_tab = show_export_template_tab
|
2024-11-12 18:14:26 +01:00
|
|
|
@wrapper = wrapper
|
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
|
|
|
|
end
|