From c3e7e39947782f5c609dc53b447b853ae0b45c77 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 7 Dec 2017 11:15:51 +0100 Subject: [PATCH] [Fix #1016] display notifications for avis --- .../new_gestionnaire/dossiers_controller.rb | 9 +++++++-- .../avis/_avis_list.html.haml | 6 ++++-- .../avis/instruction.html.haml | 2 +- .../new_gestionnaire/dossiers/avis.html.haml | 2 +- .../avis/avis_list.html.haml_spec.rb | 20 +++++++++++++++++++ 5 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 spec/views/new_gestionnaire/avis/avis_list.html.haml_spec.rb diff --git a/app/controllers/new_gestionnaire/dossiers_controller.rb b/app/controllers/new_gestionnaire/dossiers_controller.rb index 0e786d04c..7f350007f 100644 --- a/app/controllers/new_gestionnaire/dossiers_controller.rb +++ b/app/controllers/new_gestionnaire/dossiers_controller.rb @@ -5,6 +5,7 @@ module NewGestionnaire after_action :mark_demande_as_read, only: :show after_action :mark_messagerie_as_read, only: [:messagerie, :create_commentaire] + after_action :mark_avis_as_read, only: [:avis, :create_avis] def attestation send_data(dossier.attestation.pdf.read, filename: 'attestation.pdf', type: 'application/pdf') @@ -25,8 +26,7 @@ module NewGestionnaire end def avis - dossier.notifications.avis.mark_as_read - current_gestionnaire.mark_tab_as_seen(dossier, :avis) + @avis_seen_at = current_gestionnaire.follows.find_by(dossier: dossier)&.avis_seen_at end def personnes_impliquees @@ -203,5 +203,10 @@ module NewGestionnaire dossier.notifications.messagerie.mark_as_read current_gestionnaire.mark_tab_as_seen(dossier, :messagerie) end + + def mark_avis_as_read + dossier.notifications.avis.mark_as_read + current_gestionnaire.mark_tab_as_seen(dossier, :avis) + end end end diff --git a/app/views/new_gestionnaire/avis/_avis_list.html.haml b/app/views/new_gestionnaire/avis/_avis_list.html.haml index 5520cb025..8828f315e 100644 --- a/app/views/new_gestionnaire/avis/_avis_list.html.haml +++ b/app/views/new_gestionnaire/avis/_avis_list.html.haml @@ -15,7 +15,8 @@ %span.confidentiel confidentiel %span.icon.lock{ title: "Cet avis n'est pas affiché avec les autres experts consultés" } - %span.date Demande d'avis envoyée le #{I18n.l(avis.created_at.localtime, format: '%d/%m/%y')} + %span.date{ class: highlight_if_unseen_class(avis_seen_at, avis.created_at) } + Demande d'avis envoyée le #{I18n.l(avis.created_at.localtime, format: '%d/%m/%y à %H:%M')} %p= avis.introduction .answer.flex.align-start @@ -24,7 +25,8 @@ %h2.gestionnaire = (avis.email_to_display == current_gestionnaire.email) ? 'Vous' : avis.email_to_display - if avis.answer.present? - %span.date Réponse donnée le #{I18n.l(avis.updated_at.localtime, format: '%d/%m/%y')} + %span.date{ class: highlight_if_unseen_class(avis_seen_at, avis.updated_at) } + Réponse donnée le #{I18n.l(avis.updated_at.localtime, format: '%d/%m/%y à %H:%M')} - else %span.waiting En attente de réponse %p= avis.answer diff --git a/app/views/new_gestionnaire/avis/instruction.html.haml b/app/views/new_gestionnaire/avis/instruction.html.haml index bd59d91b2..1dc5860d4 100644 --- a/app/views/new_gestionnaire/avis/instruction.html.haml +++ b/app/views/new_gestionnaire/avis/instruction.html.haml @@ -42,4 +42,4 @@ .send-wrapper = f.submit 'Demander un avis', class: 'button send' - = render partial: 'avis_list', locals: { avis: @dossier.avis_for(current_gestionnaire) } + = render partial: 'avis_list', locals: { avis: @dossier.avis_for(current_gestionnaire), avis_seen_at: nil } diff --git a/app/views/new_gestionnaire/dossiers/avis.html.haml b/app/views/new_gestionnaire/dossiers/avis.html.haml index 35e446a19..0e9664df0 100644 --- a/app/views/new_gestionnaire/dossiers/avis.html.haml +++ b/app/views/new_gestionnaire/dossiers/avis.html.haml @@ -17,4 +17,4 @@ .send-wrapper = f.submit 'Demander un avis', class: 'button send', data: { disable_with: "Envoi..." } - = render partial: 'new_gestionnaire/avis/avis_list', locals: { avis: @dossier.avis } + = render partial: 'new_gestionnaire/avis/avis_list', locals: { avis: @dossier.avis, avis_seen_at: @avis_seen_at } diff --git a/spec/views/new_gestionnaire/avis/avis_list.html.haml_spec.rb b/spec/views/new_gestionnaire/avis/avis_list.html.haml_spec.rb new file mode 100644 index 000000000..0a197e1a7 --- /dev/null +++ b/spec/views/new_gestionnaire/avis/avis_list.html.haml_spec.rb @@ -0,0 +1,20 @@ +describe 'new_gestionnaire/avis/avis_list.html.haml', type: :view do + before { view.extend DossierHelper } + + subject { render 'new_gestionnaire/avis/avis_list.html.haml', avis: avis, avis_seen_at: seen_at, current_gestionnaire: gestionnaire } + + let(:gestionnaire) { create(:gestionnaire) } + let(:avis) { [create(:avis, claimant: gestionnaire)] } + + context "with a seen_at after avis created_at" do + let(:seen_at) { avis.first.created_at + 1.hour } + + it { is_expected.not_to have_css(".highlighted") } + end + + context "with a seen_at after avis created_at" do + let(:seen_at) { avis.first.created_at - 1.hour } + + it { is_expected.to have_css(".highlighted") } + end +end