feat(procedure_presentation): add since date filters

This commit is contained in:
Paul Chavard 2022-06-09 13:01:22 +01:00
parent 1cbdfe3d66
commit 95a1ea1047
5 changed files with 34 additions and 3 deletions

View file

@ -4,9 +4,16 @@ module DossierFilteringConcern
included do included do
scope :filter_by_datetimes, lambda { |column, dates| scope :filter_by_datetimes, lambda { |column, dates|
if dates.present? if dates.present?
dates case column
.map { |date| self.where(column => date..(date + 1.day)) } when 'depose_since'
.reduce(:or) where('dossiers.depose_at >= ?', dates.sort.first)
when 'updated_since'
where('dossiers.updated_at >= ?', dates.sort.first)
else
dates
.map { |date| self.where(column => date..(date + 1.day)) }
.reduce(:or)
end
else else
none none
end end

View file

@ -41,6 +41,8 @@ class ProcedurePresentation < ApplicationRecord
field_hash('self', 'en_construction_at'), field_hash('self', 'en_construction_at'),
field_hash('self', 'depose_at'), field_hash('self', 'depose_at'),
field_hash('self', 'updated_at'), field_hash('self', 'updated_at'),
field_hash('self', 'depose_since'),
field_hash('self', 'updated_since'),
field_hash('user', 'email'), field_hash('user', 'email'),
field_hash('followers_instructeurs', 'email'), field_hash('followers_instructeurs', 'email'),
field_hash('groupe_instructeur', 'label') field_hash('groupe_instructeur', 'label')

View file

@ -10,6 +10,8 @@ en:
en_construction_at: En construction le en_construction_at: En construction le
depose_at: Submitted on depose_at: Submitted on
updated_at: Updated on updated_at: Updated on
depose_since: Submitted since
updated_since: Updated since
user: user:
email: Requester email: Requester
followers_instructeurs: followers_instructeurs:

View file

@ -10,6 +10,8 @@ fr:
en_construction_at: En construction le en_construction_at: En construction le
depose_at: Déposé le depose_at: Déposé le
updated_at: Mis à jour le updated_at: Mis à jour le
depose_since: Déposé depuis
updated_since: Mis à jour depuis
user: user:
email: Demandeur email: Demandeur
followers_instructeurs: followers_instructeurs:

View file

@ -62,6 +62,8 @@ describe ProcedurePresentation do
{ "label" => 'En construction le', "table" => 'self', "column" => 'en_construction_at', 'classname' => '' }, { "label" => 'En construction le', "table" => 'self', "column" => 'en_construction_at', 'classname' => '' },
{ "label" => 'Déposé le', "table" => 'self', "column" => 'depose_at', 'classname' => '' }, { "label" => 'Déposé le', "table" => 'self', "column" => 'depose_at', 'classname' => '' },
{ "label" => 'Mis à jour le', "table" => 'self', "column" => 'updated_at', 'classname' => '' }, { "label" => 'Mis à jour le', "table" => 'self', "column" => 'updated_at', 'classname' => '' },
{ "label" => "Déposé depuis", "table" => "self", "column" => "depose_since", "classname" => "" },
{ "label" => "Mis à jour depuis", "table" => "self", "column" => "updated_since", "classname" => "" },
{ "label" => 'Demandeur', "table" => 'user', "column" => 'email', 'classname' => '' }, { "label" => 'Demandeur', "table" => 'user', "column" => 'email', 'classname' => '' },
{ "label" => 'Email instructeur', "table" => 'followers_instructeurs', "column" => 'email', 'classname' => '' }, { "label" => 'Email instructeur', "table" => 'followers_instructeurs', "column" => 'email', 'classname' => '' },
{ "label" => 'Groupe instructeur', "table" => 'groupe_instructeur', "column" => 'label', 'classname' => '' }, { "label" => 'Groupe instructeur', "table" => 'groupe_instructeur', "column" => 'label', 'classname' => '' },
@ -415,6 +417,22 @@ describe ProcedurePresentation do
it { is_expected.to contain_exactly(kept_dossier.id) } it { is_expected.to contain_exactly(kept_dossier.id) }
end end
context 'for updated_since column' do
let(:filter) { [{ 'table' => 'self', 'column' => 'updated_since', 'value' => '18/9/2018' }] }
let(:kept_dossier) { create(:dossier, procedure: procedure) }
let(:later_dossier) { create(:dossier, procedure: procedure) }
let(:discarded_dossier) { create(:dossier, procedure: procedure) }
before do
kept_dossier.touch(time: Time.zone.local(2018, 9, 18, 14, 28))
later_dossier.touch(time: Time.zone.local(2018, 9, 19, 14, 28))
discarded_dossier.touch(time: Time.zone.local(2018, 9, 17, 14, 28))
end
it { is_expected.to match_array([kept_dossier.id, later_dossier.id]) }
end
context 'ignore time of day' do context 'ignore time of day' do
let(:filter) { [{ 'table' => 'self', 'column' => 'en_construction_at', 'value' => '17/10/2018 19:30' }] } let(:filter) { [{ 'table' => 'self', 'column' => 'en_construction_at', 'value' => '17/10/2018 19:30' }] }