Procedure Index: add notification icon

This commit is contained in:
Simon Lehericey 2017-08-30 11:12:58 +02:00 committed by Mathieu Magnin
parent ff3120bf6c
commit 3e93d21bf5
6 changed files with 53 additions and 0 deletions

View file

@ -0,0 +1,9 @@
@import "colors";
span.notifications {
position: absolute;
width: 8px;
height: 8px;
border-radius: 4px;
background-color: $orange;
}

View file

@ -40,6 +40,7 @@
min-height: 36px;
border-left: 1px solid $border-grey;
width: 90px;
position: relative;
&:last-child {
border-right: 1px solid $border-grey;
@ -60,5 +61,10 @@
color: $grey;
}
}
.notifications {
top: 3px;
right: 18px;
}
}
}

View file

@ -18,6 +18,8 @@ module NewGestionnaire
.group(:procedure_id)
.reorder(nil)
.count
@notifications_count_per_procedure = current_gestionnaire.notifications_count_per_procedure
end
def show

View file

@ -93,6 +93,14 @@ class Gestionnaire < ActiveRecord::Base
Notification.unread.where(dossier_id: followed_dossiers_id).select(:dossier_id).distinct(:dossier_id).count
end
def notifications_count_per_procedure
followed_dossiers
.joins(:notifications)
.where(notifications: { already_read: false })
.group('procedure_id')
.count
end
def dossiers_with_notifications_count
notifications.pluck(:dossier_id).uniq.count
end

View file

@ -19,6 +19,8 @@
.stats-legend
à suivre
%li
- if @notifications_count_per_procedure[p.id].present?
%span.notifications{ 'aria-label': "notifications" }
- followed_count = @followed_dossiers_count_per_procedure[p.id] || 0
.stats-number
= followed_count

View file

@ -356,4 +356,30 @@ describe Gestionnaire, type: :model do
it { expect(subject).to be false }
end
end
describe '#notifications_count_per_procedure' do
subject { gestionnaire.notifications_count_per_procedure }
let(:dossier_with_unread_notification) do
create(:dossier, notifications: [Notification.create(type_notif: 'champs', already_read: false)])
end
let(:dossier_with_no_unread_notification) do
create(:dossier, notifications: [Notification.create(type_notif: 'champs', already_read: true)])
end
before { gestionnaire.followed_dossiers << followed_dossier }
context 'when a followed dossier has unread notification' do
let(:followed_dossier) { dossier_with_unread_notification }
it { is_expected.to eq({ dossier_with_unread_notification.procedure.id => 1 }) }
end
context 'when a followed dossier has unread notification' do
let(:followed_dossier) { dossier_with_no_unread_notification }
it { is_expected.to eq({ }) }
end
end
end