Merge branch 'develop' into staging

This commit is contained in:
Xavier J 2016-10-05 17:12:56 +02:00
commit c683307a61
12 changed files with 112 additions and 17 deletions

View file

@ -25,6 +25,9 @@ class Users::DescriptionController < UsersController
@procedure = @dossier.procedure @procedure = @dossier.procedure
@champs = @dossier.ordered_champs @champs = @dossier.ordered_champs
mandatory = true
mandatory = !(params[:submit].keys.first == 'brouillon') unless params[:submit].nil?
unless @dossier.update_attributes(create_params) unless @dossier.update_attributes(create_params)
@dossier = @dossier.decorate @dossier = @dossier.decorate
@ -43,10 +46,10 @@ class Users::DescriptionController < UsersController
end end
unless params[:champs].nil? unless params[:champs].nil?
champs_service_errors = ChampsService.save_formulaire @dossier.champs, params champs_service_errors = ChampsService.save_formulaire @dossier.champs, params, mandatory
unless champs_service_errors.empty? unless champs_service_errors.empty?
flash.now.alert = (champs_service_errors.inject('') {|acc, error| acc+= error[:message]+'<br>' }).html_safe flash.now.alert = (champs_service_errors.inject('') { |acc, error| acc+= error[:message]+'<br>' }).html_safe
return render 'show' return render 'show'
end end
end end
@ -56,12 +59,18 @@ class Users::DescriptionController < UsersController
return render 'show' return render 'show'
end end
if mandatory
if @dossier.draft? if @dossier.draft?
@dossier.initiated! @dossier.initiated!
end end
flash.notice = 'Félicitation, votre demande a bien été enregistrée.' flash.notice = 'Félicitation, votre demande a bien été enregistrée.'
redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: @dossier.id) redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: @dossier.id)
else
flash.notice = 'Votre brouillon a bien été sauvegardé.'
redirect_to url_for(controller: :dossiers, action: :index, liste: :brouillon)
end
end end
def pieces_justificatives def pieces_justificatives
@ -92,4 +101,5 @@ class Users::DescriptionController < UsersController
def create_params def create_params
params.permit() params.permit()
end end
end end

View file

@ -35,6 +35,10 @@ class DossiersListFacades
@list_table_columns ||= @current_devise_profil.preference_list_dossiers.where(procedure: @procedure).order(:id) @list_table_columns ||= @current_devise_profil.preference_list_dossiers.where(procedure: @procedure).order(:id)
end end
def brouillon_class
(@liste == 'brouillon' ? 'active' : '')
end
def nouveaux_class def nouveaux_class
(@liste == 'nouveaux' ? 'active' : '') (@liste == 'nouveaux' ? 'active' : '')
end end
@ -75,6 +79,10 @@ class DossiersListFacades
(@liste == 'invite' ? 'active' : '') (@liste == 'invite' ? 'active' : '')
end end
def brouillon_total
service.brouillon.count
end
def nouveaux_total def nouveaux_total
service.nouveaux.count service.nouveaux.count
end end
@ -117,6 +125,10 @@ class DossiersListFacades
service.invite.count service.invite.count
end end
def brouillon_url
base_url 'brouillon'
end
def nouveaux_url def nouveaux_url
base_url 'nouveaux' base_url 'nouveaux'
end end

View file

@ -43,6 +43,7 @@ class Dossier < ActiveRecord::Base
validates :user, presence: true validates :user, presence: true
BROUILLON = %w(draft)
NOUVEAUX = %w(initiated) NOUVEAUX = %w(initiated)
WAITING_FOR_GESTIONNAIRE = %w(updated) WAITING_FOR_GESTIONNAIRE = %w(updated)
WAITING_FOR_USER = %w(replied validated) WAITING_FOR_USER = %w(replied validated)
@ -164,6 +165,10 @@ class Dossier < ActiveRecord::Base
state state
end end
def brouillon?
BROUILLON.include?(state)
end
def nouveaux? def nouveaux?
NOUVEAUX.include?(state) NOUVEAUX.include?(state)
end end
@ -200,6 +205,10 @@ class Dossier < ActiveRecord::Base
TERMINE.include?(state) TERMINE.include?(state)
end end
def self.brouillon order = 'ASC'
where(state: BROUILLON, archived: false).order("updated_at #{order}")
end
def self.nouveaux order = 'ASC' def self.nouveaux order = 'ASC'
where(state: NOUVEAUX, archived: false).order("updated_at #{order}") where(state: NOUVEAUX, archived: false).order("updated_at #{order}")
end end

View file

@ -1,5 +1,5 @@
class ChampsService class ChampsService
def self.save_formulaire champs, params def self.save_formulaire champs, params, check_mandatory=true
errors = Array.new errors = Array.new
champs.each do |champ| champs.each do |champ|
@ -13,9 +13,11 @@ class ChampsService
params[:time_minute]["'#{champ.id}'"] params[:time_minute]["'#{champ.id}'"]
end end
if check_mandatory
if champ.mandatory? && (champ.value.nil? || champ.value.blank?) if champ.mandatory? && (champ.value.nil? || champ.value.blank?)
errors.push({message: "Le champ #{champ.libelle} doit être rempli."}) errors.push({message: "Le champ #{champ.libelle} doit être rempli."})
end end
end
champ.save champ.save
end end

View file

@ -5,7 +5,8 @@ class DossiersListUserService
end end
def dossiers_to_display def dossiers_to_display
{'nouveaux' => nouveaux, {'brouillon' => brouillon,
'nouveaux' => nouveaux,
'a_traiter' => waiting_for_user, 'a_traiter' => waiting_for_user,
'en_attente' => waiting_for_gestionnaire, 'en_attente' => waiting_for_gestionnaire,
'valides' => valides, 'valides' => valides,
@ -14,6 +15,10 @@ class DossiersListUserService
'invite' => invite}[@liste] 'invite' => invite}[@liste]
end end
def brouillon
@brouillon ||= @current_devise_profil.dossiers.brouillon
end
def nouveaux def nouveaux
@nouveaux ||= @current_devise_profil.dossiers.nouveaux @nouveaux ||= @current_devise_profil.dossiers.nouveaux
end end

View file

@ -56,7 +56,8 @@
-if !@dossier.draft? -if !@dossier.draft?
=render partial: '/layouts/modifications_terminees' =render partial: '/layouts/modifications_terminees'
-else -else
= submit_tag 'Soumettre mon dossier', id: 'suivant', class: %w(btn btn btn-success), style: 'float:right', data: { disable_with: 'Soumettre votre dossier', submit: true} = submit_tag 'Soumettre mon dossier', id: 'suivant', name: 'submit[nouveaux]', class: %w(btn btn btn-success), style: 'float:right', data: { disable_with: 'Soumettre votre dossier', submit: true}
= submit_tag 'Enregistrer un brouillon', id: 'brouillon', name: 'submit[brouillon]', class: %w(btn btn-xs btn-default), style: 'float:right; margin-right: 10px; margin-top: 6px', data: {disable_with: 'Enregistrer un brouillon', submit: true}
%br %br
%br %br

View file

@ -16,7 +16,10 @@
= dossier.id = dossier.id
%td %td
= link_to(dossier.procedure.libelle, users_dossiers_invite_path(id: invite.id)) unless invite.nil? = link_to(dossier.procedure.libelle, users_dossiers_invite_path(id: invite.id)) unless invite.nil?
= link_to(dossier.procedure.libelle, users_dossier_recapitulatif_path(dossier)) if invite.nil? - if invite.nil?
= link_to(dossier.procedure.libelle, users_dossier_recapitulatif_path(dossier)) unless dossier.brouillon?
= link_to(dossier.procedure.libelle, users_dossier_description_path(dossier)) if dossier.brouillon?
%td{id: "dossier_#{dossier.id}_state"}= dossier.display_state %td{id: "dossier_#{dossier.id}_state"}= dossier.display_state
%td= dossier.last_update %td= dossier.last_update

