Add previsualization formulaire page for administrateur

This commit is contained in:
Xavier J 2016-06-06 17:40:32 +02:00
parent d26feb4c72
commit e6b5698008
11 changed files with 284 additions and 64 deletions

View file

@ -0,0 +1,13 @@
class Admin::PrevisualisationsController < AdminController
before_action :retrieve_procedure
def show
@procedure
@dossier = Dossier.new(id: 0, procedure: @procedure)
Champ.where(dossier_id: @dossier.id).destroy_all
@dossier.build_default_champs
@champs = @dossier.ordered_champs
end
end

View file

@ -0,0 +1,9 @@
%h2.text-info
=@procedure.libelle
%br
%ul.nav.nav-tabs
= render partial: 'admin/procedures/navbar', locals: {active: 'Prévisualisation'}
#previsualisation
=render 'users/description/show'

View file

@ -14,4 +14,7 @@
%li{ class: ('disabled' if @procedure.locked?) || ('active' if active == 'Pieces') } %li{ class: ('disabled' if @procedure.locked?) || ('active' if active == 'Pieces') }
= link_to_unless(@procedure.locked?, 'Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure)) do = link_to_unless(@procedure.locked?, 'Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure)) do
= link_to('Pièces justificatives', '#') = link_to('Pièces justificatives', '#')
%li{ class: ('active' if active == 'Prévisualisation'), style: 'float:right' }
= link_to('Prévisualisation', admin_procedure_previsualisation_path(@procedure), {style: 'font-style: italic;'})

View file

@ -4,3 +4,6 @@
= form_for @procedure, url: {controller: 'admin/procedures', action: :create}, multipart: true do |f| = form_for @procedure, url: {controller: 'admin/procedures', action: :create}, multipart: true do |f|
=render partial: 'informations', locals: {f: f} =render partial: 'informations', locals: {f: f}
=f.submit 'Valider', class: 'btn btn-info', style: 'float:right' =f.submit 'Valider', class: 'btn btn-info', style: 'float:right'
%br
%br
%br

View file

@ -6,21 +6,20 @@
%ul.nav.nav-tabs %ul.nav.nav-tabs
= render partial: 'navbar', locals: {active: 'Informations'} = render partial: 'navbar', locals: {active: 'Informations'}
%li{style:'float:right'} = form_tag admin_procedure_archive_path(procedure_id: @facade.procedure.id, archive: !@facade.procedure.archived?), method: :put, style:'float: right; margin-top: 10px' do
= form_tag admin_procedure_archive_path(procedure_id: @facade.procedure.id, archive: !@facade.procedure.archived?), method: :put do %button#archive.btn.btn-small.btn-default.text-info{type: :button}
%button#archive.btn.btn-nav.text-info{type: :button} %i.fa.fa-eraser
%i.fa.fa-eraser - if @facade.procedure.archived
- if @facade.procedure.archived = 'Réactiver'
= 'Réactiver' - else
- else = 'Archiver'
= 'Archiver' #confirm
#confirm %button#valid.btn.btn-small.btn-success{type: :submit}
%button#valid.btn.btn-nav.text-success{type: :submit} %i.fa.fa-check
%i.fa.fa-check Valider
Valider %button#cancel.btn.btn-small.btn-danger{type: :button}
%button#cancel.btn.btn-nav.text-danger{type: :button} %i.fa.fa-remove
%i.fa.fa-remove Annuler
Annuler
- if @facade.procedure.locked? - if @facade.procedure.locked?
#procedure_locked.center #procedure_locked.center

View file

