Merge pull request #2897 from betagouv/frederic/fix_2675_sort_by_notification
Corrige le tri par notification sur l’onglet « tous les dossiers »
This commit is contained in:
commit
02697948ed
3 changed files with 36 additions and 26 deletions
|
@ -126,7 +126,7 @@ class Gestionnaire < ApplicationRecord
|
|||
procedure.dossiers.not_archived
|
||||
else
|
||||
procedure.dossiers.en_cours
|
||||
end.followed_by(self)
|
||||
end
|
||||
|
||||
dossiers_id_with_notifications(dossiers)
|
||||
end
|
||||
|
@ -139,35 +139,14 @@ class Gestionnaire < ApplicationRecord
|
|||
Dossier.not_archived
|
||||
else
|
||||
Dossier.en_cours
|
||||
end.followed_by(self)
|
||||
end
|
||||
|
||||
Dossier.where(id: dossiers_id_with_notifications(dossiers)).group(:procedure_id).count
|
||||
end
|
||||
|
||||
def mark_tab_as_seen(dossier, tab)
|
||||
attributes = {}
|
||||
attributes["#{tab}_seen_at"] = DateTime.now
|
||||
Follow.where(gestionnaire: self, dossier: dossier).update_all(attributes)
|
||||
end
|
||||
|
||||
def invite!
|
||||
reset_password_token = set_reset_password_token
|
||||
|
||||
GestionnaireMailer.invite_gestionnaire(self, reset_password_token).deliver_later
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def annotations_hash(demande, annotations_privees, avis, messagerie)
|
||||
{
|
||||
demande: demande,
|
||||
annotations_privees: annotations_privees,
|
||||
avis: avis,
|
||||
messagerie: messagerie
|
||||
}
|
||||
end
|
||||
|
||||
def dossiers_id_with_notifications(dossiers)
|
||||
dossiers = dossiers.followed_by(self)
|
||||
|
||||
updated_demandes = dossiers
|
||||
.joins(:champs)
|
||||
.where('champs.updated_at > follows.demande_seen_at')
|
||||
|
@ -198,4 +177,27 @@ class Gestionnaire < ApplicationRecord
|
|||
updated_messagerie
|
||||
].flat_map { |query| query.distinct.ids }.uniq
|
||||
end
|
||||
|
||||
def mark_tab_as_seen(dossier, tab)
|
||||
attributes = {}
|
||||
attributes["#{tab}_seen_at"] = DateTime.now
|
||||
Follow.where(gestionnaire: self, dossier: dossier).update_all(attributes)
|
||||
end
|
||||
|
||||
def invite!
|
||||
reset_password_token = set_reset_password_token
|
||||
|
||||
GestionnaireMailer.invite_gestionnaire(self, reset_password_token).deliver_later
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def annotations_hash(demande, annotations_privees, avis, messagerie)
|
||||
{
|
||||
demande: demande,
|
||||
annotations_privees: annotations_privees,
|
||||
avis: avis,
|
||||
messagerie: messagerie
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -78,7 +78,7 @@ class ProcedurePresentation < ApplicationRecord
|
|||
|
||||
case table
|
||||
when 'notifications'
|
||||
dossiers_id_with_notification = gestionnaire.notifications_for_procedure(procedure)
|
||||
dossiers_id_with_notification = gestionnaire.dossiers_id_with_notifications(dossiers)
|
||||
if order == 'desc'
|
||||
return dossiers_id_with_notification +
|
||||
(dossiers.order('dossiers.updated_at desc').ids - dossiers_id_with_notification)
|
||||
|
|
|
@ -238,6 +238,7 @@ describe ProcedurePresentation do
|
|||
before do
|
||||
notified_dossier.champs.first.touch(time: DateTime.new(2018, 9, 20))
|
||||
create(:follow, gestionnaire: gestionnaire, dossier: notified_dossier, demande_seen_at: DateTime.new(2018, 9, 10))
|
||||
notified_dossier.touch(time: DateTime.new(2018, 9, 20))
|
||||
recent_dossier.touch(time: DateTime.new(2018, 9, 25))
|
||||
older_dossier.touch(time: DateTime.new(2018, 5, 13))
|
||||
end
|
||||
|
@ -253,6 +254,13 @@ describe ProcedurePresentation do
|
|||
|
||||
it { is_expected.to eq([notified_dossier, recent_dossier, older_dossier].map(&:id)) }
|
||||
end
|
||||
|
||||
context 'with a dossier terminé' do
|
||||
let!(:notified_dossier) { create(:dossier, :accepte, procedure: procedure) }
|
||||
let(:order) { 'desc' }
|
||||
|
||||
it { is_expected.to eq([notified_dossier, recent_dossier, older_dossier].map(&:id)) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'for self table' do
|
||||
|
|
Loading…
Reference in a new issue