View file

@ -3,6 +3,13 @@
%br %br
#onglets #onglets
%ul.nav.nav-tabs %ul.nav.nav-tabs
%li{ class: @dossiers_list_facade.brouillon_class }
%a{:href => "#{url_for users_dossiers_path(liste: 'brouillon')}", 'data-toggle' => :tooltip, title: 'Les dossiers jamais proposés à la relecture.'}
%h5.text-default
= "Brouillons"
.badge.progress-bar-default
= @dossiers_list_facade.brouillon_total
%li{ class: @dossiers_list_facade.nouveaux_class } %li{ class: @dossiers_list_facade.nouveaux_class }
%a{:href => "#{url_for users_dossiers_path(liste: 'nouveaux')}", 'data-toggle' => :tooltip, title: 'Les nouveaux dossiers qui n\'ont pas encore été vus par votre accompagnateur.'} %a{:href => "#{url_for users_dossiers_path(liste: 'nouveaux')}", 'data-toggle' => :tooltip, title: 'Les nouveaux dossiers qui n\'ont pas encore été vus par votre accompagnateur.'}
%h5.text-info %h5.text-info

View file

@ -5,7 +5,12 @@
.col-md-1.col-lg-1 .col-md-1.col-lg-1
.fa.fa-info-circle.text-info{style:'font-size: 2em; margin-top: 20%'} .fa.fa-info-circle.text-info{style:'font-size: 2em; margin-top: 20%'}
.col-md-11.col-lg-11 .col-md-11.col-lg-11
-if dossiers_list_facade.liste == 'nouveaux' -if dossiers_list_facade.liste == 'brouillon'
Les dossiers présents dans cette liste
%b
n'ont pas encore été soumis à votre administrations.
Ils ne sont visible que par vous.
-elsif dossiers_list_facade.liste == 'nouveaux'
Les dossiers présents dans cette liste Les dossiers présents dans cette liste
%b %b
n'ont pas encore été ouverts n'ont pas encore été ouverts

View file

@ -0,0 +1,25 @@
class PurgeDraftDossier < ActiveRecord::Migration
class Dossier < ActiveRecord::Base
BROUILLON = %w(draft)
def brouillon?
BROUILLON.include?(state)
end
end
class Commentaire < ActiveRecord::Base
belongs_to :dossier
end
class Cerfa < ActiveRecord::Base
belongs_to :dossier
belongs_to :user
end
def change
Cerfa.all.each { |cerfa| cerfa.delete if cerfa.dossier.brouillon? }
Commentaire.all.each { |com| com.delete if com.dossier.brouillon? }
Dossier.where(state: :draft).destroy_all
end
end

View file

@ -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: 20161005082113) do ActiveRecord::Schema.define(version: 20161005144657) 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"

View file

@ -43,9 +43,13 @@ shared_examples 'description_controller_spec' do
context 'Tous les attributs sont bons' do context 'Tous les attributs sont bons' do
describe 'Premier enregistrement des données' do describe 'Premier enregistrement des données' do
let(:submit) { {nouveaux: 'nouveaux'} }
subject { post :create, dossier_id: dossier_id, submit: submit }
before do before do
dossier.draft! dossier.draft!
post :create, dossier_id: dossier_id subject
dossier.reload dossier.reload
end end
@ -56,6 +60,18 @@ shared_examples 'description_controller_spec' do
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
context 'when user whould like save just a draft' do
let(:submit) { {brouillon: 'brouillon'} }
it "redirection vers la page recapitulative" do
expect(response).to redirect_to("/users/dossiers?liste=brouillon")
end
it 'etat du dossier est soumis' do
expect(dossier.state).to eq('draft')
end
end
end end
context 'En train de manipuler un dossier non brouillon' do context 'En train de manipuler un dossier non brouillon' do