Merge pull request #1284 from tchak/drop-data_provide-and-data_date_format
Remove `data_provide` and `data_date_format` attributes
This commit is contained in:
commit
ddfa1e99d4
11 changed files with 16 additions and 51 deletions
2
Gemfile
2
Gemfile
|
@ -64,8 +64,6 @@ gem 'leaflet-rails'
|
||||||
gem 'leaflet-markercluster-rails', '~> 0.7.0'
|
gem 'leaflet-markercluster-rails', '~> 0.7.0'
|
||||||
gem 'leaflet-draw-rails'
|
gem 'leaflet-draw-rails'
|
||||||
|
|
||||||
gem 'bootstrap-datepicker-rails'
|
|
||||||
|
|
||||||
gem 'chartkick'
|
gem 'chartkick'
|
||||||
|
|
||||||
gem 'logstasher'
|
gem 'logstasher'
|
||||||
|
|
|
@ -92,8 +92,6 @@ GEM
|
||||||
rubyzip (~> 1.0.0)
|
rubyzip (~> 1.0.0)
|
||||||
bcrypt (3.1.11)
|
bcrypt (3.1.11)
|
||||||
bindata (2.3.4)
|
bindata (2.3.4)
|
||||||
bootstrap-datepicker-rails (1.6.4.1)
|
|
||||||
railties (>= 3.0)
|
|
||||||
bootstrap-sass (3.3.7)
|
bootstrap-sass (3.3.7)
|
||||||
autoprefixer-rails (>= 5.2.1)
|
autoprefixer-rails (>= 5.2.1)
|
||||||
sass (>= 3.3.4)
|
sass (>= 3.3.4)
|
||||||
|
@ -731,7 +729,6 @@ DEPENDENCIES
|
||||||
active_model_serializers
|
active_model_serializers
|
||||||
administrate
|
administrate
|
||||||
apipie-rails
|
apipie-rails
|
||||||
bootstrap-datepicker-rails
|
|
||||||
bootstrap-sass (~> 3.3.5)
|
bootstrap-sass (~> 3.3.5)
|
||||||
bootstrap-wysihtml5-rails (~> 0.3.3.8)
|
bootstrap-wysihtml5-rails (~> 0.3.3.8)
|
||||||
brakeman
|
brakeman
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
//= require chartkick
|
//= require chartkick
|
||||||
//= require_tree ./old_design
|
//= require_tree ./old_design
|
||||||
//= require bootstrap-sprockets
|
//= require bootstrap-sprockets
|
||||||
//= require bootstrap-datepicker/core
|
|
||||||
//= require bootstrap-datepicker/locales/bootstrap-datepicker.fr.js
|
|
||||||
|
|
||||||
//= require leaflet.js
|
//= require leaflet.js
|
||||||
//= require d3.min
|
//= require d3.min
|
||||||
|
|
|
@ -46,7 +46,6 @@
|
||||||
// = require attestation_recapitulatif
|
// = require attestation_recapitulatif
|
||||||
|
|
||||||
// = require_self
|
// = require_self
|
||||||
// = require bootstrap-datepicker3
|
|
||||||
// = require leaflet
|
// = require leaflet
|
||||||
// = require font-awesome
|
// = require font-awesome
|
||||||
// = require franceconnect
|
// = require franceconnect
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
@import "bootstrap";
|
@import "bootstrap";
|
||||||
@import "bootstrap-datepicker3";
|
|
||||||
|
|
||||||
#description-page #liste-champs {
|
#description-page #liste-champs {
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,16 @@ class ChampDecorator < Draper::Decorator
|
||||||
end
|
end
|
||||||
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
|
def description_with_links
|
||||||
description.gsub(URI.regexp, '<a target="_blank" href="\0">\0</a>') if description
|
description.gsub(URI.regexp, '<a target="_blank" href="\0">\0</a>') if description
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,15 +17,6 @@ class Champ < ActiveRecord::Base
|
||||||
mandatory
|
mandatory
|
||||||
end
|
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
|
def same_hour? num
|
||||||
same_date? num, '%H'
|
same_date? num, '%H'
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
%input.form-control{ name: "champs['#{champ.id}']",
|
%input.form-control{ name: "champs['#{champ.id}']",
|
||||||
placeholder: "JJ/MM/AAAA",
|
placeholder: "JJ/MM/AAAA",
|
||||||
id: "champs_#{champ.id}",
|
id: "champs_#{champ.id}",
|
||||||
value: champ.value ? champ.object.value : champ.value,
|
value: champ.date_for_input,
|
||||||
type: "date" }
|
type: "date" }
|
||||||
|
|
|
@ -1,18 +1,13 @@
|
||||||
%input.form-control{ name: "champs['#{champ.id}']",
|
= render partial: 'users/description/champs/date', locals: { champ: champ }
|
||||||
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 }
|
|
||||||
|
|
||||||
%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|
|
- (0..23).each do |num|
|
||||||
- num = "%.2i" %num
|
- num = "%.2i" %num
|
||||||
%option{ value: num, selected: (:selected if champ.same_hour?(num)) }
|
%option{ value: num, selected: (:selected if champ.same_hour?(num)) }
|
||||||
= num
|
= num
|
||||||
h
|
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|
|
- (0..59).each do |num|
|
||||||
- num = "%.2i" %num
|
- num = "%.2i" %num
|
||||||
- if num.to_i%5 == 0
|
- if num.to_i%5 == 0
|
||||||
|
|
|
@ -26,28 +26,6 @@ shared_examples 'champ_spec' do
|
||||||
end
|
end
|
||||||
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
|
describe '.departement', vcr: { cassette_name: 'call_geo_api_departements' } do
|
||||||
subject { Champ.departements }
|
subject { Champ.departements }
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ describe 'users/description/show.html.haml', type: :view do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'datetime value is correctly setup when is not nil' do
|
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='12'][selected='selected']") }
|
||||||
it { expect(rendered).to have_css("option[value='05'][selected='selected']") }
|
it { expect(rendered).to have_css("option[value='05'][selected='selected']") }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue