add specific routes and action for polling

This commit is contained in:
Lisa Durand 2023-12-19 11:10:03 +01:00
parent 53f9f3cbdb
commit 1541da9d39
6 changed files with 43 additions and 26 deletions

View file

@ -208,6 +208,32 @@ module Instructeurs
end
end
def polling_last_export
@has_last_export = last_export_for(params[:statut])
if @has_last_export.available?
respond_to do |format|
format.turbo_stream do
flash.notice = t('instructeurs.procedures.export_available_html', file_format: @has_last_export.format, file_url: @has_last_export.file.url)
end
format.html do
redirect_to url_from(@has_last_export.file.url)
end
end
else
respond_to do |format|
format.turbo_stream do
if !params[:no_progress_notification]
flash.notice = t('instructeurs.procedures.export_pending_html', url: exports_instructeur_procedure_path(procedure))
end
end
format.html do
redirect_to exports_instructeur_procedure_path(procedure), notice: t('instructeurs.procedures.export_pending_html', url: exports_instructeur_procedure_path(procedure))
end
end
end
end
def email_notifications
@procedure = procedure
@assign_to = assign_tos.first
@ -381,11 +407,7 @@ module Instructeurs
end
def last_export_for(statut)
export = Export.where(instructeur_id: current_instructeur.id, statut: statut).last
if export.present?
return nil if export.updated_at < 1.hour.ago
end
export
Export.where(instructeur_id: current_instructeur.id, statut: statut, updated_at: 1.hour.ago..).last
end
def cookies_export_key

View file

@ -29,13 +29,4 @@
#last-export-alert
- if @has_last_export.present?
= render Dsfr::AlertComponent.new(state: :info, size: :sm, extra_class_names: 'fr-my-2w') do |c|
- c.body do
%p
- if @has_last_export.pending?
= t('instructeurs.procedures.last_export_pending')
- if @has_last_export.generated?
= t('instructeurs.procedures.last_export_available_html', file_format: @has_last_export.format, file_url: @has_last_export.file.url)
- if @has_last_export.failed?
= t('instructeurs.procedures.last_export_failed', file_format: @has_last_export.format)
= render partial: "last_export_alert"

View file

@ -0,0 +1,11 @@
- if @has_last_export.present?
%div{ data: @has_last_export.pending? ? { controller: "turbo-poll", turbo_poll_url_value: polling_last_export_instructeur_procedure_path(export_format: @has_last_export.format, statut: @statut), turbo_poll_interval_value: 5_000, turbo_poll_max_checks_value: 6 } : {} }
= render Dsfr::AlertComponent.new(state: :info, size: :sm, extra_class_names: 'fr-my-2w') do |c|
- c.body do
%p
- if @has_last_export.pending?
= t('instructeurs.procedures.last_export_pending')
- if @has_last_export.generated?
= t('instructeurs.procedures.last_export_available_html', file_format: @has_last_export.format, file_url: @has_last_export.file.url)
- if @has_last_export.failed?
= t('instructeurs.procedures.last_export_failed', file_format: @has_last_export.format)

View file

@ -8,14 +8,4 @@
= render Dossiers::ExportDropdownComponent.new(procedure: @procedure, statut: @statut, count: @dossiers_count, export_url: method(:download_export_instructeur_procedure_path))
= turbo_stream.update "last-export-alert" do
- if @has_last_export.present?
%div{ data: @has_last_export.pending? ? { controller: "turbo-poll", turbo_poll_url_value: download_export_instructeur_procedure_path(export_format: @has_last_export.format, statut: @statut), turbo_poll_interval_value: 5_000, turbo_poll_max_checks_value: 6 } : {} }
= render Dsfr::AlertComponent.new(state: :info, size: :sm, extra_class_names: 'fr-my-2w') do |c|
- c.body do
%p
- if @has_last_export.pending?
= t('instructeurs.procedures.last_export_pending')
- if @has_last_export.generated?
= t('instructeurs.procedures.last_export_available_html', file_format: @has_last_export.format, file_url: @has_last_export.file.url)
- if @has_last_export.failed?
= t('instructeurs.procedures.last_export_failed', file_format: @has_last_export.format)
= render partial: "last_export_alert"

View file

@ -0,0 +1,2 @@
= turbo_stream.update "last-export-alert" do
= render partial: "last_export_alert"

View file

@ -448,6 +448,7 @@ Rails.application.routes.draw do
get 'remove_filter'
get 'download_export'
post 'download_export'
get 'polling_last_export'
get 'stats'
get 'exports'
get 'email_notifications'