Merge pull request #284 from sgmap/rename_and_refactor_dossier_with_notification_for
[Fix #276] Rename and refactor dossier_with_notification_for
This commit is contained in:
commit
c65b1e232a
4 changed files with 24 additions and 15 deletions
|
@ -30,7 +30,7 @@ class DossiersListFacades
|
||||||
end
|
end
|
||||||
|
|
||||||
def gestionnaire_procedures_name_and_id_list
|
def gestionnaire_procedures_name_and_id_list
|
||||||
@current_devise_profil.procedures.order('libelle ASC').inject([]) { |acc, procedure| acc.push({id: procedure.id, libelle: procedure.libelle, unread_notifications: @current_devise_profil.dossier_with_notification_for(procedure)}) }
|
@current_devise_profil.procedures.order('libelle ASC').inject([]) { |acc, procedure| acc.push({id: procedure.id, libelle: procedure.libelle, unread_notifications: @current_devise_profil.dossiers_with_notifications_count_for_procedure(procedure)}) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def unread_notifications
|
def unread_notifications
|
||||||
|
|
|
@ -86,16 +86,9 @@ class Gestionnaire < ActiveRecord::Base
|
||||||
0
|
0
|
||||||
end
|
end
|
||||||
|
|
||||||
def dossier_with_notification_for procedure
|
def dossiers_with_notifications_count_for_procedure(procedure)
|
||||||
procedure_ids = dossiers_follow.pluck(:procedure_id)
|
followed_dossiers_id = dossiers_follow.where(procedure: procedure).pluck(:id)
|
||||||
|
Notification.unread.where(dossier_id: followed_dossiers_id).select(:dossier_id).distinct(:dossier_id).count
|
||||||
if procedure_ids.include?(procedure.id)
|
|
||||||
return dossiers_follow.where(procedure_id: procedure.id)
|
|
||||||
.inject(0) do |acc, dossier|
|
|
||||||
acc += ((dossier.notifications.where(already_read: false).count) > 0 ? 1 : 0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def dossiers_with_notifications_count
|
def dossiers_with_notifications_count
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
- if total_new > 0
|
- if total_new > 0
|
||||||
.badge.progress-bar-success{ title: 'Nouveaux dossiers' }
|
.badge.progress-bar-success{ title: 'Nouveaux dossiers' }
|
||||||
= total_new
|
= total_new
|
||||||
- unread_notif_count = current_gestionnaire.dossier_with_notification_for(procedure)
|
- unread_notif_count = current_gestionnaire.dossiers_with_notifications_count_for_procedure(procedure)
|
||||||
- if unread_notif_count > 0
|
- if unread_notif_count > 0
|
||||||
.badge.progress-bar-warning{ title: 'Notifications' }
|
.badge.progress-bar-warning{ title: 'Notifications' }
|
||||||
= unread_notif_count
|
= unread_notif_count
|
||||||
|
|
|
@ -313,8 +313,8 @@ describe Gestionnaire, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#dossier_with_notification_for' do
|
describe '#dossiers_with_notifications_count_for_procedure' do
|
||||||
subject { gestionnaire.dossier_with_notification_for(procedure) }
|
subject { gestionnaire.dossiers_with_notifications_count_for_procedure(procedure) }
|
||||||
|
|
||||||
context 'without notifications' do
|
context 'without notifications' do
|
||||||
it { is_expected.to eq(0) }
|
it { is_expected.to eq(0) }
|
||||||
|
@ -336,12 +336,28 @@ describe Gestionnaire, type: :model do
|
||||||
it { is_expected.to eq(0) }
|
it { is_expected.to eq(0) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with 2 notification' do
|
context 'with 2 notifications' do
|
||||||
let!(:notification){ create(:notification, already_read: false, dossier: dossier) }
|
let!(:notification){ create(:notification, already_read: false, dossier: dossier) }
|
||||||
let!(:notification2){ create(:notification, already_read: false, dossier: dossier) }
|
let!(:notification2){ create(:notification, already_read: false, dossier: dossier) }
|
||||||
|
|
||||||
it { is_expected.to eq(1) }
|
it { is_expected.to eq(1) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with another dossier' do
|
||||||
|
let!(:dossier2){create(:dossier, procedure: procedure, state: 'received')}
|
||||||
|
let!(:follow2){ create(:follow, dossier: dossier2, gestionnaire: gestionnaire) }
|
||||||
|
|
||||||
|
context 'and some notifications' do
|
||||||
|
let!(:notification){ create(:notification, already_read: false, dossier: dossier) }
|
||||||
|
let!(:notification2){ create(:notification, already_read: false, dossier: dossier) }
|
||||||
|
let!(:notification3){ create(:notification, already_read: false, dossier: dossier) }
|
||||||
|
|
||||||
|
let!(:notification4){ create(:notification, already_read: false, dossier: dossier2) }
|
||||||
|
let!(:notification5){ create(:notification, already_read: false, dossier: dossier2) }
|
||||||
|
|
||||||
|
it { is_expected.to eq(2) }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue