From c27b2da90b1ed5072d4b08f0ff490196c63bb674 Mon Sep 17 00:00:00 2001 From: Judith Date: Thu, 13 Aug 2020 10:23:11 +0200 Subject: [PATCH 1/2] datetime type de champ: changed the years range from [1950;2100] to [to current year - 1; current year + 50] (or [entered_date; current_year + 50] if old date already entered) because: The type_de_champ Datetime is used for close future dates and very close past dates (for accident declaration for ex.) The select currently has a range from 1950 to 2100, so 70+ years not supposed to be used, leading to: - many bad data entered (0000 or 1950 to not scroll) - making it difficult for users to give the proper date (current date is lost in the middle of 149 others) so risk to be lazy and select a random one or genuinely make a mistake --- app/helpers/champ_helper.rb | 8 ++++++++ .../shared/dossiers/editable_champs/_datetime.html.haml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/helpers/champ_helper.rb b/app/helpers/champ_helper.rb index 7283c967d..2af656d69 100644 --- a/app/helpers/champ_helper.rb +++ b/app/helpers/champ_helper.rb @@ -56,4 +56,12 @@ module ChampHelper end end end + + def datetime_start_year(date) + if date == nil || date.year == 0 || date.year >= Date.today.year - 1 + Date.today.year - 1 + else + date.year + end + end end diff --git a/app/views/shared/dossiers/editable_champs/_datetime.html.haml b/app/views/shared/dossiers/editable_champs/_datetime.html.haml index a64ad3671..3283633f9 100644 --- a/app/views/shared/dossiers/editable_champs/_datetime.html.haml +++ b/app/views/shared/dossiers/editable_champs/_datetime.html.haml @@ -1,4 +1,4 @@ - parsed_value = champ.value.present? ? Time.zone.parse(champ.value) : nil .datetime - = form.datetime_select(:value, selected: parsed_value, start_year: 1950, end_year: 2100, minute_step: 5, include_blank: true) + = form.datetime_select(:value, selected: parsed_value, start_year: datetime_start_year(parsed_value), end_year: Date.today.year + 50, minute_step: 5, include_blank: true) From bfabd3b6a550146645153f8831118a43038a8602 Mon Sep 17 00:00:00 2001 From: Judith Date: Thu, 13 Aug 2020 13:30:52 +0200 Subject: [PATCH 2/2] Specs adapted --- spec/features/users/brouillon_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/features/users/brouillon_spec.rb b/spec/features/users/brouillon_spec.rb index ca27fb539..e7bc4840b 100644 --- a/spec/features/users/brouillon_spec.rb +++ b/spec/features/users/brouillon_spec.rb @@ -14,7 +14,7 @@ feature 'The user' do fill_in('text', with: 'super texte') fill_in('textarea', with: 'super textarea') fill_in('date', with: '12-12-2012') - select_date_and_time(Time.zone.parse('06/01/1985 7h05'), form_id_for_datetime('datetime')) + select_date_and_time(Time.zone.parse('06/01/2030 7h05'), form_id_for_datetime('datetime')) fill_in('number', with: '42') check('checkbox') choose('Madame') @@ -50,7 +50,7 @@ feature 'The user' do expect(champ_value_for('text')).to eq('super texte') expect(champ_value_for('textarea')).to eq('super textarea') expect(champ_value_for('date')).to eq('2012-12-12') - expect(champ_value_for('datetime')).to eq('06/01/1985 07:05') + expect(champ_value_for('datetime')).to eq('06/01/2030 07:05') expect(champ_value_for('number')).to eq('42') expect(champ_value_for('checkbox')).to eq('on') expect(champ_value_for('civilite')).to eq('Mme') @@ -74,7 +74,7 @@ feature 'The user' do expect(page).to have_field('text', with: 'super texte') expect(page).to have_field('textarea', with: 'super textarea') expect(page).to have_field('date', with: '2012-12-12') - check_date_and_time(Time.zone.parse('06/01/1985 7:05'), form_id_for_datetime('datetime')) + check_date_and_time(Time.zone.parse('06/01/2030 7:05'), form_id_for_datetime('datetime')) expect(page).to have_field('number', with: '42') expect(page).to have_checked_field('checkbox') expect(page).to have_checked_field('Madame')