@ -0,0 +1,50 @@
.container#description_page
%h2
= @dossier.procedure.libelle
%h3 Votre dossier
%br
-#TODO use form_for
= form_tag(url_for({controller: 'users/description', action: :create, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST', multipart: true) do
%div
.row
.col-md-12
%h4 Libellé pour votre dossier *
= text_field_tag :nom_projet, @dossier.nom_projet, placeholder: 'Nom du projet', class: 'form-control'
%br
.row
.col-md-12
%h4 Description *
= text_area_tag :description, @dossier.description, rows: '6', placeholder: 'Description du projet', class: 'form-control wysihtml5'
#liste_champs
-unless @champs.nil?
=render partial: 'users/description/champs'
-if !@procedure.lien_demarche.blank? || @procedure.cerfa_flag || @dossier.types_de_piece_justificative.size > 0
%br
%h3 Documents administratifs
-unless @procedure.lien_demarche.blank?
%p
Formulaire / documentation de la démarche :
%a{style:'font-size:0.9em; padding-left:3px', id: 'lien_cerfa' ,href: "#{@procedure.lien_demarche}", :target => '_blank'} Accéder
%br
//TODO a refactorer
= render partial: 'users/description/pieces_justificatives'
- if user_signed_in?
%div{style: 'text-align:right'}
%h6 Tous les champs portant un * sont obligatoires.
-if !@dossier.draft?
=render partial: '/layouts/modifications_terminees'
-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}
%br
%br

View file

@ -1,48 +1 @@
.container#description_page = render partial: 'show'
%h2
= @dossier.procedure.libelle
%h3 Votre dossier
%br
-#TODO use form_for
= form_tag(url_for({controller: :description, action: :create, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST', multipart: true) do
%div
.row
.col-md-12
%h4 Libellé pour votre dossier *
= text_field_tag :nom_projet, @dossier.nom_projet, placeholder: 'Nom du projet', class: 'form-control'
%br
.row
.col-md-12
%h4 Description *
= text_area_tag :description, @dossier.description, rows: '6', placeholder: 'Description du projet', class: 'form-control wysihtml5'
#liste_champs
-unless @champs.nil?
=render partial: 'champs'
-if !@procedure.lien_demarche.blank? || @procedure.cerfa_flag || @dossier.pieces_justificatives.size > 1
%br
%h3 Documents administratifs
-unless @procedure.lien_demarche.blank?
%p
Formulaire / documentation de la démarche :
%a{style:'font-size:0.9em; padding-left:3px', id: 'lien_cerfa' ,href: "#{@procedure.lien_demarche}", :target => '_blank'} Accéder
%br
//TODO a refactorer
= render partial: 'pieces_justificatives'
%div{style: 'text-align:right'}
%h6 Tous les champs portant un * sont obligatoires.
-if !@dossier.draft?
=render partial: '/layouts/modifications_terminees'
-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}
%br
%br

View file

@ -94,6 +94,7 @@ Rails.application.routes.draw do
resource :accompagnateurs, only: [:show, :update] resource :accompagnateurs, only: [:show, :update]
resource :previsualisation, only: [:show]
resources :types_de_champ, only: [:destroy] resources :types_de_champ, only: [:destroy]
resource :pieces_justificatives, only: [:show, :update] resource :pieces_justificatives, only: [:show, :update]

View file

@ -0,0 +1,16 @@
require 'spec_helper'
describe Admin::PrevisualisationsController, type: :controller do
let(:admin) { create(:administrateur) }
let(:procedure) { create :procedure, administrateur: admin }
before do
sign_in admin
end
describe 'GET #show' do
subject { get :show, procedure_id: procedure.id }
it { expect(subject.status).to eq(200) }
end
end

View file

@ -0,0 +1,172 @@
require 'spec_helper'
describe 'admin/previsualisations/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(:dossier) { create(:dossier, procedure: procedure, user: user) }
let(:dossier_id) { dossier.id }
before do
assign(:dossier, dossier)
assign(:procedure, dossier.procedure)
assign(:champs, dossier.ordered_champs)
end
context 'tous les attributs sont présents sur la page' do
before do
render
end
it 'Le formulaire envoie vers /users/dossiers/:dossier_id/description en #POST' do
expect(rendered).to have_selector("form[action='/users/dossiers/#{dossier_id}/description'][method=post]")
end
it 'Nom du projet' do
expect(rendered).to have_selector('input[id=nom_projet][name=nom_projet]')
end
it 'Description du projet' do
expect(rendered).to have_selector('textarea[id=description][name=description]')
end
it 'Charger votre CERFA (PDF)' do
expect(rendered).to have_selector('input[type=file][name=cerfa_pdf][id=cerfa_pdf]')
end
it 'Lien CERFA' do
expect(rendered).to have_selector('#lien_cerfa')
end
end
context 'si la page précédente n\'est pas recapitulatif' do
before do
render
end
it 'le bouton "Terminer" n\'est pas présent' do
expect(rendered).not_to have_selector('#suivant')
end
end
context 'si la page précédente est recapitularif' do
before do
dossier.initiated!
dossier.reload
render
end
it 'le bouton "Terminer" n\'est pas présent' do
expect(rendered).to_not have_selector('#suivant')
end
it 'le bouton "Modification terminé" n\'est pas présent' do
expect(rendered).not_to have_selector('#modification_terminee')
end
it 'le lien de retour au récapitulatif n\'est pas présent' do
expect(rendered).not_to have_selector("a[href='/users/dossiers/#{dossier_id}/recapitulatif']")
end
end
context 'les valeurs sont réaffichées si elles sont présentes dans la BDD' do
let!(:dossier) do
create(:dossier,
nom_projet: 'Projet de test',
description: 'Description de test',
user: user)
end
before do
render
end
it 'Nom du projet' do
expect(rendered).to have_selector("input[id=nom_projet][value='#{dossier.nom_projet}']")
end
it 'Description du projet' do
expect(rendered).to have_content("#{dossier.description}")
end
end
context 'Champs' do
let(:champs) { dossier.champs }
before do
render
end
describe 'first champs' do
subject { dossier.champs.first }
it { expect(rendered).to have_css(".type_champ-#{subject.type_champ}") }
it { expect(rendered).to have_css("#champs_#{subject.id}") }
end
describe 'last champs' do
subject { dossier.champs.last }
it { expect(rendered).to have_css(".type_champ-#{subject.type_champ}") }
it { expect(rendered).to have_css("#champs_#{subject.id}") }
end
end
context 'Pièces justificatives' do
let(:all_type_pj_procedure_id) { dossier.procedure.type_de_piece_justificative_ids }
before do
render
end
context 'la liste des pièces justificatives a envoyé est affichée' do
it 'RIB' do
expect(rendered).to have_css("#piece_justificative_#{all_type_pj_procedure_id[0]}")
end
end
context 'la liste des pièces récupérées automatiquement est signaliée' do
it 'Attestation MSA' do
expect(rendered).to have_selector("#piece_justificative_#{all_type_pj_procedure_id[1]}", "Nous l'avons récupéré pour vous.")
end
end
end
context 'Envoi des CERFA désactivé' do
let!(:cerfa_flag) { false }
before do
render
end
it { expect(rendered).to_not have_css("#cerfa_flag") }
it { expect(rendered).to_not have_selector('input[type=file][name=cerfa_pdf][id=cerfa_pdf]') }
end
describe 'display title Documents administratifs' do
before do
render
end
let(:procedure) { create :procedure, lien_demarche: '' }
let(:dossier) { create(:dossier, procedure: procedure) }
context 'when dossier not have cerfa, piece justificative and demarche link' do
it { expect(rendered).not_to have_content 'Documents administratifs' }
end
context 'when dossier have pj' do
let(:dossier) { create(:dossier) }
it { expect(rendered).to have_content 'Documents administratifs' }
end
context 'when procedure have demarche link' do
let(:procedure) { create :procedure }
it { expect(rendered).to have_content 'Documents administratifs' }
end
context 'when procedure have cerfa flag true' do
let(:procedure) {create(:procedure, cerfa_flag: true)}
it { expect(rendered).to have_content 'Documents administratifs' }
end
end
end

View file

@ -8,6 +8,7 @@ describe 'users/description/show.html.haml', type: :view do
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
before do before do
sign_in user
assign(:dossier, dossier) assign(:dossier, dossier)
assign(:procedure, dossier.procedure) assign(:procedure, dossier.procedure)
assign(:champs, dossier.ordered_champs) assign(:champs, dossier.ordered_champs)