Merge pull request #9855 from demarches-simplifiees/display-last-export-in-same-page-ldu

ETQ instructeur, j'ai besoin d'un accès très facile à mondernier export
This commit is contained in:
Lisa Durand 2023-12-20 10:02:08 +00:00 committed by GitHub
commit e52bd9d6bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 110 additions and 5 deletions

View file

@ -1,13 +1,13 @@
.fr-mb-5v
- if @batch.finished_at.present?
= render Dsfr::AlertComponent.new(title: t(".title.finish"), state: (@batch.errors? ? :warning : :success), heading_level: 'h2') do |c|
= render Dsfr::AlertComponent.new(title: t(".title.finish"), state: (@batch.errors? ? :warning : :success), heading_level: 'h2', extra_class_names: 'fr-my-2w') do |c|
- c.body do
%p
= t(".#{batch.operation}.finish.text_success", count: @batch.total_count, success_count: @batch.success_count)
- else
= render Dsfr::AlertComponent.new(title: t(".title.in_progress"), state: :info, heading_level: 'h2') do |c|
= render Dsfr::AlertComponent.new(title: t(".title.in_progress"), state: :info, heading_level: 'h2', extra_class_names: 'fr-my-2w') do |c|
- c.body do
%p= t(".#{batch.operation}.in_progress.text_success", count: @batch.total_count, success_count: @batch.success_count)

View file

@ -94,6 +94,7 @@ module Instructeurs
@not_archived_notifications_dossier_ids = notifications[:en_cours] + notifications[:termines]
@has_export_notification = notify_exports?
@last_export = last_export_for(statut)
@filtered_sorted_ids = procedure_presentation.filtered_sorted_ids(dossiers, statut, count: dossiers_count)
@ -181,6 +182,8 @@ module Instructeurs
@statut = export_options[:statut]
@dossiers_count = export.count
@last_export = last_export_for(@statut)
if export.available?
respond_to do |format|
format.turbo_stream do
@ -205,6 +208,16 @@ module Instructeurs
end
end
def polling_last_export
@statut = statut
@last_export = last_export_for(@statut)
if @last_export.available?
flash.notice = t('instructeurs.procedures.export_available_html', file_format: @last_export.format, file_url: @last_export.file.url)
else
flash.notice = t('instructeurs.procedures.export_pending_html', url: exports_instructeur_procedure_path(procedure))
end
end
def email_notifications
@procedure = procedure
@assign_to = assign_tos.first
@ -377,6 +390,10 @@ module Instructeurs
scope.exists?
end
def last_export_for(statut)
Export.where(instructeur_id: current_instructeur.id, statut: statut, updated_at: 1.hour.ago..).last
end
def cookies_export_key
"exports_#{@procedure.id}_seen_at"
end

View file

@ -26,3 +26,6 @@
= link_to t('instructeurs.dossiers.header.banner.exports_list'), exports_instructeur_procedure_path(procedure), class: 'header-link'
- if @has_export_notification
%span.notifications{ 'aria-label': t('instructeurs.dossiers.header.banner.exports_notification_label') }
#last-export-alert
= render partial: "last_export_alert", locals: { export: @last_export, statut: @statut }

View file

@ -0,0 +1,11 @@
- if export.present?
%div{ data: export.pending? ? { controller: "turbo-poll", turbo_poll_url_value: polling_last_export_instructeur_procedure_path(export_format: 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 export.pending?
= t('instructeurs.procedures.last_export_pending')
- if export.generated?
= t('instructeurs.procedures.last_export_available_html', file_format: export.format, file_url: export.file.url)
- if export.failed?
= t('instructeurs.procedures.last_export_failed', file_format: export.format)

View file

@ -6,3 +6,6 @@
- else
= turbo_stream.update_all '.dossiers-export' do
= 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
= render partial: "last_export_alert", locals: { export: @last_export, statut: @statut }

View file

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

View file

@ -1,8 +1,11 @@
en:
instructeurs:
procedures:
export_available_html: The export in %{file_format} format is ready. You can <a href="%{file_url}">download</a>
export_pending_html: We generate this export. You will be able to download it in a few minutes from <a href="%{url}">the exports list</a>.
export_available_html: The export in %{file_format} format is ready. You can <a href="%{file_url}">download it</a>
export_pending_html: We generate this export. You can see all your exports visiting <a href="%{url}">the exports list</a>.
last_export_available_html: Your last export in %{file_format} format is ready. You can <a href="%{file_url}">download it</a>
last_export_failed: Your last export in %{file_format} failed.
last_export_pending: Your last export is in process.
exports:
title: Exports list
export_description: |

View file

@ -2,7 +2,10 @@ fr:
instructeurs:
procedures:
export_available_html: Lexport au format %{file_format} est prêt. Vous pouvez le <a href="%{file_url}">télécharger</a>
export_pending_html: Nous générons cet export. Vous pourrez le télécharger dans quelques minutes depuis <a href="%{url}">la liste des exports</a>.
export_pending_html: Nous générons cet export. Vous pouvez retrouver tous vos exports sur <a href="%{url}">la liste des exports</a>.
last_export_available_html: Votre dernier export au format %{file_format} est prêt. Vous pouvez le <a href="%{file_url}">télécharger</a>
last_export_failed: Votre dernier export au format %{file_format} n'a pas fonctionné.
last_export_pending: Votre dernier export est en cours de création.
exports:
title: Liste des exports
export_description: |

View file

@ -452,6 +452,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'

View file

@ -508,6 +508,68 @@ describe Instructeurs::ProceduresController, type: :controller do
end
end
end
context 'exports alert' do
context 'without generated export' do
let(:statut) { 'tous' }
let!(:export) { create(:export, :pending, groupe_instructeurs: [gi_2]) }
render_views
before do
subject
end
it { expect(assigns(:last_export)).to eq(export) }
it { expect(response.body).to include("Votre dernier export est en cours de création") }
end
context 'with recent generated export' do
let(:statut) { 'tous' }
let!(:export) { create(:export, :generated, groupe_instructeurs: [gi_2], updated_at: 1.minute.ago) }
render_views
before do
subject
end
it { expect(assigns(:last_export)).to eq(export) }
it { expect(response.body).to include("Votre dernier export au format csv est prêt") }
end
context 'with failed export ' do
let(:statut) { 'tous' }
let!(:export) { create(:export, :failed, groupe_instructeurs: [gi_2], updated_at: 1.minute.ago) }
render_views
before do
subject
end
it { expect(assigns(:last_export)).to eq(export) }
it { expect(response.body).to include("Votre dernier export au format csv n&#39;a pas fonctionné") }
end
context 'with export more than hour ago' do
let(:statut) { 'tous' }
let!(:export) { create(:export, :generated, groupe_instructeurs: [gi_2], updated_at: 2.hours.ago) }
before do
subject
end
it { expect(assigns(:last_export)).to eq(nil) }
end
context 'logged in with another instructeur' do
let(:instructeur_2) { create(:instructeur) }
let(:statut) { 'tous' }
let!(:export) { create(:export, :generated, groupe_instructeurs: [gi_2], updated_at: 1.minute.ago) }
before do
sign_in(instructeur_2.user)
instructeur_2.groupe_instructeurs << gi_2
subject
end
it { expect(assigns(:last_export)).to eq(nil) }
end
end
end
end