2023-09-11 16:36:55 +02:00
|
|
|
class Dossiers::ExportLinkComponent < ApplicationComponent
|
2023-06-08 11:25:39 +02:00
|
|
|
include ApplicationHelper
|
|
|
|
|
2023-01-13 15:36:13 +01:00
|
|
|
def initialize(procedure:, exports:, statut: nil, count: nil, class_btn: nil, export_url: nil)
|
2022-05-11 16:30:41 +02:00
|
|
|
@procedure = procedure
|
|
|
|
@exports = exports
|
|
|
|
@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
|
|
|
|
|
2022-11-16 11:50:19 +01:00
|
|
|
def allowed_format?(item)
|
|
|
|
item.fetch(:format) != :json || @procedure.active_revision.carte?
|
2022-05-11 16:30:41 +02:00
|
|
|
end
|
|
|
|
|
2023-09-13 13:06:50 +02:00
|
|
|
def download_export_path(export_format:, statut:, force_export: false, 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,
|
|
|
|
force_export: force_export,
|
2023-09-13 13:06:50 +02:00
|
|
|
statut: statut,
|
2022-05-11 16:30:41 +02:00
|
|
|
no_progress_notification: no_progress_notification)
|
|
|
|
end
|
|
|
|
|
|
|
|
def refresh_button_options(export)
|
|
|
|
{
|
2023-09-11 16:36:55 +02:00
|
|
|
title: t(".refresh_old_export", export_format: ".#{export.format}"),
|
|
|
|
class: "fr-btn fr-btn--sm fr-icon-refresh-line fr-btn--icon-left fr-btn--tertiary fr-mt-1w"
|
2022-05-11 16:30:41 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def ready_link_label(export)
|
2023-09-11 16:36:55 +02:00
|
|
|
t(".everything_ready",
|
2022-05-11 16:30:41 +02:00
|
|
|
export_format: ".#{export.format}")
|
|
|
|
end
|
|
|
|
|
2023-09-11 16:36:55 +02:00
|
|
|
def ready_link_label_extra_infos(export)
|
|
|
|
t(".ready_link_label_extra_infos",
|
|
|
|
export_time: helpers.time_ago_in_words(export.updated_at),
|
|
|
|
export_tabs: export.statut.to_s)
|
|
|
|
end
|
|
|
|
|
2022-05-11 16:30:41 +02:00
|
|
|
def pending_label(export)
|
|
|
|
t(".everything_pending_html",
|
|
|
|
export_time: time_ago_in_words(export.created_at),
|
|
|
|
export_format: ".#{export.format}")
|
|
|
|
end
|
|
|
|
|
2023-09-11 16:36:55 +02:00
|
|
|
def failed_label(export)
|
|
|
|
t(".failed_label",
|
|
|
|
export_format: ".#{export.format}")
|
|
|
|
end
|
|
|
|
|
2022-05-11 16:30:41 +02:00
|
|
|
def poll_controller_options(export)
|
|
|
|
{
|
|
|
|
controller: 'turbo-poll',
|
2023-09-13 13:06:50 +02:00
|
|
|
turbo_poll_url_value: download_export_path(export_format: export.format, statut: export.statut, no_progress_notification: true),
|
2022-05-11 16:30:41 +02:00
|
|
|
turbo_poll_interval_value: 6000,
|
|
|
|
turbo_poll_max_checks_value: 10
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|