Add notifications into procedure list on back office report
This commit is contained in:
parent
02ce392ff3
commit
153c472ef6
5 changed files with 55 additions and 2 deletions
|
@ -27,7 +27,7 @@ class DossiersListFacades
|
|||
end
|
||||
|
||||
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}) }
|
||||
@current_devise_profil.procedures.order('libelle ASC').inject([]) { |acc, procedure| acc.push({id: procedure.id, libelle: procedure.libelle, notification_unread: @current_devise_profil.notification_unread(procedure)}) }
|
||||
end
|
||||
|
||||
def procedure_id
|
||||
|
|
|
@ -63,6 +63,18 @@ class Gestionnaire < ActiveRecord::Base
|
|||
PreferenceSmartListingPage.create(page: 1, procedure: nil, gestionnaire: self, liste: 'a_traiter')
|
||||
end
|
||||
|
||||
def notification_unread procedure
|
||||
procedure_ids = dossiers_follow.pluck(:procedure_id)
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
0
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def valid_couple_table_attr? table, column
|
||||
|
|
|
@ -17,3 +17,6 @@
|
|||
= link_to backoffice_dossiers_procedure_path(procedure[:id]), {title: procedure[:libelle]} do
|
||||
%div.procedure_list_element{ class: ('active' if procedure[:id] == @facade_data_view.procedure.id rescue '') }
|
||||
= truncate(procedure[:libelle], length: 50)
|
||||
-if procedure[:notification_unread] > 0
|
||||
.badge.progress-bar-warning
|
||||
= procedure[:notification_unread]
|
||||
|
|
|
@ -50,10 +50,12 @@ describe DossiersListFacades do
|
|||
|
||||
it { expect(subject.first[:id]).to eq procedure.id }
|
||||
it { expect(subject.first[:libelle]).to eq procedure.libelle }
|
||||
it { expect(subject.first[:notification_unread]).to eq 0 }
|
||||
|
||||
|
||||
it { expect(subject.last[:id]).to eq procedure_2.id }
|
||||
it { expect(subject.last[:libelle]).to eq procedure_2.libelle }
|
||||
|
||||
it { expect(subject.last[:notification_unread]).to eq 0 }
|
||||
end
|
||||
|
||||
describe '#active_filter?' do
|
||||
|
|
|
@ -208,4 +208,40 @@ describe Gestionnaire, type: :model do
|
|||
expect(admin.valid_password?('super secret')).to be(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#notification_unread' do
|
||||
subject { gestionnaire.notification_unread procedure }
|
||||
|
||||
context 'when gestionnaire follow any dossier' do
|
||||
it { is_expected.to eq 0 }
|
||||
it { expect(gestionnaire.follows.count).to eq 0 }
|
||||
it { expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).not_to receive(:inject)
|
||||
subject }
|
||||
end
|
||||
|
||||
context 'when gestionnaire follow any dossier into the procedure past in params' do
|
||||
before do
|
||||
create :follow, gestionnaire: gestionnaire, dossier: create(:dossier, procedure: procedure_2)
|
||||
end
|
||||
|
||||
it { is_expected.to eq 0 }
|
||||
it { expect(gestionnaire.follows.count).to eq 1 }
|
||||
it { expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).not_to receive(:inject)
|
||||
subject }
|
||||
end
|
||||
|
||||
context 'when gestionnaire follow a dossier with a notification into the procedure past in params' do
|
||||
let(:dossier) { create(:dossier, procedure: procedure, state: 'initiated') }
|
||||
|
||||
before do
|
||||
create :follow, gestionnaire: gestionnaire, dossier: dossier
|
||||
create :notification, dossier: dossier
|
||||
end
|
||||
|
||||
it { is_expected.to eq 1 }
|
||||
it { expect(gestionnaire.follows.count).to eq 1 }
|
||||
it { expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).to receive(:inject)
|
||||
subject }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue