diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 1ca3a5bcf..9a9a01b0b 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -101,14 +101,28 @@ class Gestionnaire < ActiveRecord::Base end end - def notifications_for_procedure(procedure) - dossiers = procedure.dossiers.en_cours.followed_by(self) + def notifications_for_procedure(procedure, state = :en_cours) + dossiers = case state + when :termine + procedure.dossiers.termine + when :not_archived + procedure.dossiers.not_archived + else + procedure.dossiers.en_cours + end.followed_by(self) dossiers_id_with_notifications(dossiers) end - def notifications_per_procedure - dossiers = Dossier.en_cours.followed_by(self) + def notifications_per_procedure(state = :en_cours) + dossiers = case state + when :termine + Dossier.termine + when :not_archived + Dossier.not_archived + else + Dossier.en_cours + end.followed_by(self) Dossier.where(id: dossiers_id_with_notifications(dossiers)).group(:procedure_id).count end diff --git a/app/views/new_gestionnaire/procedures/index.html.haml b/app/views/new_gestionnaire/procedures/index.html.haml index 084518d73..c4faed67a 100644 --- a/app/views/new_gestionnaire/procedures/index.html.haml +++ b/app/views/new_gestionnaire/procedures/index.html.haml @@ -37,6 +37,8 @@ %li %object = link_to(procedure_path(p, statut: 'traites')) do + - if current_gestionnaire.notifications_per_procedure(:termine)[p.id].present? + %span.notifications{ 'aria-label': "notifications" } - termines_count = @dossiers_termines_count_per_procedure[p.id] || 0 .stats-number = termines_count diff --git a/app/views/new_gestionnaire/procedures/show.html.haml b/app/views/new_gestionnaire/procedures/show.html.haml index 2e334e972..b0c4762ef 100644 --- a/app/views/new_gestionnaire/procedures/show.html.haml +++ b/app/views/new_gestionnaire/procedures/show.html.haml @@ -23,13 +23,13 @@ %span.badge= @followed_dossiers.count %li{ class: (@statut == 'traites') ? 'active' : nil }> + - if current_gestionnaire.notifications_for_procedure(@procedure, :termine).present? + %span.notifications{ 'aria-label': 'notifications' } = link_to(procedure_path(@procedure, statut: 'traites')) do = t('pluralize.processed', count: @termines_dossiers.count) %span.badge= @termines_dossiers.count %li{ class: (@statut == 'tous') ? 'active' : nil }> - - if current_gestionnaire.notifications_for_procedure(@procedure).present? - %span.notifications{ 'aria-label': 'notifications' } = link_to(procedure_path(@procedure, statut: 'tous')) do tous les dossiers %span.badge= @all_state_dossiers.count @@ -96,7 +96,7 @@ %td.folder-col = link_to(dossier_path(@procedure, dossier), class: 'cell-link') do %span.icon.folder - - if current_gestionnaire.notifications_for_procedure(@procedure).include?(dossier.id) + - if current_gestionnaire.notifications_for_procedure(@procedure, :not_archived).include?(dossier.id) %span.notifications{ 'aria-label': 'notifications' } %td.number-col