Css for index dossier count, using method in dossier model to get unreaded notification count

This commit is contained in:
JC 2017-01-02 16:45:03 +01:00
parent 620a8559dd
commit ac85392454
5 changed files with 24 additions and 16 deletions

View file

@ -169,19 +169,26 @@
margin: 0 30px 0 30px; margin: 0 30px 0 30px;
} }
.notification { .notification {
padding: 10px 10px 10px 20px; padding: 10px 2px 10px 15px;
.dossier, .updated-at { .dossier, .updated-at {
display: inline-block; display: inline-block;
color: #CCCCCC; color: #CCCCCC;
font-size: 12px; font-size: 12px;
text-align: left; text-align: left;
} }
.dossier-index, .updated-at-index { .dossier-index, .updated-at-index, .count {
display: inline-block; display: inline-block;
color: #FFFFFF; color: #FFFFFF;
font-size: 15px; font-size: 14px;
text-align: left; text-align: left;
} }
.count {
background-color: #F0AD4E;
border-radius: 25px;
padding: 0 5px 0 5px;
width: 25px;
text-align: center;
}
.type-notif { .type-notif {
font-size: 16px; font-size: 16px;
} }

View file

@ -3,6 +3,6 @@ class NotificationDecorator < Draper::Decorator
def index_display def index_display
['champs', 'piece_justificative'].include?(type_notif) ? type = liste.join(" ") : type = liste.last ['champs', 'piece_justificative'].include?(type_notif) ? type = liste.join(" ") : type = liste.last
{ dossier: "Dossier n°#{dossier.id}", date: updated_at.strftime('%d/%m %H:%M'), type: type } { dossier: "Dossier n°#{dossier.id}", date: created_at.strftime('%d/%m %H:%M'), type: type }
end end
end end

View file

@ -38,14 +38,6 @@ class DossiersListFacades
current_devise_profil.notifications current_devise_profil.notifications
end end
def last_unread_notifications
last_unread_notifications = []
dossiers_with_unread_notifications.each do |dossier|
last_unread_notifications << dossier.notifications.last
end
return last_unread_notifications
end
def dossiers_with_unread_notifications def dossiers_with_unread_notifications
(unread_notifications.inject([]) { |acc, notif| acc.push(notif.dossier) }).uniq (unread_notifications.inject([]) { |acc, notif| acc.push(notif.dossier) }).uniq
end end

View file

@ -59,6 +59,14 @@ class Dossier < ActiveRecord::Base
TERMINE = %w(closed refused without_continuation) TERMINE = %w(closed refused without_continuation)
ALL_STATE = %w(initiated updated replied validated submitted received closed refused without_continuation) ALL_STATE = %w(initiated updated replied validated submitted received closed refused without_continuation)
def unreaded_notifications
@unreaded_notif ||= notifications.where(already_read: false)
end
def first_unread_notification
unreaded_notifications.order("created_at ASC").first
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

View file

@ -40,8 +40,9 @@
- if @facade_data_view.dossiers_with_unread_notifications.empty? - if @facade_data_view.dossiers_with_unread_notifications.empty?
.no-notification= "Aucune notification pour le moment." .no-notification= "Aucune notification pour le moment."
- else - else
- @facade_data_view.last_unread_notifications.each do |notification| - @facade_data_view.dossiers_with_unread_notifications.each do |dossier|
= link_to backoffice_dossier_path(notification.dossier.id) do = link_to backoffice_dossier_path(dossier.id) do
.notification .notification
.dossier-index= notification.decorate.index_display[:dossier] .dossier-index= "Dossier n°#{dossier.id}"
.updated-at-index= notification.decorate.index_display[:date] .updated-at-index= dossier.first_unread_notification.created_at.strftime('%d/%m %H:%M')
.count= dossier.unreaded_notifications.count