[Fix #1016] display notifications for new messages
This commit is contained in:
parent
5474ff8bb4
commit
8e67e5c057
7 changed files with 79 additions and 7 deletions
|
@ -1,7 +1,23 @@
|
|||
TPS.scrollMessagerie = function () {
|
||||
var scrollTo = function ($container, $scrollTo) {
|
||||
$container.scrollTop(
|
||||
$scrollTo.offset().top - $container.offset().top + $container.scrollTop()
|
||||
);
|
||||
}
|
||||
|
||||
var scrollToBottom = function ($container) {
|
||||
$container.scrollTop($container.prop('scrollHeight'));
|
||||
}
|
||||
|
||||
var $ul = $(".messagerie ul").first();
|
||||
if($ul.length) {
|
||||
$ul.scrollTop($ul.prop('scrollHeight'));
|
||||
var $elementToScroll = $('.date.highlighted').first();
|
||||
|
||||
if ($elementToScroll.length != 0) {
|
||||
scrollTo($ul, $elementToScroll);
|
||||
} else {
|
||||
scrollToBottom($ul);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ module NewGestionnaire
|
|||
include ActionView::Helpers::TextHelper
|
||||
|
||||
after_action :mark_demande_as_read, only: :show
|
||||
after_action :mark_messagerie_as_read, only: [:messagerie, :create_commentaire]
|
||||
|
||||
def attestation
|
||||
send_data(dossier.attestation.pdf.read, filename: 'attestation.pdf', type: 'application/pdf')
|
||||
|
@ -14,9 +15,8 @@ module NewGestionnaire
|
|||
end
|
||||
|
||||
def messagerie
|
||||
dossier.notifications.messagerie.mark_as_read
|
||||
current_gestionnaire.mark_tab_as_seen(dossier, :messagerie)
|
||||
@commentaire = Commentaire.new
|
||||
@messagerie_seen_at = current_gestionnaire.follows.find_by(dossier: dossier)&.messagerie_seen_at
|
||||
end
|
||||
|
||||
def annotations_privees
|
||||
|
@ -198,5 +198,10 @@ module NewGestionnaire
|
|||
dossier.notifications.demande.mark_as_read
|
||||
current_gestionnaire.mark_tab_as_seen(dossier, :demande)
|
||||
end
|
||||
|
||||
def mark_messagerie_as_read
|
||||
dossier.notifications.messagerie.mark_as_read
|
||||
current_gestionnaire.mark_tab_as_seen(dossier, :messagerie)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
%ul.messages-list
|
||||
- @dossier.commentaires.each do |commentaire|
|
||||
%li
|
||||
= render partial: "new_gestionnaire/shared/commentaires/commentaire", locals: { commentaire: commentaire }
|
||||
= render partial: "new_gestionnaire/shared/commentaires/commentaire", locals: { commentaire: commentaire, messagerie_seen_at: nil }
|
||||
|
||||
= render partial: "new_gestionnaire/shared/commentaires/form", locals: { commentaire: @commentaire, form_url: commentaire_avis_path(@avis) }
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
%ul.messages-list
|
||||
- @dossier.commentaires.each do |commentaire|
|
||||
%li
|
||||
= render partial: "new_gestionnaire/shared/commentaires/commentaire", locals: { commentaire: commentaire }
|
||||
= render partial: "new_gestionnaire/shared/commentaires/commentaire", locals: { commentaire: commentaire, messagerie_seen_at: @messagerie_seen_at }
|
||||
|
||||
= render partial: "new_gestionnaire/shared/commentaires/form", locals: { commentaire: @commentaire, form_url: commentaire_dossier_path(@dossier.procedure, @dossier) }
|
||||
|
|
|
@ -4,9 +4,10 @@
|
|||
%h2
|
||||
%span.mail
|
||||
= render partial: 'new_gestionnaire/shared/commentaires/commentaire_issuer', locals: { commentaire: commentaire, current_gestionnaire: current_gestionnaire }
|
||||
- if ![current_gestionnaire.email, @dossier.user.email, 'contact@tps.apientreprise.fr'].include?(commentaire.email)
|
||||
- if ![current_gestionnaire.email, commentaire.dossier.user.email, 'contact@tps.apientreprise.fr'].include?(commentaire.email)
|
||||
%span.guest Invité
|
||||
%span.date= I18n.l(commentaire.created_at.localtime, format: '%H:%M le %d/%m/%Y')
|
||||
%span.date{ class: highlight_if_unseen_class(messagerie_seen_at, commentaire.created_at) }
|
||||
= I18n.l(commentaire.created_at.localtime, format: '%d/%m/%Y à %H:%M ')
|
||||
.rich-text= sanitize(commentaire.body)
|
||||
|
||||
- if commentaire.piece_justificative
|
||||
|
|
28
spec/helpers/dossier_helper_spec.rb
Normal file
28
spec/helpers/dossier_helper_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DossierHelper, type: :helper do
|
||||
describe ".highlight_if_unseen_class" do
|
||||
let(:seen_at) { DateTime.now }
|
||||
|
||||
subject { highlight_if_unseen_class(seen_at, updated_at) }
|
||||
|
||||
context "when commentaire date is created before last seen datetime" do
|
||||
let(:updated_at) { seen_at - 2.days }
|
||||
|
||||
it { is_expected.to eq nil }
|
||||
end
|
||||
|
||||
context "when commentaire date is created after last seen datetime" do
|
||||
let(:updated_at) { seen_at + 2.hours }
|
||||
|
||||
it { is_expected.to eq "highlighted" }
|
||||
end
|
||||
|
||||
context "when there is no last seen datetime" do
|
||||
let(:updated_at) { DateTime.now }
|
||||
let(:seen_at) { nil }
|
||||
|
||||
it { is_expected.to eq nil }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,22 @@
|
|||
describe 'new_gestionnaire/shared/commentaires/commentaire.html.haml', type: :view do
|
||||
before { view.extend DossierHelper }
|
||||
|
||||
subject { render 'new_gestionnaire/shared/commentaires/commentaire.html.haml', commentaire: commentaire, messagerie_seen_at: seen_at, current_gestionnaire: current_gestionnaire }
|
||||
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:commentaire) { create(:commentaire, dossier: dossier) }
|
||||
let(:current_gestionnaire) { create(:gestionnaire) }
|
||||
let(:seen_at) { commentaire.created_at + 1.hour }
|
||||
|
||||
context "with a seen_at after commentaire created_at" do
|
||||
let(:seen_at) { commentaire.created_at + 1.hour }
|
||||
|
||||
it { is_expected.not_to have_css(".highlighted") }
|
||||
end
|
||||
|
||||
context "with a seen_at after commentaire created_at" do
|
||||
let(:seen_at) { commentaire.created_at - 1.hour }
|
||||
|
||||
it { is_expected.to have_css(".highlighted") }
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue