Merge pull request #1313 from betagouv/revert-273b3f2f

Revert "Remove `data_provide` and `data_date_format` attributes"
This commit is contained in:
gregoirenovel 2018-01-23 16:04:28 +01:00 committed by GitHub
commit e76226a9cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 51 additions and 16 deletions

View file

@ -64,6 +64,8 @@ gem 'leaflet-rails'
gem 'leaflet-markercluster-rails', '~> 0.7.0'
gem 'leaflet-draw-rails'
gem 'bootstrap-datepicker-rails'
gem 'chartkick'
gem 'logstasher'

View file

@ -92,6 +92,8 @@ 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)
@ -729,6 +731,7 @@ DEPENDENCIES
active_model_serializers
administrate
apipie-rails
bootstrap-datepicker-rails
bootstrap-sass (~> 3.3.5)
bootstrap-wysihtml5-rails (~> 0.3.3.8)
brakeman

View file

@ -17,6 +17,8 @@
//= 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

View file

@ -46,6 +46,7 @@
// = require attestation_recapitulatif
// = require_self
// = require bootstrap-datepicker3
// = require leaflet
// = require font-awesome
// = require franceconnect

View file

@ -1,4 +1,5 @@
@import "bootstrap";
@import "bootstrap-datepicker3";
#description-page #liste-champs {

View file

@ -19,16 +19,6 @@ 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, '<a target="_blank" href="\0">\0</a>') if description
end

View file

@ -17,6 +17,15 @@ 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

View file

@ -1,5 +1,5 @@
%input.form-control{ name: "champs['#{champ.id}']",
placeholder: "JJ/MM/AAAA",
id: "champs_#{champ.id}",
value: champ.date_for_input,
value: champ.value ? champ.object.value : champ.value,
type: "date" }

View file

@ -1,13 +1,18 @@
= render partial: 'users/description/champs/date', locals: { champ: champ }
%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 }
%br
%select.form-control{ name: "time_hour['#{champ.id}']", style: 'width:50px;display:inline;', id: "time_hour_#{champ.id}" }
%select.form-control{ name: "time_hour['#{champ.id}']", style: 'margin-left: 5px;', 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}']", style: 'width:50px;display:inline;', id: "time_minute_#{champ.id}" }
%select.form-control{ name: "time_minute['#{champ.id}']", id: "time_minute_#{champ.id}" }
- (0..59).each do |num|
- num = "%.2i" %num
- if num.to_i%5 == 0

View file

@ -26,6 +26,28 @@ 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 }

View file

@ -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='date'][id='champs_#{champ_datetime.id}'][value='22/06/2016']") }
it { expect(rendered).to have_css("input[type='datetime'][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