Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ETQ instructeur, j'ai besoin d'un accès très facile à mondernier export #9855

Merged
merged 6 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
11 changes: 11 additions & 0 deletions app/controllers/instructeurs/procedures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def show
@not_archived_notifications_dossier_ids = notifications[:en_cours] + notifications[:termines]

@has_export_notification = notify_exports?
@has_last_export = last_export_for(@statut)

@filtered_sorted_ids = procedure_presentation.filtered_sorted_ids(dossiers, statut, count: dossiers_count)

Expand Down Expand Up @@ -181,6 +182,8 @@ def download_export
@statut = export_options[:statut]
@dossiers_count = export.count

@has_last_export = last_export_for(@statut)

if export.available?
respond_to do |format|
format.turbo_stream do
Expand Down Expand Up @@ -377,6 +380,14 @@ def notify_exports?
scope.exists?
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
Copy link
Member

@colinux colinux Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

petite simplification :

Suggested change
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
"exports_#{@procedure.id}_seen_at"
end
Expand Down
13 changes: 13 additions & 0 deletions app/views/instructeurs/procedures/_header.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,16 @@
= 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
- 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)
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,16 @@
- 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
- 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)
7 changes: 5 additions & 2 deletions config/locales/views/instructeurs/procedures/exports/en.yml
Original file line number Diff line number Diff line change
@@ -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: |
Expand Down
5 changes: 4 additions & 1 deletion config/locales/views/instructeurs/procedures/exports/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ fr:
instructeurs:
procedures:
export_available_html: L’export 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: |
Expand Down
62 changes: 62 additions & 0 deletions spec/controllers/instructeurs/procedures_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,68 @@
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(:has_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(:has_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(:has_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(:has_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(:has_last_export)).to eq(nil) }
end
end
end
end

Expand Down