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
|
||||
@dossier = dossier
|
||||
dossier.notifications.demande.mark_as_read
|
||||
end
|
||||
|
||||
def messagerie
|
||||
@dossier = dossier
|
||||
dossier.notifications.messagerie.mark_as_read
|
||||
end
|
||||
|
||||
def instruction
|
||||
@dossier = dossier
|
||||
dossier.notifications.instruction.mark_as_read
|
||||
end
|
||||
|
||||
def follow
|
||||
|
|
|
@ -104,6 +104,16 @@ class Dossier < ActiveRecord::Base
|
|||
pieces_justificatives.where(type_de_piece_justificative_id: type_id).count > 0
|
||||
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)
|
||||
pieces_justificatives.where(type_de_piece_justificative_id: type).last
|
||||
end
|
||||
|
|
|
@ -8,7 +8,27 @@ class Notification < ActiveRecord::Base
|
|||
avis: 'avis'
|
||||
}
|
||||
|
||||
DEMANDE = %w(cerfa piece_justificative champs submitted)
|
||||
INSTRUCTION = %w(avis)
|
||||
MESSAGERIE = %w(commentaire)
|
||||
|
||||
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
|
||||
|
|
|
@ -6,11 +6,18 @@
|
|||
%li
|
||||
= "Dossier n° #{dossier.id}"
|
||||
%ul.tabs
|
||||
- notifications_summary = dossier.notifications_summary
|
||||
%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)
|
||||
%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)
|
||||
%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)
|
||||
%li
|
||||
= link_to "Historique", "#"
|
||||
|
|
|
@ -72,10 +72,30 @@ describe NewGestionnaire::DossiersController, type: :controller do
|
|||
it { expect(response).to redirect_to(procedures_url) }
|
||||
end
|
||||
|
||||
describe "#show" do
|
||||
before { get :show, params: { procedure_id: procedure.id, dossier_id: dossier.id } }
|
||||
describe '#show #messagerie #instruction' do
|
||||
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
|
||||
|
||||
it { expect(response).to have_http_status(:success) }
|
||||
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) }
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue