diff --git a/app/assets/stylesheets/description.scss b/app/assets/stylesheets/description.scss index e40c2d551..6bef57d7f 100644 --- a/app/assets/stylesheets/description.scss +++ b/app/assets/stylesheets/description.scss @@ -77,12 +77,21 @@ } } -.type_champ-datetime { +.type_champ-date { @extend .col-md-2; @extend .col-lg-2; - input[type='number'] { - width: 100%; + input[type='date'] { + width: 120px; + } +} + +.type_champ-datetime { + @extend .col-md-4; + @extend .col-lg-4; + + input[type='datetime'] { + width: 120px; } } diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb index ea9a9954f..dfe9672d3 100644 --- a/app/controllers/users/description_controller.rb +++ b/app/controllers/users/description_controller.rb @@ -46,6 +46,14 @@ class Users::DescriptionController < UsersController @dossier.champs.each do |champ| 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?) flash.now.alert = "Le champ #{champ.libelle} doit être rempli." return render 'show' diff --git a/app/models/champ.rb b/app/models/champ.rb index 593acfe97..7b6c357b9 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -9,7 +9,28 @@ class Champ < ActiveRecord::Base end def data_provide - return 'datepicker' if type_champ == 'datetime' + return 'datepicker' if type_champ == 'datetime' || type_champ == 'date' return 'typeahead' if type_champ == 'address' 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 diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 98b148447..3f3bdf1f4 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -2,6 +2,7 @@ class TypeDeChamp < ActiveRecord::Base enum type_champs: { text: 'text', textarea: 'textarea', + date: 'date', datetime: 'datetime', number: 'number', checkbox: 'checkbox', diff --git a/app/services/dossier_service.rb b/app/services/dossier_service.rb index 1c33fd769..d6ee9b4ae 100644 --- a/app/services/dossier_service.rb +++ b/app/services/dossier_service.rb @@ -7,38 +7,18 @@ class DossierService end 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_adapter = SIADE::EtablissementAdapter.new(@siret) - etablissement_thread = Thread.new { - @etablissement_adapter = SIADE::EtablissementAdapter.new(@siret) + @dossier.create_etablissement(@etablissement_adapter.to_params) - @dossier.create_etablissement(@etablissement_adapter.to_params) - } + @rna_adapter = SIADE::RNAAdapter.new(@siret) + @dossier.entreprise.create_rna_information(@rna_adapter.to_params) - rna_thread = Thread.new { - @rna_adapter = SIADE::RNAAdapter.new(@siret) - - sleep(0.1) while entreprise_thread.alive? - - @dossier.entreprise.create_rna_information(@rna_adapter.to_params) - } - - exercices_thread = Thread.new { - @exercices_adapter = SIADE::ExercicesAdapter.new(@siret) - - sleep(0.1) while etablissement_thread.alive? - - @dossier.etablissement.exercices.create(@exercices_adapter.to_params) - } - - sleep(0.1) while entreprise_thread.alive? || - etablissement_thread.alive? || - rna_thread.alive? || - exercices_thread.alive? + @exercices_adapter = SIADE::ExercicesAdapter.new(@siret) + @dossier.etablissement.exercices.create(@exercices_adapter.to_params) @dossier.update_attributes(mandataire_social: mandataire_social?(@entreprise_adapter.mandataires_sociaux)) @dossier.etablissement.update_attributes(entreprise: @dossier.entreprise) diff --git a/app/views/users/description/_champs.html.haml b/app/views/users/description/_champs.html.haml index db6decbf3..df175b482 100644 --- a/app/views/users/description/_champs.html.haml +++ b/app/views/users/description/_champs.html.haml @@ -15,19 +15,13 @@ = '*' -if champ.type_champ == 'textarea' - %textarea.form-control.wysihtml5{name:"champs['#{champ.id}']", - 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 + =render partial: 'users/description/champs/textarea', locals: {champ: champ} - %label.radio-inline - = radio_button_tag "champs['#{champ.id}']", "Mme", champ.value == 'Mme' - Madame + -elsif champ.type_champ == 'civilite' + =render partial: 'users/description/champs/civilite', locals: {champ: champ} + + - elsif champ.type_champ == 'datetime' + =render partial: 'users/description/champs/datetime', locals: {champ: champ} -else %input.form-control{name:"champs['#{champ.id}']", @@ -36,7 +30,7 @@ value: champ.value, type: champ.type_champ, '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? .row diff --git a/app/views/users/description/champs/_civilite.html.haml b/app/views/users/description/champs/_civilite.html.haml new file mode 100644 index 000000000..1a9ad45f3 --- /dev/null +++ b/app/views/users/description/champs/_civilite.html.haml @@ -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 \ No newline at end of file diff --git a/app/views/users/description/champs/_datetime.html.haml b/app/views/users/description/champs/_datetime.html.haml new file mode 100644 index 000000000..557704485 --- /dev/null +++ b/app/views/users/description/champs/_datetime.html.haml @@ -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 \ No newline at end of file diff --git a/app/views/users/description/champs/_textarea.html.haml b/app/views/users/description/champs/_textarea.html.haml new file mode 100644 index 000000000..4c062a300 --- /dev/null +++ b/app/views/users/description/champs/_textarea.html.haml @@ -0,0 +1,5 @@ +%textarea.form-control.wysihtml5{name:"champs['#{champ.id}']", + placeholder: champ.description, + id: "champs_#{champ.id}", + row: '6'} + =champ.value \ No newline at end of file diff --git a/db/migrate/20160622081321_convert_all_datetime_to_date_on_database.rb b/db/migrate/20160622081321_convert_all_datetime_to_date_on_database.rb new file mode 100644 index 000000000..7d6d09bd0 --- /dev/null +++ b/db/migrate/20160622081321_convert_all_datetime_to_date_on_database.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index c990bd982..630778df7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # 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 enable_extension "plpgsql" diff --git a/spec/controllers/users/description_controller_spec.rb b/spec/controllers/users/description_controller_spec.rb index 29c8028d8..bcf08bcbb 100644 --- a/spec/controllers/users/description_controller_spec.rb +++ b/spec/controllers/users/description_controller_spec.rb @@ -1,9 +1,9 @@ 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(: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_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.' } context 'Tous les attributs sont bons' do - # TODO separer en deux tests : check donnees et check redirect describe 'Premier enregistrement des données' do before do 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 end @@ -79,12 +78,13 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name: expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif") end + it { expect(dossier.nom_projet).to eq nom_projet } + it 'etat du dossier est soumis' do expect(dossier.state).to eq('initiated') end end - # TODO changer les valeurs des champs et check in bdd context 'En train de manipuler un dossier non brouillon' do before do dossier.initiated! @@ -119,7 +119,7 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name: end context 'Quand la procédure accepte les CERFA' do - context 'Sauvegarde du CERFA PDF', vcr: { cassette_name: 'controllers_users_description_controller_save_cerfa' } do + context 'Sauvegarde du CERFA PDF', vcr: {cassette_name: 'controllers_users_description_controller_save_cerfa'} do before do post :create, dossier_id: dossier_id, nom_projet: nom_projet, @@ -128,7 +128,7 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name: dossier.reload end - context 'when a CERFA PDF is sent', vcr: { cassette_name: 'controllers_users_description_controller_cerfa_is_sent' } do + context 'when a CERFA PDF is sent', vcr: {cassette_name: 'controllers_users_description_controller_cerfa_is_sent'} do subject { dossier.cerfa.first } it 'content' do @@ -180,13 +180,23 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name: describe 'Sauvegarde des champs' do let(:champs_dossier) { dossier.champs } 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 post :create, {dossier_id: dossier_id, nom_projet: nom_projet, description: description, 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 @@ -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(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 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 } 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(flash[:alert]).to be_present } @@ -210,7 +224,7 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name: end end - context 'Sauvegarde des pièces justificatives', vcr: { cassette_name: 'controllers_users_description_controller_sauvegarde_pj' } do + context 'Sauvegarde des pièces justificatives', vcr: {cassette_name: 'controllers_users_description_controller_sauvegarde_pj'} do let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids } before do post :create, {dossier_id: dossier_id, @@ -221,7 +235,7 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name: dossier.reload end - describe 'clamav anti-virus presence', vcr: { cassette_name: 'controllers_users_description_controller_clamav_presence' } do + describe 'clamav anti-virus presence', vcr: {cassette_name: 'controllers_users_description_controller_clamav_presence'} do it 'ClamavService safe_file? is call' do expect(ClamavService).to receive(:safe_file?).twice @@ -230,8 +244,6 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name: description: description, 'piece_justificative_'+all_pj_type[0].to_s => piece_justificative_0, 'piece_justificative_'+all_pj_type[1].to_s => piece_justificative_1} - - end end @@ -248,7 +260,7 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name: end end - describe 'POST #pieces_justificatives', vcr: { cassette_name: 'controllers_users_description_controller_pieces_justificatives' } do + describe 'POST #pieces_justificatives', vcr: {cassette_name: 'controllers_users_description_controller_pieces_justificatives'} do let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids } subject { patch :pieces_justificatives, {dossier_id: dossier.id, @@ -275,7 +287,7 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name: end end - context 'when PJ have already a document', vcr: { cassette_name: 'controllers_users_description_controller_pj_already_exist' } do + context 'when PJ have already a document', vcr: {cassette_name: 'controllers_users_description_controller_pj_already_exist'} do before do create :piece_justificative, :rib, dossier: dossier, type_de_piece_justificative_id: all_pj_type[0] create :piece_justificative, :contrat, dossier: dossier, type_de_piece_justificative_id: all_pj_type[1] @@ -283,7 +295,7 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name: it { expect(dossier.pieces_justificatives.size).to eq 2 } - context 'when upload two PJ', vcr: { cassette_name: 'controllers_users_description_controller_pj_already_exist_upload_2pj' } do + context 'when upload two PJ', vcr: {cassette_name: 'controllers_users_description_controller_pj_already_exist_upload_2pj'} do before do subject dossier.reload @@ -345,7 +357,7 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name: it { expect(dossier.pieces_justificatives.size).to eq 2 } - context 'when upload two PJ', vcr: { cassette_name: 'controllers_users_description_controller_upload_2pj' } do + context 'when upload two PJ', vcr: {cassette_name: 'controllers_users_description_controller_upload_2pj'} do before do subject dossier.reload diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index 2614d06e6..376180656 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -36,6 +36,14 @@ FactoryGirl.define do 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 after(:build) do |procedure, _evaluator| rib = create(:type_de_piece_justificative, :rib) diff --git a/spec/views/users/description/show.html.haml_spec.rb b/spec/views/users/description/show.html.haml_spec.rb index 04e256317..a6a283dc4 100644 --- a/spec/views/users/description/show.html.haml_spec.rb +++ b/spec/views/users/description/show.html.haml_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe 'users/description/show.html.haml', type: :view do let(:user) { create(:user) } 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_id) { dossier.id } @@ -82,8 +82,12 @@ describe 'users/description/show.html.haml', type: :view do context 'Champs' do 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 + champ_datetime.value = "22/06/2016 12:05" + champ_datetime.save render 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("#champs_#{subject.id}") } 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 context 'Pièces justificatives' do @@ -156,7 +166,7 @@ describe 'users/description/show.html.haml', type: :view do end context 'when procedure have cerfa flag true' do - let(:procedure) {create(:procedure, cerfa_flag: true)} + let(:procedure) { create(:procedure, cerfa_flag: true) } it { expect(rendered).to have_content 'Documents administratifs' } end