From 30fdc2d796d46c8772a966ad82e041ea9d66d5e1 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Thu, 6 Jun 2024 22:11:59 +0200 Subject: [PATCH] Replace all datepickers with date input Nowadays all browsers have reasonable date input support... --- .../admin/conferences/_form_fields.html.haml | 4 +- app/views/admin/programs/_form.html.haml | 4 +- .../admin/survey_questions/_form.html.haml | 4 +- app/views/admin/surveys/_form.html.haml | 4 +- .../admin/surveys/_survey_question.html.haml | 4 +- spec/features/conference_spec.rb | 45 +++++++------------ 6 files changed, 26 insertions(+), 39 deletions(-) diff --git a/app/views/admin/conferences/_form_fields.html.haml b/app/views/admin/conferences/_form_fields.html.haml index ceb72acc..afa644ed 100644 --- a/app/views/admin/conferences/_form_fields.html.haml +++ b/app/views/admin/conferences/_form_fields.html.haml @@ -49,11 +49,11 @@ .form-group = f.label :start_date, "Start Date" %abbr{title: 'This field is required'} * - = f.text_field :start_date, id: 'conference-start-datepicker', required: true, class: 'form-control' + = f.date_field :start_date, required: true, class: 'form-control' .form-group = f.label :end_date, "End Date" %abbr{title: 'This field is required'} * - = f.text_field :end_date, id: 'conference-end-datepicker', required: true, class: 'form-control' + = f.date_field :end_date, required: true, class: 'form-control' - unless f.object.new_record? # We are showing more fields on the edit form .form-group = f.number_field :start_hour, size: 2, min: 0, max: 23, class: 'form-control' diff --git a/app/views/admin/programs/_form.html.haml b/app/views/admin/programs/_form.html.haml index 037418bf..645cc79d 100644 --- a/app/views/admin/programs/_form.html.haml +++ b/app/views/admin/programs/_form.html.haml @@ -25,9 +25,9 @@ For the feature to work you need to set the voting dates below as well .form-group = f.label :voting_start_date - = f.text_field :voting_start_date, id: 'datetimepicker-voting_start_date', value: (f.object.voting_start_date.to_formatted_s(:db_without_seconds) unless f.object.voting_start_date.nil?), class: 'form-control' + = f.datetime_field :voting_start_date, value: (f.object.voting_start_date.to_formatted_s(:db_without_seconds) unless f.object.voting_start_date.nil?), class: 'form-control' = f.label :voting_end_date - = f.text_field :voting_end_date, id: 'datetimepicker-voting_end_date', value: (f.object.voting_end_date.to_formatted_s(:db_without_seconds) unless f.object.voting_end_date.nil?), class: 'form-control' + = f.datetime_field :voting_end_date, value: (f.object.voting_end_date.to_formatted_s(:db_without_seconds) unless f.object.voting_end_date.nil?), class: 'form-control' %h4 Languages %hr diff --git a/app/views/admin/survey_questions/_form.html.haml b/app/views/admin/survey_questions/_form.html.haml index b77bb1c5..7b8885ed 100644 --- a/app/views/admin/survey_questions/_form.html.haml +++ b/app/views/admin/survey_questions/_form.html.haml @@ -86,10 +86,10 @@ .kinds.text{ class: @survey_question.text? ? '' : 'hidden' } %textarea.form-control{ rows: 4 } .kinds.datetime{ class: @survey_question.datetime? ? '' : 'hidden' } - .form-group{ class: 'datetimepicker' } + .form-group .input-group .input-group-addon %span.fa-solid.fa-calendar - %input.form-control{ readonly: 'readonly' } + %input.form-control{ type: 'datetime-local', readonly: 'readonly' } .kinds.numeric{ class: @survey_question.numeric? ? '' : 'hidden' } %input.form-control{ type: 'number' } diff --git a/app/views/admin/surveys/_form.html.haml b/app/views/admin/surveys/_form.html.haml index b03022ab..3479bbc7 100644 --- a/app/views/admin/surveys/_form.html.haml +++ b/app/views/admin/surveys/_form.html.haml @@ -22,7 +22,7 @@ = f.select :target, Survey.targets.keys, class: 'form-control' .form-group = f.label :start_date - = f.text_field :start_date, class: 'datetimepicker form-control' + = f.datetime_field :start_date, class: 'form-control' = f.label :end_date - = f.text_field :end_date, class: 'datetimepicker form-control' + = f.datetime_field :end_date, class: 'form-control' = f.submit nil, class: 'btn btn-primary' diff --git a/app/views/admin/surveys/_survey_question.html.haml b/app/views/admin/surveys/_survey_question.html.haml index f006036e..0219ce46 100644 --- a/app/views/admin/surveys/_survey_question.html.haml +++ b/app/views/admin/surveys/_survey_question.html.haml @@ -32,10 +32,10 @@ - elsif survey_question.text? = text_area_tag "survey_submission[#{survey_question.id}][]", survey_reply.text, rows: 4, class: 'form-control', required: survey_question.mandatory - elsif survey_question.datetime? - .form-group{ class: 'datetimepicker' } + .form-group .input-group .input-group-addon %span.fa-solid.fa-calendar - %input.form-control{ readonly: 'readonly', name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text, required: survey_question.mandatory } + %input.form-control{ type: 'datetime-local', readonly: 'readonly', name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text, required: survey_question.mandatory } - elsif survey_question.numeric? %input.form-control{ type: 'number', name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text, required: survey_question.mandatory } diff --git a/spec/features/conference_spec.rb b/spec/features/conference_spec.rb index 39d5106f..be4235cc 100644 --- a/spec/features/conference_spec.rb +++ b/spec/features/conference_spec.rb @@ -3,9 +3,19 @@ require 'spec_helper' feature Conference do - let!(:user) { create(:admin) } + let(:user) { create(:admin) } let!(:organization) { create(:organization) } - shared_examples 'add and update conference' do + + describe 'admin' do + let(:conference) { create(:conference, organization: organization) } + + scenario 'has organization name in menu bar for conference views', feature: true, js: true do + sign_in user + visit admin_conference_path(conference.short_title) + + expect(find('.navbar-brand').text).to eq(conference.organization.name) + end + scenario 'adds a new conference', feature: true, js: true do expected_count = Conference.count + 1 sign_in user @@ -19,13 +29,8 @@ feature Conference do select('(GMT+01:00) Berlin', from: 'conference[timezone]') today = Time.zone.today - 1 - page - .execute_script("$('#conference-start-datepicker').val('" + - "#{today.strftime('%d/%m/%Y')}')") - page - .execute_script("$('#conference-end-datepicker').val('" + - "#{(today + 7).strftime('%d/%m/%Y')}')") - + fill_in 'conference_start_date', with: today.strftime('%Y/%m/%d') + fill_in 'conference_end_date', with: (today + 7).strftime('%Y/%m/%d') click_button 'Create Conference' page.find('#flash') @@ -50,13 +55,8 @@ feature Conference do fill_in 'conference_short_title', with: 'NewCon' day = Time.zone.today + 10 - page - .execute_script("$('#conference-start-datepicker').val('" + - "#{day.strftime('%d/%m/%Y')}')") - page - .execute_script("$('#conference-end-datepicker').val('" + - "#{(day + 7).strftime('%d/%m/%Y')}')") - + fill_in 'conference_start_date', with: day.strftime('%Y/%m/%d') + fill_in 'conference_end_date', with: (day + 7).strftime('%Y/%m/%d') page.accept_alert do click_button 'Update Conference' end @@ -70,17 +70,4 @@ feature Conference do expect(Conference.count).to eq(expected_count) end end - - describe 'admin' do - let!(:conference) { create(:conference) } - - scenario 'has organization name in menu bar for conference views', feature: true, js: true do - sign_in user - visit admin_conference_path(conference.short_title) - - expect(find('.navbar-brand').text).to eq(conference.organization.name) - end - - it_behaves_like 'add and update conference' - end end