diff --git a/app/components/dossiers/export_component.rb b/app/components/dossiers/export_component.rb new file mode 100644 index 000000000..96e4f5d7a --- /dev/null +++ b/app/components/dossiers/export_component.rb @@ -0,0 +1,49 @@ +class Dossiers::ExportComponent < ApplicationComponent + def initialize(procedure:, exports:, statut:, count:) + @procedure = procedure + @exports = exports + @statut = statut + @count = count + end + + def exports + helpers.exports_list(@exports, @statut) + end + + def download_export_path(export_format:, force_export: false, no_progress_notification: nil) + download_export_instructeur_procedure_path(@procedure, + export_format: export_format, + statut: @statut, + force_export: force_export, + no_progress_notification: no_progress_notification) + end + + def refresh_button_options(export) + { + title: t(".everything_short", export_format: ".#{export.format}"), + class: "button small", + style: "padding-right: 2px" + } + end + + def ready_link_label(export) + t(".everything_ready_html", + export_time: helpers.time_ago_in_words(export.updated_at), + export_format: ".#{export.format}") + end + + def pending_label(export) + t(".everything_pending_html", + export_time: time_ago_in_words(export.created_at), + export_format: ".#{export.format}") + end + + def poll_controller_options(export) + { + controller: 'turbo-poll', + turbo_poll_url_value: download_export_path(export_format: export.format, no_progress_notification: true), + turbo_poll_interval_value: 6000, + turbo_poll_max_checks_value: 10 + } + end +end diff --git a/app/components/dossiers/export_component/export_component.en.yml b/app/components/dossiers/export_component/export_component.en.yml new file mode 100644 index 000000000..c548a2b08 --- /dev/null +++ b/app/components/dossiers/export_component/export_component.en.yml @@ -0,0 +1,12 @@ +--- +en: + everything_csv_html: Ask an export in format .csv
(only folders, without repeatable fields) + everything_xlsx_html: Ask an export in format .xlsx + everything_ods_html: Ask an export in format .ods + everything_zip_html: Ask an export in format .zip + everything_short: Ask an export in format%{export_format} + everything_pending_html: Ask an export in format %{export_format} is being generated
(ask %{export_time} ago) + everything_ready_html: Download the export in format %{export_format}
(generated %{export_time} ago) + download: + one: Download a file + other: Download %{count} files diff --git a/app/components/dossiers/export_component/export_component.fr.yml b/app/components/dossiers/export_component/export_component.fr.yml new file mode 100644 index 000000000..7e185ccda --- /dev/null +++ b/app/components/dossiers/export_component/export_component.fr.yml @@ -0,0 +1,12 @@ +--- +fr: + everything_csv_html: Demander un export au format .csv
(uniquement les dossiers, sans les champs répétables) + everything_xlsx_html: Demander un export au format .xlsx + everything_ods_html: Demander un export au format .ods + everything_zip_html: Demander un export au format .zip + everything_short: Demander un export au format %{export_format} + everything_pending_html: Un export au format %{export_format} est en train d’être généré
(demandé il y a %{export_time}) + everything_ready_html: Télécharger l’export au format %{export_format}
(généré il y a %{export_time}) + download: + one: Télécharger un dossier + other: Télécharger %{count} dossiers diff --git a/app/components/dossiers/export_component/export_component.html.haml b/app/components/dossiers/export_component/export_component.html.haml new file mode 100644 index 000000000..aad58e0c5 --- /dev/null +++ b/app/components/dossiers/export_component/export_component.html.haml @@ -0,0 +1,22 @@ +%span.dropdown{ data: { controller: 'menu-button' } } + %button.button.dropdown-button{ data: { menu_button_target: 'button' } } + = t(".download", count: @count) + #download-menu.dropdown-content.fade-in-down{ style: 'width: 450px', data: { menu_button_target: 'menu' } } + %ul.dropdown-items{ 'data-turbo': 'true' } + - exports.each do |item| + - export = item[:export] + %li + - if export.nil? + // i18n-tasks-use t('.everything_csv_html') + // i18n-tasks-use t('.everything_xlsx_html') + // i18n-tasks-use t('.everything_ods_html') + // i18n-tasks-use t('.everything_zip_html') + = link_to t(".everything_#{item[:format]}_html"), download_export_path(export_format: item[:format]), data: { turbo_method: :post } + - elsif export.ready? + = link_to ready_link_label(export), export.file.service_url, target: "_blank", rel: "noopener" + - if export.old? + = button_to download_export_path(export_format: export.format, force_export: true), **refresh_button_options(export) do + .icon.retry + - else + %span{ data: poll_controller_options(export) } + = pending_label(export) diff --git a/app/views/instructeurs/procedures/_dossiers_export.html.haml b/app/views/instructeurs/procedures/_dossiers_export.html.haml deleted file mode 100644 index cffde1c1a..000000000 --- a/app/views/instructeurs/procedures/_dossiers_export.html.haml +++ /dev/null @@ -1,23 +0,0 @@ -%span.dropdown{ data: { controller: 'menu-button' } } - %button.button.dropdown-button{ data: { menu_button_target: 'button' } } - = t(".download", count: count) - #download-menu.dropdown-content.fade-in-down{ style: 'width: 450px', data: { menu_button_target: 'menu' } } - %ul.dropdown-items - - exports_list(exports, statut).each do |item| - - format = item[:format] - - export = item[:export] - %li - - if export.nil? - // i18n-tasks-use t('.everything_csv_html') - // i18n-tasks-use t('.everything_xlsx_html') - // i18n-tasks-use t('.everything_ods_html') - // i18n-tasks-use t('.everything_zip_html') - = link_to t(".everything_#{format}_html"), download_export_instructeur_procedure_path(procedure, statut: statut, export_format: format), remote: true - - elsif export.ready? - = link_to t(".everything_ready_html", export_time: time_ago_in_words(export.updated_at), export_format: ".#{format}"), export.file.service_url, target: "_blank", rel: "noopener" - - if export.old? - = button_to download_export_instructeur_procedure_path(procedure, export_format: format, statut: statut, force_export: true), class: "button small", style: "padding-right: 2px", title: t(".everything_short", export_format: ".#{format}"), remote: true, method: :get, params: { export_format: format, statut: statut, force_export: true } do - .icon.retry - - else - %span{ 'data-export-poll-url': download_export_instructeur_procedure_path(procedure, export_format: format, statut: statut, no_progress_notification: true) } - = t(".everything_pending_html", export_time: time_ago_in_words(export.created_at), export_format: ".#{format}") diff --git a/config/locales/views/instructeurs/procedures/en.yml b/config/locales/views/instructeurs/procedures/en.yml index fd70b140f..f8b2fd478 100644 --- a/config/locales/views/instructeurs/procedures/en.yml +++ b/config/locales/views/instructeurs/procedures/en.yml @@ -9,17 +9,6 @@ en: archived: archived dossiers_close_to_expiration: expiring dossiers_supprimes_recemment: recently deleted - dossiers_export: - everything_csv_html: Ask an export in format .csv
(only folders, without repeatable fields) - everything_xlsx_html: Ask an export in format .xlsx - everything_ods_html: Ask an export in format .ods - everything_zip_html: Ask an export in format .zip - everything_short: Ask an export in format%{export_format} - everything_pending_html: Ask an export in format %{export_format} is being generated
(ask %{export_time} ago) - everything_ready_html: Download the export in format %{export_format}
(generated %{export_time} ago) - download: - one: Download a file - other: Download %{count} files email_usagers: contact_users: Contact users (draft) notice: "You will send a message to %{dossiers_count} whose files are in draft, in the instructor groups : %{groupe_instructeurs}." diff --git a/config/locales/views/instructeurs/procedures/fr.yml b/config/locales/views/instructeurs/procedures/fr.yml index 7d9f79ed1..8436728af 100644 --- a/config/locales/views/instructeurs/procedures/fr.yml +++ b/config/locales/views/instructeurs/procedures/fr.yml @@ -8,18 +8,7 @@ fr: all: dossiers archived: archivés dossiers_close_to_expiration: expirant - dossiers_supprimes_recemment: supprimés - dossiers_export: - everything_csv_html: Demander un export au format .csv
(uniquement les dossiers, sans les champs répétables) - everything_xlsx_html: Demander un export au format .xlsx - everything_ods_html: Demander un export au format .ods - everything_zip_html: Demander un export au format .zip - everything_short: Demander un export au format %{export_format} - everything_pending_html: Un export au format %{export_format} est en train d’être généré
(demandé il y a %{export_time}) - everything_ready_html: Télécharger l’export au format %{export_format}
(généré il y a %{export_time}) - download: - one: Télécharger un dossier - other: Télécharger %{count} dossiers + dossiers_supprimes_recemment: supprimés email_usagers: contact_users: Contacter les usagers (brouillon) notice: "Vous allez envoyer un message à %{dossiers_count} dont les dossiers sont en brouillon, dans les groupes instructeurs : %{groupe_instructeurs}."