Merge branch 'develop' into staging
This commit is contained in:
commit
73171a6ad5
14 changed files with 156 additions and 65 deletions
|
@ -77,12 +77,21 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.type_champ-datetime {
|
.type_champ-date {
|
||||||
@extend .col-md-2;
|
@extend .col-md-2;
|
||||||
@extend .col-lg-2;
|
@extend .col-lg-2;
|
||||||
|
|
||||||
input[type='number'] {
|
input[type='date'] {
|
||||||
width: 100%;
|
width: 120px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.type_champ-datetime {
|
||||||
|
@extend .col-md-4;
|
||||||
|
@extend .col-lg-4;
|
||||||
|
|
||||||
|
input[type='datetime'] {
|
||||||
|
width: 120px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,14 @@ class Users::DescriptionController < UsersController
|
||||||
@dossier.champs.each do |champ|
|
@dossier.champs.each do |champ|
|
||||||
champ.value = params[:champs]["'#{champ.id}'"]
|
champ.value = params[:champs]["'#{champ.id}'"]
|
||||||
|
|
||||||
|
if champ.type_champ == 'datetime'
|
||||||
|
champ.value = params[:champs]["'#{champ.id}'"]+
|
||||||
|
' ' +
|
||||||
|
params[:time_hour]["'#{champ.id}'"] +
|
||||||
|
':' +
|
||||||
|
params[:time_minute]["'#{champ.id}'"]
|
||||||
|
end
|
||||||
|
|
||||||
if champ.mandatory? && (champ.value.nil? || champ.value.blank?)
|
if champ.mandatory? && (champ.value.nil? || champ.value.blank?)
|
||||||
flash.now.alert = "Le champ #{champ.libelle} doit être rempli."
|
flash.now.alert = "Le champ #{champ.libelle} doit être rempli."
|
||||||
return render 'show'
|
return render 'show'
|
||||||
|
|
|
@ -9,7 +9,28 @@ class Champ < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def data_provide
|
def data_provide
|
||||||
return 'datepicker' if type_champ == 'datetime'
|
return 'datepicker' if type_champ == 'datetime' || type_champ == 'date'
|
||||||
return 'typeahead' if type_champ == 'address'
|
return 'typeahead' if type_champ == 'address'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def data_date_format
|
||||||
|
('dd/mm/yyyy' if type_champ == 'datetime' || type_champ == 'date')
|
||||||
|
end
|
||||||
|
|
||||||
|
def same_hour? num
|
||||||
|
same_date? num, '%H'
|
||||||
|
end
|
||||||
|
|
||||||
|
def same_minute? num
|
||||||
|
same_date? num, '%M'
|
||||||
|
end
|
||||||
|
|
||||||
|
def same_date? num, compare
|
||||||
|
if type_champ == 'datetime' && !value.nil?
|
||||||
|
if value.to_datetime.strftime(compare) == num
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,7 @@ class TypeDeChamp < ActiveRecord::Base
|
||||||
enum type_champs: {
|
enum type_champs: {
|
||||||
text: 'text',
|
text: 'text',
|
||||||
textarea: 'textarea',
|
textarea: 'textarea',
|
||||||
|
date: 'date',
|
||||||
datetime: 'datetime',
|
datetime: 'datetime',
|
||||||
number: 'number',
|
number: 'number',
|
||||||
checkbox: 'checkbox',
|
checkbox: 'checkbox',
|
||||||
|
|
|
@ -7,38 +7,18 @@ class DossierService
|
||||||
end
|
end
|
||||||
|
|
||||||
def dossier_informations!
|
def dossier_informations!
|
||||||
entreprise_thread = Thread.new {
|
|
||||||
@entreprise_adapter = SIADE::EntrepriseAdapter.new(DossierService.siren @siret)
|
@entreprise_adapter = SIADE::EntrepriseAdapter.new(DossierService.siren @siret)
|
||||||
|
|
||||||
@dossier.create_entreprise(@entreprise_adapter.to_params)
|
@dossier.create_entreprise(@entreprise_adapter.to_params)
|
||||||
}
|
|
||||||
|
|
||||||
etablissement_thread = Thread.new {
|
|
||||||
@etablissement_adapter = SIADE::EtablissementAdapter.new(@siret)
|
@etablissement_adapter = SIADE::EtablissementAdapter.new(@siret)
|
||||||
|
|
||||||
@dossier.create_etablissement(@etablissement_adapter.to_params)
|
@dossier.create_etablissement(@etablissement_adapter.to_params)
|
||||||
}
|
|
||||||
|
|
||||||
rna_thread = Thread.new {
|
|
||||||
@rna_adapter = SIADE::RNAAdapter.new(@siret)
|
@rna_adapter = SIADE::RNAAdapter.new(@siret)
|
||||||
|
|
||||||
sleep(0.1) while entreprise_thread.alive?
|
|
||||||
|
|
||||||
@dossier.entreprise.create_rna_information(@rna_adapter.to_params)
|
@dossier.entreprise.create_rna_information(@rna_adapter.to_params)
|
||||||
}
|
|
||||||
|
|
||||||
exercices_thread = Thread.new {
|
|
||||||
@exercices_adapter = SIADE::ExercicesAdapter.new(@siret)
|
@exercices_adapter = SIADE::ExercicesAdapter.new(@siret)
|
||||||
|
|
||||||
sleep(0.1) while etablissement_thread.alive?
|
|
||||||
|
|
||||||
@dossier.etablissement.exercices.create(@exercices_adapter.to_params)
|
@dossier.etablissement.exercices.create(@exercices_adapter.to_params)
|
||||||
}
|
|
||||||
|
|
||||||
sleep(0.1) while entreprise_thread.alive? ||
|
|
||||||
etablissement_thread.alive? ||
|
|
||||||
rna_thread.alive? ||
|
|
||||||
exercices_thread.alive?
|
|
||||||
|
|
||||||
@dossier.update_attributes(mandataire_social: mandataire_social?(@entreprise_adapter.mandataires_sociaux))
|
@dossier.update_attributes(mandataire_social: mandataire_social?(@entreprise_adapter.mandataires_sociaux))
|
||||||
@dossier.etablissement.update_attributes(entreprise: @dossier.entreprise)
|
@dossier.etablissement.update_attributes(entreprise: @dossier.entreprise)
|
||||||
|
|
|
@ -15,19 +15,13 @@
|
||||||
= '*'
|
= '*'
|
||||||
|
|
||||||
-if champ.type_champ == 'textarea'
|
-if champ.type_champ == 'textarea'
|
||||||
%textarea.form-control.wysihtml5{name:"champs['#{champ.id}']",
|
=render partial: 'users/description/champs/textarea', locals: {champ: champ}
|
||||||
placeholder: champ.description,
|
|
||||||
id: "champs_#{champ.id}",
|
|
||||||
row: '6'}
|
|
||||||
=champ.value
|
|
||||||
-elsif champ.type_champ == 'civilite'
|
|
||||||
%label.radio-inline
|
|
||||||
= radio_button_tag "champs['#{champ.id}']", "M.", champ.value == 'Mme' ? false : true
|
|
||||||
Monsieur
|
|
||||||
|
|
||||||
%label.radio-inline
|
-elsif champ.type_champ == 'civilite'
|
||||||
= radio_button_tag "champs['#{champ.id}']", "Mme", champ.value == 'Mme'
|
=render partial: 'users/description/champs/civilite', locals: {champ: champ}
|
||||||
Madame
|
|
||||||
|
- elsif champ.type_champ == 'datetime'
|
||||||
|
=render partial: 'users/description/champs/datetime', locals: {champ: champ}
|
||||||
|
|
||||||
-else
|
-else
|
||||||
%input.form-control{name:"champs['#{champ.id}']",
|
%input.form-control{name:"champs['#{champ.id}']",
|
||||||
|
@ -36,7 +30,7 @@
|
||||||
value: champ.value,
|
value: champ.value,
|
||||||
type: champ.type_champ,
|
type: champ.type_champ,
|
||||||
'data-provide' => champ.data_provide,
|
'data-provide' => champ.data_provide,
|
||||||
'data-date-format' => ('dd/mm/yyyy' if champ.type_champ == 'datetime')}
|
'data-date-format' => champ.data_date_format}
|
||||||
|
|
||||||
- unless champ.description.empty?
|
- unless champ.description.empty?
|
||||||
.row
|
.row
|
||||||
|
|
7
app/views/users/description/champs/_civilite.html.haml
Normal file
7
app/views/users/description/champs/_civilite.html.haml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
%label.radio-inline
|
||||||
|
= radio_button_tag "champs['#{champ.id}']", "M.", champ.value == 'Mme' ? false : true
|
||||||
|
Monsieur
|
||||||
|
|
||||||
|
%label.radio-inline
|
||||||
|
= radio_button_tag "champs['#{champ.id}']", "Mme", champ.value == 'Mme'
|
||||||
|
Madame
|
21
app/views/users/description/champs/_datetime.html.haml
Normal file
21
app/views/users/description/champs/_datetime.html.haml
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
%input.form-control{name:"champs['#{champ.id}']",
|
||||||
|
placeholder: champ.libelle,
|
||||||
|
id: "champs_#{champ.id}",
|
||||||
|
value: (champ.value.split(/[ ][0-9]*:[0-9]*/).first unless champ.value.nil?),
|
||||||
|
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}"}
|
||||||
|
- (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}"}
|
||||||
|
- (0..59).each do |num|
|
||||||
|
- num = "%.2i" %num
|
||||||
|
- if num.to_i%5 == 0
|
||||||
|
%option{value: num, selected: (:selected if champ.same_minute?(num))}
|
||||||
|
= num
|
||||||
|
min
|
5
app/views/users/description/champs/_textarea.html.haml
Normal file
5
app/views/users/description/champs/_textarea.html.haml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
%textarea.form-control.wysihtml5{name:"champs['#{champ.id}']",
|
||||||
|
placeholder: champ.description,
|
||||||
|
id: "champs_#{champ.id}",
|
||||||
|
row: '6'}
|
||||||
|
=champ.value
|
|
@ -0,0 +1,15 @@
|
||||||
|
class ConvertAllDatetimeToDateOnDatabase < ActiveRecord::Migration
|
||||||
|
|
||||||
|
class TypeDeChamp < ActiveRecord::Base
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def change
|
||||||
|
TypeDeChamp.all.each do |type_de_champ|
|
||||||
|
if type_de_champ.type_champ == 'datetime'
|
||||||
|
type_de_champ.type_champ = 'date'
|
||||||
|
type_de_champ.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20160609145737) do
|
ActiveRecord::Schema.define(version: 20160622081321) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
||||||
describe Users::DescriptionController, type: :controller, vcr: {cassette_name: 'controllers_users_description_controller'} do
|
describe Users::DescriptionController, type: :controller, vcr: {cassette_name: 'controllers_users_description_controller'} do
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, cerfa_flag: true) }
|
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime, cerfa_flag: true) }
|
||||||
let(:dossier) { create(:dossier, procedure: procedure, user: user) }
|
let(:dossier) { create(:dossier, procedure: procedure, user: user) }
|
||||||
|
|
||||||
let(:dossier_id) { dossier.id }
|
let(:dossier_id) { dossier.id }
|
||||||
|
@ -67,11 +67,10 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name:
|
||||||
let(:description) { 'Description de test Coucou, je suis un saut à la ligne Je suis un double saut la ligne.' }
|
let(:description) { 'Description de test Coucou, je suis un saut à la ligne Je suis un double saut la ligne.' }
|
||||||
|
|
||||||
context 'Tous les attributs sont bons' do
|
context 'Tous les attributs sont bons' do
|
||||||
# TODO separer en deux tests : check donnees et check redirect
|
|
||||||
describe 'Premier enregistrement des données' do
|
describe 'Premier enregistrement des données' do
|
||||||
before do
|
before do
|
||||||
dossier.draft!
|
dossier.draft!
|
||||||
post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description
|
post :create, dossier_id: dossier_id, nom_projet: nom_projet
|
||||||
dossier.reload
|
dossier.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -79,12 +78,13 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name:
|
||||||
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif")
|
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it { expect(dossier.nom_projet).to eq nom_projet }
|
||||||
|
|
||||||
it 'etat du dossier est soumis' do
|
it 'etat du dossier est soumis' do
|
||||||
expect(dossier.state).to eq('initiated')
|
expect(dossier.state).to eq('initiated')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO changer les valeurs des champs et check in bdd
|
|
||||||
context 'En train de manipuler un dossier non brouillon' do
|
context 'En train de manipuler un dossier non brouillon' do
|
||||||
before do
|
before do
|
||||||
dossier.initiated!
|
dossier.initiated!
|
||||||
|
@ -180,13 +180,23 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name:
|
||||||
describe 'Sauvegarde des champs' do
|
describe 'Sauvegarde des champs' do
|
||||||
let(:champs_dossier) { dossier.champs }
|
let(:champs_dossier) { dossier.champs }
|
||||||
let(:dossier_champs_first) { 'test value' }
|
let(:dossier_champs_first) { 'test value' }
|
||||||
|
let(:dossier_date_value) { '23/06/2016' }
|
||||||
|
let(:dossier_hour_value) { '17' }
|
||||||
|
let(:dossier_minute_value) { '00' }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
post :create, {dossier_id: dossier_id,
|
post :create, {dossier_id: dossier_id,
|
||||||
nom_projet: nom_projet,
|
nom_projet: nom_projet,
|
||||||
description: description,
|
description: description,
|
||||||
champs: {
|
champs: {
|
||||||
"'#{dossier.champs.first.id}'" => dossier_champs_first
|
"'#{dossier.champs.first.id}'" => dossier_champs_first,
|
||||||
|
"'#{dossier.champs.second.id}'" => dossier_date_value
|
||||||
|
},
|
||||||
|
time_hour: {
|
||||||
|
"'#{dossier.champs.second.id}'" => dossier_hour_value,
|
||||||
|
},
|
||||||
|
time_minute: {
|
||||||
|
"'#{dossier.champs.second.id}'" => dossier_minute_value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dossier.reload
|
dossier.reload
|
||||||
|
@ -195,6 +205,10 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name:
|
||||||
it { expect(dossier.champs.first.value).to eq(dossier_champs_first) }
|
it { expect(dossier.champs.first.value).to eq(dossier_champs_first) }
|
||||||
it { expect(response).to redirect_to users_dossier_recapitulatif_path }
|
it { expect(response).to redirect_to users_dossier_recapitulatif_path }
|
||||||
|
|
||||||
|
context 'when champs is type_de_champ datetime' do
|
||||||
|
it { expect(dossier.champs.second.value).to eq(dossier_date_value+' '+dossier_hour_value+':'+dossier_minute_value) }
|
||||||
|
end
|
||||||
|
|
||||||
context 'when champs value is empty' do
|
context 'when champs value is empty' do
|
||||||
let(:dossier_champs_first) { '' }
|
let(:dossier_champs_first) { '' }
|
||||||
|
|
||||||
|
@ -202,7 +216,7 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name:
|
||||||
it { expect(response).to redirect_to users_dossier_recapitulatif_path }
|
it { expect(response).to redirect_to users_dossier_recapitulatif_path }
|
||||||
|
|
||||||
context 'when champs is mandatory' do
|
context 'when champs is mandatory' do
|
||||||
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ_mandatory, cerfa_flag: true) }
|
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ_mandatory, :with_datetime, cerfa_flag: true) }
|
||||||
|
|
||||||
it { expect(response).not_to redirect_to users_dossier_recapitulatif_path }
|
it { expect(response).not_to redirect_to users_dossier_recapitulatif_path }
|
||||||
it { expect(flash[:alert]).to be_present }
|
it { expect(flash[:alert]).to be_present }
|
||||||
|
@ -230,8 +244,6 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name:
|
||||||
description: description,
|
description: description,
|
||||||
'piece_justificative_'+all_pj_type[0].to_s => piece_justificative_0,
|
'piece_justificative_'+all_pj_type[0].to_s => piece_justificative_0,
|
||||||
'piece_justificative_'+all_pj_type[1].to_s => piece_justificative_1}
|
'piece_justificative_'+all_pj_type[1].to_s => piece_justificative_1}
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,14 @@ FactoryGirl.define do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :with_datetime do
|
||||||
|
after(:build) do |procedure, _evaluator|
|
||||||
|
type_de_champ = create(:type_de_champ, mandatory: true, type_champ: :datetime)
|
||||||
|
|
||||||
|
procedure.types_de_champ << type_de_champ
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
trait :with_two_type_de_piece_justificative do
|
trait :with_two_type_de_piece_justificative do
|
||||||
after(:build) do |procedure, _evaluator|
|
after(:build) do |procedure, _evaluator|
|
||||||
rib = create(:type_de_piece_justificative, :rib)
|
rib = create(:type_de_piece_justificative, :rib)
|
||||||
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
||||||
describe 'users/description/show.html.haml', type: :view do
|
describe 'users/description/show.html.haml', type: :view do
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
let(:cerfa_flag) { true }
|
let(:cerfa_flag) { true }
|
||||||
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, cerfa_flag: cerfa_flag) }
|
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime, cerfa_flag: cerfa_flag) }
|
||||||
let(:dossier) { create(:dossier, procedure: procedure, user: user) }
|
let(:dossier) { create(:dossier, procedure: procedure, user: user) }
|
||||||
let(:dossier_id) { dossier.id }
|
let(:dossier_id) { dossier.id }
|
||||||
|
|
||||||
|
@ -82,8 +82,12 @@ describe 'users/description/show.html.haml', type: :view do
|
||||||
|
|
||||||
context 'Champs' do
|
context 'Champs' do
|
||||||
let(:champs) { dossier.champs }
|
let(:champs) { dossier.champs }
|
||||||
|
let(:types_de_champ) { procedure.types_de_champ.where(type_champ: 'datetime').first }
|
||||||
|
let(:champ_datetime) { champs.where(type_de_champ_id: types_de_champ.id).first }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
champ_datetime.value = "22/06/2016 12:05"
|
||||||
|
champ_datetime.save
|
||||||
render
|
render
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -98,6 +102,12 @@ describe 'users/description/show.html.haml', type: :view do
|
||||||
it { expect(rendered).to have_css(".type_champ-#{subject.type_champ}") }
|
it { expect(rendered).to have_css(".type_champ-#{subject.type_champ}") }
|
||||||
it { expect(rendered).to have_css("#champs_#{subject.id}") }
|
it { expect(rendered).to have_css("#champs_#{subject.id}") }
|
||||||
end
|
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("option[value='12'][selected='selected']")}
|
||||||
|
it { expect(rendered).to have_css("option[value='05'][selected='selected']")}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Pièces justificatives' do
|
context 'Pièces justificatives' do
|
||||||
|
|
Loading…
Reference in a new issue