Dossier: add notification icon
This commit is contained in:
parent
fbd16b8c75
commit
a298c48e8f
5 changed files with 64 additions and 4 deletions
|
@ -6,14 +6,17 @@ module NewGestionnaire
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@dossier = dossier
|
@dossier = dossier
|
||||||
|
dossier.notifications.demande.mark_as_read
|
||||||
end
|
end
|
||||||
|
|
||||||
def messagerie
|
def messagerie
|
||||||
@dossier = dossier
|
@dossier = dossier
|
||||||
|
dossier.notifications.messagerie.mark_as_read
|
||||||
end
|
end
|
||||||
|
|
||||||
def instruction
|
def instruction
|
||||||
@dossier = dossier
|
@dossier = dossier
|
||||||
|
dossier.notifications.instruction.mark_as_read
|
||||||
end
|
end
|
||||||
|
|
||||||
def follow
|
def follow
|
||||||
|
|
|
@ -104,6 +104,16 @@ class Dossier < ActiveRecord::Base
|
||||||
pieces_justificatives.where(type_de_piece_justificative_id: type_id).count > 0
|
pieces_justificatives.where(type_de_piece_justificative_id: type_id).count > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def notifications_summary
|
||||||
|
unread_notifications = notifications.unread
|
||||||
|
|
||||||
|
{
|
||||||
|
demande: unread_notifications.select(&:demande?).present?,
|
||||||
|
instruction: unread_notifications.select(&:instruction?).present?,
|
||||||
|
messagerie: unread_notifications.select(&:messagerie?).present?
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def retrieve_last_piece_justificative_by_type(type)
|
def retrieve_last_piece_justificative_by_type(type)
|
||||||
pieces_justificatives.where(type_de_piece_justificative_id: type).last
|
pieces_justificatives.where(type_de_piece_justificative_id: type).last
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,27 @@ class Notification < ActiveRecord::Base
|
||||||
avis: 'avis'
|
avis: 'avis'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEMANDE = %w(cerfa piece_justificative champs submitted)
|
||||||
|
INSTRUCTION = %w(avis)
|
||||||
|
MESSAGERIE = %w(commentaire)
|
||||||
|
|
||||||
belongs_to :dossier
|
belongs_to :dossier
|
||||||
|
|
||||||
scope :unread, -> { where(already_read: false) }
|
scope :unread, -> { where(already_read: false) }
|
||||||
|
scope :demande, -> { where(type_notif: DEMANDE) }
|
||||||
|
scope :instruction, -> { where(type_notif: INSTRUCTION) }
|
||||||
|
scope :messagerie, -> { where(type_notif: MESSAGERIE) }
|
||||||
|
scope :mark_as_read, -> { update_all(already_read: true) }
|
||||||
|
|
||||||
|
def demande?
|
||||||
|
Notification::DEMANDE.include?(type_notif)
|
||||||
|
end
|
||||||
|
|
||||||
|
def instruction?
|
||||||
|
Notification::INSTRUCTION.include?(type_notif)
|
||||||
|
end
|
||||||
|
|
||||||
|
def messagerie?
|
||||||
|
Notification::MESSAGERIE.include?(type_notif)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,11 +6,18 @@
|
||||||
%li
|
%li
|
||||||
= "Dossier n° #{dossier.id}"
|
= "Dossier n° #{dossier.id}"
|
||||||
%ul.tabs
|
%ul.tabs
|
||||||
|
- notifications_summary = dossier.notifications_summary
|
||||||
%li{ class: current_page?(dossier_path(dossier.procedure, dossier)) ? 'active' : nil }
|
%li{ class: current_page?(dossier_path(dossier.procedure, dossier)) ? 'active' : nil }
|
||||||
|
- if notifications_summary[:demande]
|
||||||
|
%span.notifications{ 'aria-label': 'notifications' }
|
||||||
= link_to "Demande", dossier_path(dossier.procedure, dossier)
|
= link_to "Demande", dossier_path(dossier.procedure, dossier)
|
||||||
%li{ class: current_page?(instruction_dossier_path(dossier.procedure, dossier)) ? 'active' : nil }
|
%li{ class: current_page?(instruction_dossier_path(dossier.procedure, dossier)) ? 'active' : nil }
|
||||||
|
- if notifications_summary[:instruction]
|
||||||
|
%span.notifications{ 'aria-label': 'notifications' }
|
||||||
= link_to "Instruction", instruction_dossier_path(dossier.procedure, dossier)
|
= link_to "Instruction", instruction_dossier_path(dossier.procedure, dossier)
|
||||||
%li{ class: current_page?(messagerie_dossier_path(dossier.procedure, dossier)) ? 'active' : nil }
|
%li{ class: current_page?(messagerie_dossier_path(dossier.procedure, dossier)) ? 'active' : nil }
|
||||||
|
- if notifications_summary[:messagerie]
|
||||||
|
%span.notifications{ 'aria-label': 'notifications' }
|
||||||
= link_to "Messagerie", messagerie_dossier_path(dossier.procedure, dossier)
|
= link_to "Messagerie", messagerie_dossier_path(dossier.procedure, dossier)
|
||||||
%li
|
%li
|
||||||
= link_to "Historique", "#"
|
= link_to "Historique", "#"
|
||||||
|
|
|
@ -72,12 +72,32 @@ describe NewGestionnaire::DossiersController, type: :controller do
|
||||||
it { expect(response).to redirect_to(procedures_url) }
|
it { expect(response).to redirect_to(procedures_url) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#show" do
|
describe '#show #messagerie #instruction' do
|
||||||
before { get :show, params: { procedure_id: procedure.id, dossier_id: dossier.id } }
|
before do
|
||||||
|
dossier.notifications = %w(champs avis commentaire).map{ |type| Notification.create!(type_notif: type) }
|
||||||
|
get method, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
||||||
|
dossier.notifications.each(&:reload)
|
||||||
|
end
|
||||||
|
|
||||||
|
context '#show' do
|
||||||
|
let(:method) { :show }
|
||||||
|
it { expect(dossier.notifications.map(&:already_read)).to match([true, false, false]) }
|
||||||
it { expect(response).to have_http_status(:success) }
|
it { expect(response).to have_http_status(:success) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context '#instruction' do
|
||||||
|
let(:method) { :instruction }
|
||||||
|
it { expect(dossier.notifications.map(&:already_read)).to match([false, true, false]) }
|
||||||
|
it { expect(response).to have_http_status(:success) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context '#messagerie' do
|
||||||
|
let(:method) { :messagerie }
|
||||||
|
it { expect(dossier.notifications.map(&:already_read)).to match([false, false, true]) }
|
||||||
|
it { expect(response).to have_http_status(:success) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#create_commentaire" do
|
describe "#create_commentaire" do
|
||||||
let(:saved_commentaire) { dossier.commentaires.first }
|
let(:saved_commentaire) { dossier.commentaires.first }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue