From 3af93735a3224073b136eabe0f707be60ce123fc Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 20 Sep 2023 13:03:11 +0200 Subject: [PATCH] feat(exports): turbo poll for pending exports --- .../export_link_component/export_link_component.html.haml | 2 +- app/controllers/instructeurs/procedures_controller.rb | 5 +++++ app/views/instructeurs/procedures/exports.html.haml | 4 +++- app/views/instructeurs/procedures/exports.turbo_stream.haml | 3 +++ 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 app/views/instructeurs/procedures/exports.turbo_stream.haml diff --git a/app/components/dossiers/export_link_component/export_link_component.html.haml b/app/components/dossiers/export_link_component/export_link_component.html.haml index 3e57732d0..e9fcb77ee 100644 --- a/app/components/dossiers/export_link_component/export_link_component.html.haml +++ b/app/components/dossiers/export_link_component/export_link_component.html.haml @@ -1,4 +1,4 @@ -%ul.fr-raw-list +%ul#exports-list.fr-raw-list - @exports.each do |export| %li.fr-mb-3w .flex diff --git a/app/controllers/instructeurs/procedures_controller.rb b/app/controllers/instructeurs/procedures_controller.rb index d3cdbe7e7..ba0a7df0c 100644 --- a/app/controllers/instructeurs/procedures_controller.rb +++ b/app/controllers/instructeurs/procedures_controller.rb @@ -231,6 +231,11 @@ module Instructeurs value: DateTime.current, expires: Export::MAX_DUREE_GENERATION + Export::MAX_DUREE_CONSERVATION_EXPORT } + + respond_to do |format| + format.turbo_stream + format.html + end end def email_usagers diff --git a/app/views/instructeurs/procedures/exports.html.haml b/app/views/instructeurs/procedures/exports.html.haml index af3f6acfa..97dd7c79e 100644 --- a/app/views/instructeurs/procedures/exports.html.haml +++ b/app/views/instructeurs/procedures/exports.html.haml @@ -10,8 +10,10 @@ = render Dsfr::CalloutComponent.new(title: nil) do |c| - c.with_body do %p= t('.export_description') + - if @exports.present? - = render Dossiers::ExportLinkComponent.new(procedure: @procedure, exports: @exports, statut: @statut, count: @dossiers_count, class_btn: 'fr-btn--tertiary', export_url: method(:download_export_instructeur_procedure_path)) + %div{ data: @exports.any?(&:pending?) ? { controller: "turbo-poll", turbo_poll_url_value: "", turbo_poll_interval_value: 10_000, turbo_poll_max_checks_value: 6 } : {} } + = render Dossiers::ExportLinkComponent.new(procedure: @procedure, exports: @exports, statut: @statut, count: @dossiers_count, class_btn: 'fr-btn--tertiary', export_url: method(:download_export_instructeur_procedure_path)) - else = t('.no_export_html', expiration_time: Export::MAX_DUREE_CONSERVATION_EXPORT.in_hours.to_i ) diff --git a/app/views/instructeurs/procedures/exports.turbo_stream.haml b/app/views/instructeurs/procedures/exports.turbo_stream.haml new file mode 100644 index 000000000..bdf3cc729 --- /dev/null +++ b/app/views/instructeurs/procedures/exports.turbo_stream.haml @@ -0,0 +1,3 @@ += turbo_stream.replace "exports-list" do + - if @exports.present? + = render Dossiers::ExportLinkComponent.new(procedure: @procedure, exports: @exports, statut: @statut, count: @dossiers_count, class_btn: 'fr-btn--tertiary', export_url: method(:download_export_instructeur_procedure_path))