Notification: new acknowledgment system
This commit is contained in:
parent
f7d7cec5ae
commit
ed4e885e6f
3 changed files with 29 additions and 0 deletions
|
@ -7,21 +7,25 @@ module NewGestionnaire
|
||||||
def show
|
def show
|
||||||
@dossier = dossier
|
@dossier = dossier
|
||||||
dossier.notifications.demande.mark_as_read
|
dossier.notifications.demande.mark_as_read
|
||||||
|
current_gestionnaire.mark_tab_as_seen(dossier, :demande)
|
||||||
end
|
end
|
||||||
|
|
||||||
def messagerie
|
def messagerie
|
||||||
@dossier = dossier
|
@dossier = dossier
|
||||||
dossier.notifications.messagerie.mark_as_read
|
dossier.notifications.messagerie.mark_as_read
|
||||||
|
current_gestionnaire.mark_tab_as_seen(dossier, :messagerie)
|
||||||
end
|
end
|
||||||
|
|
||||||
def annotations_privees
|
def annotations_privees
|
||||||
@dossier = dossier
|
@dossier = dossier
|
||||||
dossier.notifications.annotations_privees.mark_as_read
|
dossier.notifications.annotations_privees.mark_as_read
|
||||||
|
current_gestionnaire.mark_tab_as_seen(dossier, :annotations_privees)
|
||||||
end
|
end
|
||||||
|
|
||||||
def avis
|
def avis
|
||||||
@dossier = dossier
|
@dossier = dossier
|
||||||
dossier.notifications.avis.mark_as_read
|
dossier.notifications.avis.mark_as_read
|
||||||
|
current_gestionnaire.mark_tab_as_seen(dossier, :avis)
|
||||||
end
|
end
|
||||||
|
|
||||||
def follow
|
def follow
|
||||||
|
|
|
@ -175,6 +175,12 @@ class Gestionnaire < ActiveRecord::Base
|
||||||
Dossier.where(id: dossiers_id_with_notifications(dossiers)).group(:procedure_id).count
|
Dossier.where(id: dossiers_id_with_notifications(dossiers)).group(:procedure_id).count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mark_tab_as_seen(dossier, tab)
|
||||||
|
attributes = {}
|
||||||
|
attributes["#{tab}_seen_at"] = DateTime.now
|
||||||
|
Follow.where(gestionnaire: self, dossier: dossier).update_all(attributes)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def valid_couple_table_attr? table, column
|
def valid_couple_table_attr? table, column
|
||||||
|
|
|
@ -550,4 +550,23 @@ describe Gestionnaire, type: :model do
|
||||||
it { is_expected.to match({ procedure.id => 1 }) }
|
it { is_expected.to match({ procedure.id => 1 }) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#mark_tab_as_seen' do
|
||||||
|
let!(:dossier) { create(:dossier, :followed, state: 'initiated') }
|
||||||
|
let(:gestionnaire) { dossier.follows.first.gestionnaire }
|
||||||
|
let(:freeze_date) { DateTime.parse('12/12/2012') }
|
||||||
|
|
||||||
|
context 'when demande is acknowledged' do
|
||||||
|
let(:follow) { gestionnaire.follows.find_by(dossier: dossier) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
Timecop.freeze(freeze_date)
|
||||||
|
gestionnaire.mark_tab_as_seen(dossier, :demande)
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(follow.demande_seen_at).to eq(freeze_date) }
|
||||||
|
|
||||||
|
after { Timecop.return }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue