refactor(dossier): add Dossier::ExportComponent
This commit is contained in:
parent
7e1c793728
commit
2ce389d474
7 changed files with 96 additions and 46 deletions
49
app/components/dossiers/export_component.rb
Normal file
49
app/components/dossiers/export_component.rb
Normal file
|
@ -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
|
|
@ -0,0 +1,12 @@
|
||||||
|
---
|
||||||
|
en:
|
||||||
|
everything_csv_html: Ask an export in format .csv<br>(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<br>(ask %{export_time} ago)
|
||||||
|
everything_ready_html: Download the export in format %{export_format}<br>(generated %{export_time} ago)
|
||||||
|
download:
|
||||||
|
one: Download a file
|
||||||
|
other: Download %{count} files
|
|
@ -0,0 +1,12 @@
|
||||||
|
---
|
||||||
|
fr:
|
||||||
|
everything_csv_html: Demander un export au format .csv<br>(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é<br>(demandé il y a %{export_time})
|
||||||
|
everything_ready_html: Télécharger l’export au format %{export_format}<br>(généré il y a %{export_time})
|
||||||
|
download:
|
||||||
|
one: Télécharger un dossier
|
||||||
|
other: Télécharger %{count} dossiers
|
|
@ -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)
|
|
@ -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}")
|
|
|
@ -9,17 +9,6 @@ en:
|
||||||
archived: archived
|
archived: archived
|
||||||
dossiers_close_to_expiration: expiring
|
dossiers_close_to_expiration: expiring
|
||||||
dossiers_supprimes_recemment: recently deleted
|
dossiers_supprimes_recemment: recently deleted
|
||||||
dossiers_export:
|
|
||||||
everything_csv_html: Ask an export in format .csv<br>(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<br>(ask %{export_time} ago)
|
|
||||||
everything_ready_html: Download the export in format %{export_format}<br>(generated %{export_time} ago)
|
|
||||||
download:
|
|
||||||
one: Download a file
|
|
||||||
other: Download %{count} files
|
|
||||||
email_usagers:
|
email_usagers:
|
||||||
contact_users: Contact users (draft)
|
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}."
|
notice: "You will send a message to %{dossiers_count} whose files are in draft, in the instructor groups : %{groupe_instructeurs}."
|
||||||
|
|
|
@ -9,17 +9,6 @@ fr:
|
||||||
archived: archivés
|
archived: archivés
|
||||||
dossiers_close_to_expiration: expirant
|
dossiers_close_to_expiration: expirant
|
||||||
dossiers_supprimes_recemment: supprimés
|
dossiers_supprimes_recemment: supprimés
|
||||||
dossiers_export:
|
|
||||||
everything_csv_html: Demander un export au format .csv<br>(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é<br>(demandé il y a %{export_time})
|
|
||||||
everything_ready_html: Télécharger l’export au format %{export_format}<br>(généré il y a %{export_time})
|
|
||||||
download:
|
|
||||||
one: Télécharger un dossier
|
|
||||||
other: Télécharger %{count} dossiers
|
|
||||||
email_usagers:
|
email_usagers:
|
||||||
contact_users: Contacter les usagers (brouillon)
|
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}."
|
notice: "Vous allez envoyer un message à %{dossiers_count} dont les dossiers sont en brouillon, dans les groupes instructeurs : %{groupe_instructeurs}."
|
||||||
|
|
Loading…
Reference in a new issue