Skip to content

Commit

Permalink
[Fix #1016] display notifications for avis
Browse files Browse the repository at this point in the history
  • Loading branch information
mmagn committed Dec 7, 2017
1 parent 516268a commit 430a3a8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
9 changes: 7 additions & 2 deletions app/controllers/new_gestionnaire/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class DossiersController < ProceduresController

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')
Expand All @@ -25,8 +26,7 @@ def annotations_privees
end

def avis
dossier.notifications.avis.mark_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :avis)
@follow = current_gestionnaire.follows.find_by(dossier: dossier)
end

def personnes_impliquees
Expand Down Expand Up @@ -203,5 +203,10 @@ def mark_messagerie_as_read
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
6 changes: 4 additions & 2 deletions app/views/new_gestionnaire/avis/_avis_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
%span.confidentiel
confidentiel
.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: updated_at_bg_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
Expand All @@ -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: updated_at_bg_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
2 changes: 1 addition & 1 deletion app/views/new_gestionnaire/avis/instruction.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
2 changes: 1 addition & 1 deletion app/views/new_gestionnaire/dossiers/avis.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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: @follow&.avis_seen_at }
20 changes: 20 additions & 0 deletions spec/views/new_gestionnaire/avis/avis_list.html.haml_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 430a3a8

Please sign in to comment.