Improuve export UI
This commit is contained in:
parent
a88f780252
commit
651a928b7c
4 changed files with 26 additions and 6 deletions
|
@ -169,6 +169,11 @@ module Instructeurs
|
|||
|
||||
export = Export.find_or_create_export(export_format, groupe_instructeurs)
|
||||
|
||||
if export.ready? && export.old? && params[:force_export]
|
||||
export.destroy
|
||||
export = Export.find_or_create_export(export_format, groupe_instructeurs)
|
||||
end
|
||||
|
||||
if export.ready?
|
||||
respond_to do |format|
|
||||
format.js do
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
# updated_at :datetime not null
|
||||
#
|
||||
class Export < ApplicationRecord
|
||||
MAX_DUREE_CONSERVATION_EXPORT = 1.hour
|
||||
MAX_DUREE_CONSERVATION_EXPORT = 3.hours
|
||||
|
||||
enum format: {
|
||||
csv: 'csv',
|
||||
|
@ -45,6 +45,10 @@ class Export < ApplicationRecord
|
|||
file.attached?
|
||||
end
|
||||
|
||||
def old?
|
||||
updated_at < 20.minutes.ago
|
||||
end
|
||||
|
||||
def self.find_or_create_export(format, groupe_instructeurs)
|
||||
create_with(groupe_instructeurs: groupe_instructeurs)
|
||||
.create_or_find_by(format: format, key: generate_cache_key(groupe_instructeurs))
|
||||
|
|
|
@ -7,11 +7,12 @@
|
|||
- [[xlsx_export, :xlsx], [ods_export, :ods], [csv_export, :csv]].each do |(export, format)|
|
||||
%li
|
||||
- if export.nil?
|
||||
- export_text = "Demander un export au format .#{format}"
|
||||
- if format == :csv
|
||||
- export_text = "Demander un export au format .#{format}<br/>(uniquement les dossiers, sans les champs répétables)".html_safe
|
||||
= link_to export_text, download_export_instructeur_procedure_path(procedure, export_format: format), remote: true
|
||||
= link_to t("#{format}_html", scope: [:instructeurs, :procedure, :export_stale]), download_export_instructeur_procedure_path(procedure, export_format: format), remote: true
|
||||
- elsif export.ready?
|
||||
= link_to "Télécharger l'export au format .#{format}", export.file.service_url, target: "_blank", rel: "noopener"
|
||||
= link_to t(:export_ready_html, export_time: time_ago_in_words(export.updated_at), export_format: ".#{format}", scope: [:instructeurs, :procedure]), export.file.service_url, target: "_blank", rel: "noopener"
|
||||
- if export.old?
|
||||
= button_to download_export_instructeur_procedure_path(procedure, export_format: format, force_export: true), class: "button small", style: "padding-right: 2px", title: t(:short, export_format: ".#{format}", scope: [:instructeurs, :procedure, :export_stale]), remote: true, method: :get, params: { export_format: format, force_export: true } do
|
||||
.icon.retry
|
||||
- else
|
||||
%span{ 'data-export-poll-url': download_export_instructeur_procedure_path(procedure, export_format: format, no_progress_notification: true) }
|
||||
= t(:export_pending_html, export_time: time_ago_in_words(export.created_at), export_format: ".#{format}", scope: [:instructeurs, :procedure])
|
||||
|
|
10
config/locales/views/instructeurs/fr.yml
Normal file
10
config/locales/views/instructeurs/fr.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
fr:
|
||||
instructeurs:
|
||||
procedure:
|
||||
export_stale:
|
||||
short: Demander un export au format %{export_format}
|
||||
csv_html: Demander un export au format .csv<br>(uniquement les dossiers, sans les champs répétables)
|
||||
xlsx_html: Demander un export au format .xlsx
|
||||
ods_html: Demander un export au format .ods
|
||||
export_ready_html: Télécharger l’export au format %{export_format}<br>(généré il y a %{export_time})
|
||||
export_pending_html: Un export au format %{export_format} est en train d’être généré<br>(demandé il y a %{export_time})
|
Loading…
Reference in a new issue