Merge pull request #140 from sgmap/remove_facade_data_view
Remove @facade_data_view from left_panel view
This commit is contained in:
commit
8fdb61ae54
5 changed files with 56 additions and 26 deletions
|
@ -98,6 +98,10 @@ class Gestionnaire < ActiveRecord::Base
|
|||
0
|
||||
end
|
||||
|
||||
def dossiers_with_notifications_count
|
||||
notifications.pluck(:dossier_id).uniq.count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def valid_couple_table_attr? table, column
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
class Notification < ActiveRecord::Base
|
||||
belongs_to :dossier
|
||||
|
||||
# after_save :broadcast_notification
|
||||
|
||||
enum type_notif: {
|
||||
commentaire: 'commentaire',
|
||||
cerfa: 'cerfa',
|
||||
|
@ -10,10 +7,5 @@ class Notification < ActiveRecord::Base
|
|||
champs: 'champs',
|
||||
submitted: 'submitted'
|
||||
}
|
||||
|
||||
# def broadcast_notification
|
||||
# ActionCable.server.broadcast 'notifications',
|
||||
# message: "Dossier nº #{self.dossier.id} : #{self.liste.last}",
|
||||
# dossier: {id: self.dossier.id}
|
||||
# end
|
||||
scope :unread, -> { where(already_read: false) }
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@ class Procedure < ActiveRecord::Base
|
|||
has_many :types_de_champ, class_name: 'TypeDeChampPublic', dependent: :destroy
|
||||
has_many :types_de_champ_private, dependent: :destroy
|
||||
has_many :dossiers
|
||||
has_many :notifications, through: :dossiers
|
||||
|
||||
has_one :procedure_path, dependent: :destroy
|
||||
|
||||
|
@ -47,6 +48,8 @@ class Procedure < ActiveRecord::Base
|
|||
end
|
||||
|
||||
scope :not_archived, -> { where(archived: false) }
|
||||
scope :by_libelle, -> { order(libelle: :asc) }
|
||||
|
||||
|
||||
def path
|
||||
procedure_path.path unless procedure_path.nil?
|
||||
|
|
|
@ -1,42 +1,42 @@
|
|||
%div#first-block
|
||||
#first-block
|
||||
.dossiers-en-cours
|
||||
.count= @facade_data_view.total_dossier_follow
|
||||
.count= current_gestionnaire.dossiers_follow.count
|
||||
.text SUIVIS
|
||||
.nouveaux-dossiers
|
||||
.count= @facade_data_view.total_new_dossier
|
||||
.count= current_gestionnaire.dossiers.nouveaux.count
|
||||
.text NOUVEAUX
|
||||
.nouvelles-notifications
|
||||
.count= @facade_data_view.dossiers_with_unread_notifications.count
|
||||
.count= current_gestionnaire.dossiers_with_notifications_count
|
||||
.text MODIFIÉS
|
||||
|
||||
%div#action-block
|
||||
#action-block
|
||||
|
||||
%div#menu-block
|
||||
#menu-block
|
||||
.split-hr-left
|
||||
#switch-buttons
|
||||
#switch-procedures.active Procédures
|
||||
#switch-notifications Notifications
|
||||
|
||||
%div#infos-block
|
||||
#infos-block
|
||||
.split-hr-left
|
||||
#procedure-list
|
||||
- @facade_data_view.gestionnaire_procedures_name_and_id_list.each do |procedure|
|
||||
|
||||
= link_to backoffice_dossiers_procedure_path(procedure[:id]), { title: procedure[:libelle] } do
|
||||
.procedure-list-element{ class: ('active' if procedure[:id] == @facade_data_view.procedure.id rescue '') }
|
||||
= truncate(procedure[:libelle], length: 50)
|
||||
- total_new = @facade_data_view.new_dossier_number procedure[:id]
|
||||
- current_gestionnaire.procedures.by_libelle.each do |procedure|
|
||||
= link_to backoffice_dossiers_procedure_path(procedure.id), { title: procedure.libelle } do
|
||||
.procedure-list-element{ class: ('active' if procedure.id.to_s == params[:id]) }
|
||||
= procedure.libelle.truncate(50)
|
||||
- total_new = procedure.dossiers.nouveaux.count
|
||||
- if total_new > 0
|
||||
.badge.progress-bar-success{ title: 'Nouveaux dossiers' }
|
||||
= total_new
|
||||
- if procedure[:unread_notifications] > 0
|
||||
- unread_notif_count = procedure.notifications.unread.count
|
||||
- if unread_notif_count > 0
|
||||
.badge.progress-bar-warning{ title: 'Notifications' }
|
||||
= procedure[:unread_notifications]
|
||||
= unread_notif_count
|
||||
#notifications-list.hidden
|
||||
- if @facade_data_view.dossiers_with_unread_notifications.empty?
|
||||
- if current_gestionnaire.notifications.empty?
|
||||
.no-notification Aucune notification pour le moment.
|
||||
- else
|
||||
- @facade_data_view.dossiers_with_unread_notifications.each do |dossier|
|
||||
- current_gestionnaire.notifications.includes(:dossier).map(&:dossier).uniq.each do |dossier|
|
||||
= link_to backoffice_dossier_path(dossier.id) do
|
||||
.notification
|
||||
.dossier-index= "Dossier nº #{dossier.id}"
|
||||
|
|
|
@ -272,6 +272,37 @@ describe Gestionnaire, type: :model do
|
|||
it { is_expected.to be_nil }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#dossiers_with_notifications_count' do
|
||||
subject { gestionnaire.dossiers_with_notifications_count }
|
||||
|
||||
context 'when there is no notifications' do
|
||||
it { is_expected.to eq(0) }
|
||||
end
|
||||
|
||||
context 'when there is one notification for one dossier' do
|
||||
let(:notification){ create(:notification, already_read: false) }
|
||||
let!(:follow){ create(:follow, dossier: notification.dossier, gestionnaire: gestionnaire) }
|
||||
|
||||
it { is_expected.to eq(1) }
|
||||
end
|
||||
|
||||
context 'when there are many notifications for one dossier' do
|
||||
let(:notification){ create(:notification, already_read: false) }
|
||||
let(:notification2){ create(:notification, already_read: false, dossier: notification.dossier) }
|
||||
let!(:follow){ create(:follow, dossier: notification.dossier, gestionnaire: gestionnaire) }
|
||||
|
||||
it { is_expected.to eq(1) }
|
||||
end
|
||||
|
||||
context 'when there are many notifications for many dossiers' do
|
||||
let(:notification){ create(:notification, already_read: false) }
|
||||
let(:notification2){ create(:notification, already_read: false) }
|
||||
let!(:follow){ create(:follow, dossier: notification.dossier, gestionnaire: gestionnaire) }
|
||||
let!(:follow2){ create(:follow, dossier: notification2.dossier, gestionnaire: gestionnaire) }
|
||||
|
||||
it { is_expected.to eq(2) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue