2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-09-11 16:36:55 +02:00
|
|
|
class Dossiers::ExportLinkComponent < ApplicationComponent
|
2023-06-08 11:25:39 +02:00
|
|
|
include ApplicationHelper
|
2023-09-20 14:00:18 +02:00
|
|
|
include TabsHelper
|
2023-06-08 11:25:39 +02:00
|
|
|
|
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
|
|
|
|
|
2024-05-29 15:42:49 +02:00
|
|
|
def download_export_path(export_format:, statut:, export_template_id: nil, 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,
|
2024-05-29 15:42:49 +02:00
|
|
|
export_template_id:,
|
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
|
|
|
|
|
2023-09-19 16:39:23 +02:00
|
|
|
def time_info(export)
|
|
|
|
if export.available?
|
|
|
|
t(".ready_link_label_time_info", export_time: helpers.time_ago_in_words(export.updated_at))
|
|
|
|
else
|
2023-09-21 13:59:14 +02:00
|
|
|
t(".not_ready_link_label_time_info", export_time: helpers.time_ago_in_words(export.created_at))
|
2023-09-19 16:39:23 +02:00
|
|
|
end
|
2022-05-11 16:30:41 +02:00
|
|
|
end
|
|
|
|
|
2023-09-19 16:39:23 +02:00
|
|
|
def export_title(export)
|
2024-10-14 22:23:59 +02:00
|
|
|
if !export.built_from_procedure_presentation?
|
2023-09-21 13:59:14 +02:00
|
|
|
t(".export_title_everything", export_format: export.format)
|
|
|
|
elsif export.tous?
|
|
|
|
t(".export_title", export_format: export.format, count: export.count)
|
2023-09-20 12:22:43 +02:00
|
|
|
else
|
2023-09-21 13:59:14 +02:00
|
|
|
t(".export_title_with_tab", export_tabs: human_export_status(export), export_format: export.format, count: export.count)
|
2023-09-20 12:22:43 +02:00
|
|
|
end
|
2022-05-11 16:30:41 +02:00
|
|
|
end
|
|
|
|
|
2023-09-20 14:00:18 +02:00
|
|
|
def human_export_status(export)
|
|
|
|
key = tab_i18n_key_from_status(export.statut)
|
|
|
|
|
|
|
|
t(key, count: export.count) || export.statut
|
|
|
|
end
|
|
|
|
|
2023-09-19 16:39:23 +02:00
|
|
|
def badge(export)
|
|
|
|
if export.available?
|
|
|
|
content_tag(:span, t(".success_label"), { class: "fr-badge fr-badge--success fr-text-right" })
|
|
|
|
elsif export.failed?
|
|
|
|
content_tag(:span, t(".failed_label"), { class: "fr-badge fr-badge--warning fr-text-right" })
|
|
|
|
else
|
|
|
|
content_tag(:span, t(".pending_label"), { class: "fr-badge fr-badge--info fr-text-right" })
|
|
|
|
end
|
2023-09-11 16:36:55 +02:00
|
|
|
end
|
|
|
|
|
2023-09-19 16:39:23 +02:00
|
|
|
def export_button(export)
|
|
|
|
if export.available?
|
2023-09-21 13:59:14 +02:00
|
|
|
render Dsfr::DownloadComponent.new(attachment: export.file, name: t('.download_export'))
|
2023-09-19 16:39:23 +02:00
|
|
|
elsif export.pending?
|
2023-09-20 16:04:22 +02:00
|
|
|
content_tag(:a, t('.refresh_page'), { href: "", class: 'fr-btn fr-btn--sm fr-btn--tertiary' })
|
2023-09-19 16:39:23 +02:00
|
|
|
end
|
2022-05-11 16:30:41 +02:00
|
|
|
end
|
|
|
|
|
2023-09-19 16:39:23 +02:00
|
|
|
def refresh_button_options(export)
|
2022-05-11 16:30:41 +02:00
|
|
|
{
|
2023-09-28 12:41:19 +02:00
|
|
|
title: t(".refresh_old_export"),
|
|
|
|
"aria-label" => t(".refresh_old_export"),
|
|
|
|
class: "fr-btn fr-btn--sm fr-icon-refresh-line fr-btn--tertiary fr-btn--icon-left"
|
2022-05-11 16:30:41 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|