feat(instructeurs): notification badge when a new export has been generated
Co-Authored-By: Lisa Durand <lisa.c.durand@gmail.com>
This commit is contained in:
parent
99f5b39dbb
commit
a867c9a998
5 changed files with 69 additions and 0 deletions
|
@ -90,6 +90,8 @@ module Instructeurs
|
|||
@has_termine_notifications = notifications[:termines].present?
|
||||
@not_archived_notifications_dossier_ids = notifications[:en_cours] + notifications[:termines]
|
||||
|
||||
@has_export_notification = notify_exports?
|
||||
|
||||
@filtered_sorted_ids = procedure_presentation.filtered_sorted_ids(dossiers, statut, count: dossiers_count)
|
||||
|
||||
page = params[:page].presence || 1
|
||||
|
@ -225,6 +227,10 @@ module Instructeurs
|
|||
def exports
|
||||
@procedure = procedure
|
||||
@exports = Export.for_groupe_instructeurs(groupe_instructeur_ids).order(updated_at: :desc)
|
||||
cookies.encrypted[cookies_export_key] = {
|
||||
value: DateTime.current,
|
||||
expires: Export::MAX_DUREE_GENERATION + Export::MAX_DUREE_CONSERVATION_EXPORT
|
||||
}
|
||||
end
|
||||
|
||||
def email_usagers
|
||||
|
@ -353,5 +359,22 @@ module Instructeurs
|
|||
def bulk_message_params
|
||||
params.require(:bulk_message).permit(:body)
|
||||
end
|
||||
|
||||
def notify_exports?
|
||||
last_seen_at = begin
|
||||
DateTime.parse(cookies.encrypted[cookies_export_key])
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
|
||||
scope = Export.generated.for_groupe_instructeurs(groupe_instructeur_ids)
|
||||
scope = scope.where(updated_at: last_seen_at...) if last_seen_at
|
||||
|
||||
scope.exists?
|
||||
end
|
||||
|
||||
def cookies_export_key
|
||||
"exports_#{@procedure.id}_seen_at"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,3 +24,5 @@
|
|||
= link_to t('instructeurs.dossiers.header.banner.administrators_list'), administrateurs_instructeur_procedure_path(procedure), class: 'header-link'
|
||||
|
|
||||
= 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') }
|
||||
|
|
|
@ -13,6 +13,7 @@ en:
|
|||
notification_management: notification management
|
||||
administrators_list: administrators list
|
||||
exports_list: exports list
|
||||
exports_notification_label: A new export is ready to download
|
||||
statistics: statistics
|
||||
instructeurs: instructors
|
||||
contact_users: contact users (draft)
|
||||
|
|
|
@ -13,6 +13,7 @@ fr:
|
|||
notification_management: gestion des notifications
|
||||
administrators_list: voir les administrateurs
|
||||
exports_list: voir les exports
|
||||
exports_notification_label: Un nouvel export est prêt à être téléchargé
|
||||
statistics: statistiques
|
||||
instructeurs: instructeurs
|
||||
contact_users: contacter les usagers (brouillon)
|
||||
|
|
|
@ -466,6 +466,48 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
it { expect(assigns(:filtered_sorted_paginated_ids)).to match_array([archived_dossier].map(&:id)) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'exports notification' do
|
||||
context 'without generated export' do
|
||||
before do
|
||||
create(:export, :pending, groupe_instructeurs: [gi_2])
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(assigns(:has_export_notification)).to be(false) }
|
||||
end
|
||||
|
||||
context 'with generated export' do
|
||||
render_views
|
||||
before do
|
||||
create(:export, :generated, groupe_instructeurs: [gi_2], updated_at: 1.minute.ago)
|
||||
|
||||
if exports_seen_at
|
||||
cookies.encrypted["exports_#{procedure.id}_seen_at"] = exports_seen_at.to_datetime.to_s
|
||||
end
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
context 'without cookie' do
|
||||
let(:exports_seen_at) { nil }
|
||||
it { expect(assigns(:has_export_notification)).to be(true) }
|
||||
end
|
||||
|
||||
context 'with cookie in past' do
|
||||
let(:exports_seen_at) { 1.hour.ago }
|
||||
it { expect(assigns(:has_export_notification)).to be(true) }
|
||||
|
||||
it { expect(response.body).to match(/Un nouvel export est prêt/) }
|
||||
end
|
||||
|
||||
context 'with cookie set after last generated export' do
|
||||
let(:exports_seen_at) { 10.seconds.ago }
|
||||
it { expect(assigns(:has_export_notification)).to be(false) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue