Merge pull request #9160 from colinux/improve-instructeurs-filter-date

ETQ instructeur je lis la date d'un filtre dans un format "humain"
This commit is contained in:
Colin Darie 2023-06-12 12:22:51 +00:00 committed by GitHub
commit 9d8ad9b3d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View file

@ -261,10 +261,24 @@ class ProcedurePresentation < ApplicationRecord
instructeur.groupe_instructeurs instructeur.groupe_instructeurs
.find { _1.id == filter['value'].to_i }&.label || filter['value'] .find { _1.id == filter['value'].to_i }&.label || filter['value']
else else
field = find_field(filter[TABLE], filter[COLUMN])
if field["type"] == :date
parsed_date = safe_parse_date(filter['value'])
return parsed_date.present? ? I18n.l(parsed_date) : nil
end
filter['value'] filter['value']
end end
end end
def safe_parse_date(string)
Date.parse(string)
rescue Date::Error
nil
end
def add_filter(statut, field, value) def add_filter(statut, field, value)
if value.present? if value.present?
table, column = field.split(SLASH) table, column = field.split(SLASH)

View file

@ -823,6 +823,14 @@ describe ProcedurePresentation do
expect(subject).to eq("En construction") expect(subject).to eq("En construction")
end end
end end
context 'when filter is a date' do
let(:filters) { { "suivis" => [{ "table" => "self", "column" => "en_instruction_at", "value" => "15/06/2023" }] } }
it 'should get formatted value' do
expect(subject).to eq("15/06/2023")
end
end
end end
describe "#add_filter" do describe "#add_filter" do