diff --git a/Gemfile b/Gemfile index 591ce5f76..8666492d0 100644 --- a/Gemfile +++ b/Gemfile @@ -64,8 +64,6 @@ gem 'leaflet-rails' gem 'leaflet-markercluster-rails', '~> 0.7.0' gem 'leaflet-draw-rails' -gem 'bootstrap-datepicker-rails' - gem 'chartkick' gem 'logstasher' diff --git a/Gemfile.lock b/Gemfile.lock index df20eaa38..0b10d1a88 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -92,8 +92,6 @@ GEM rubyzip (~> 1.0.0) bcrypt (3.1.11) bindata (2.3.4) - bootstrap-datepicker-rails (1.6.4.1) - railties (>= 3.0) bootstrap-sass (3.3.7) autoprefixer-rails (>= 5.2.1) sass (>= 3.3.4) @@ -731,7 +729,6 @@ DEPENDENCIES active_model_serializers administrate apipie-rails - bootstrap-datepicker-rails bootstrap-sass (~> 3.3.5) bootstrap-wysihtml5-rails (~> 0.3.3.8) brakeman diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index d5ce61307..62f9b7d15 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -17,8 +17,6 @@ //= require chartkick //= require_tree ./old_design //= require bootstrap-sprockets -//= require bootstrap-datepicker/core -//= require bootstrap-datepicker/locales/bootstrap-datepicker.fr.js //= require leaflet.js //= require d3.min diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 99cf3f12a..ed0ae2bf5 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -46,7 +46,6 @@ // = require attestation_recapitulatif // = require_self -// = require bootstrap-datepicker3 // = require leaflet // = require font-awesome // = require franceconnect diff --git a/app/assets/stylesheets/description.scss b/app/assets/stylesheets/description.scss index 3efa4d01b..3c97d8476 100644 --- a/app/assets/stylesheets/description.scss +++ b/app/assets/stylesheets/description.scss @@ -1,5 +1,4 @@ @import "bootstrap"; -@import "bootstrap-datepicker3"; #description-page #liste-champs { diff --git a/app/decorators/champ_decorator.rb b/app/decorators/champ_decorator.rb index 4652d5d08..ee6e524e3 100644 --- a/app/decorators/champ_decorator.rb +++ b/app/decorators/champ_decorator.rb @@ -19,6 +19,16 @@ class ChampDecorator < Draper::Decorator end end + def date_for_input + if object.value.present? + if type_champ == "date" + object.value + elsif type_champ == "datetime" && object.value != ' 00:00' + DateTime.parse(object.value, "%d/%m/%Y %H:%M").strftime("%d/%m/%Y") + end + end + end + def description_with_links description.gsub(URI.regexp, '\0') if description end diff --git a/app/models/champ.rb b/app/models/champ.rb index ca6a59c8c..abba4569b 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -17,15 +17,6 @@ class Champ < ActiveRecord::Base mandatory end - def data_provide - return 'datepicker' if (type_champ == 'datetime') && !(BROWSER.value.chrome? || BROWSER.value.edge?) - return 'typeahead' if type_champ == 'address' - end - - def data_date_format - ('dd/mm/yyyy' if type_champ == 'datetime') - end - def same_hour? num same_date? num, '%H' end diff --git a/app/views/users/description/champs/_date.html.haml b/app/views/users/description/champs/_date.html.haml index 74088b67c..7e0d94563 100644 --- a/app/views/users/description/champs/_date.html.haml +++ b/app/views/users/description/champs/_date.html.haml @@ -1,5 +1,5 @@ %input.form-control{ name: "champs['#{champ.id}']", placeholder: "JJ/MM/AAAA", id: "champs_#{champ.id}", - value: champ.value ? champ.object.value : champ.value, + value: champ.date_for_input, type: "date" } diff --git a/app/views/users/description/champs/_datetime.html.haml b/app/views/users/description/champs/_datetime.html.haml index 061ed821d..298d66860 100644 --- a/app/views/users/description/champs/_datetime.html.haml +++ b/app/views/users/description/champs/_datetime.html.haml @@ -1,18 +1,13 @@ -%input.form-control{ name: "champs['#{champ.id}']", - placeholder: champ.libelle, - id: "champs_#{champ.id}", - value: (champ.value.split(/[ ][0-9]*:[0-9]*/).first if champ.value.present?), - type: champ.type_champ, - 'data-provide' => champ.data_provide, - 'data-date-format' => champ.data_date_format } += render partial: 'users/description/champs/date', locals: { champ: champ } -%select.form-control{ name: "time_hour['#{champ.id}']", style: 'margin-left: 5px;', id: "time_hour_#{champ.id}" } +%br +%select.form-control{ name: "time_hour['#{champ.id}']", style: 'width:50px;display:inline;', id: "time_hour_#{champ.id}" } - (0..23).each do |num| - num = "%.2i" %num %option{ value: num, selected: (:selected if champ.same_hour?(num)) } = num h -%select.form-control{ name: "time_minute['#{champ.id}']", id: "time_minute_#{champ.id}" } +%select.form-control{ name: "time_minute['#{champ.id}']", style: 'width:50px;display:inline;', id: "time_minute_#{champ.id}" } - (0..59).each do |num| - num = "%.2i" %num - if num.to_i%5 == 0 diff --git a/spec/models/champ_shared_example.rb b/spec/models/champ_shared_example.rb index c8bb4360e..60dc38e9a 100644 --- a/spec/models/champ_shared_example.rb +++ b/spec/models/champ_shared_example.rb @@ -26,28 +26,6 @@ shared_examples 'champ_spec' do end end - describe 'data_provide' do - let(:champ) { create :champ } - - subject { champ.data_provide } - - context 'when type_champ is datetime' do - before do - champ.type_de_champ = create :type_de_champ_public, type_champ: 'datetime' - end - - it { is_expected.to eq 'datepicker' } - end - - context 'when type_champ is address' do - before do - champ.type_de_champ = create :type_de_champ_public, type_champ: 'address' - end - - it { is_expected.to eq 'typeahead' } - end - end - describe '.departement', vcr: { cassette_name: 'call_geo_api_departements' } do subject { Champ.departements } diff --git a/spec/views/users/description/show.html.haml_spec.rb b/spec/views/users/description/show.html.haml_spec.rb index 4f7bf3d62..c4d78f860 100644 --- a/spec/views/users/description/show.html.haml_spec.rb +++ b/spec/views/users/description/show.html.haml_spec.rb @@ -82,7 +82,7 @@ describe 'users/description/show.html.haml', type: :view do end describe 'datetime value is correctly setup when is not nil' do - it { expect(rendered).to have_css("input[type='datetime'][id='champs_#{champ_datetime.id}'][value='22/06/2016']") } + it { expect(rendered).to have_css("input[type='date'][id='champs_#{champ_datetime.id}'][value='22/06/2016']") } it { expect(rendered).to have_css("option[value='12'][selected='selected']") } it { expect(rendered).to have_css("option[value='05'][selected='selected']") } end