-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix #1016] display notifications for new messages
- Loading branch information
Showing
7 changed files
with
81 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,26 @@ | ||
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); | ||
} | ||
} | ||
}; | ||
|
||
document.addEventListener("turbolinks:load", TPS.scrollMessagerie); | ||
|
||
$('.date.highlighted').first() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, '[email protected]'].include?(commentaire.email) | ||
- if ![current_gestionnaire.email, commentaire.dossier.user.email, '[email protected]'].include?(commentaire.email) | ||
%span.guest Invité | ||
%span.date= I18n.l(commentaire.created_at.localtime, format: '%H:%M le %d/%m/%Y') | ||
%span.date{ class: updated_at_bg_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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe DossierHelper, type: :helper do | ||
describe ".updated_at_bg_class" do | ||
let(:seen_at) { DateTime.now } | ||
|
||
subject { updated_at_bg_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 |
22 changes: 22 additions & 0 deletions
22
spec/views/new_gestionnaire/shared/commentaires/commentaire.html.haml_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |