Merge pull request #2401 from betagouv/dossier-form-tab

[Détails d'un dossier] Onglet "Formulaire"
This commit is contained in:
Paul Chavard 2018-08-14 13:39:06 +00:00 committed by GitHub
commit 1c87814d17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 154 additions and 53 deletions

View file

@ -30,4 +30,8 @@
font-weight: bold;
}
}
.button.edit-form {
float: right;
}
}

View file

@ -47,9 +47,9 @@
.status-explanation {
text-align: left;
&.brouillon,
&.en-construction,
&.en-instruction {
.brouillon,
.en-construction,
.en-instruction {
max-width: 600px;
margin: auto;
}

View file

@ -4,8 +4,8 @@ module NewUser
helper_method :new_demarche_url
before_action :ensure_ownership!, except: [:index, :show, :modifier, :update, :recherche]
before_action :ensure_ownership_or_invitation!, only: [:show, :modifier, :update]
before_action :ensure_ownership!, except: [:index, :show, :formulaire, :modifier, :update, :recherche]
before_action :ensure_ownership_or_invitation!, only: [:show, :formulaire, :modifier, :update]
before_action :ensure_dossier_can_be_updated, only: [:update_identite, :update]
before_action :forbid_invite_submission!, only: [:update]
@ -34,6 +34,10 @@ module NewUser
@dossier = dossier
end
def formulaire
@dossier = dossier
end
def attestation
send_data(dossier.attestation.pdf.read, filename: 'attestation.pdf', type: 'application/pdf')
end
@ -104,7 +108,11 @@ module NewUser
NotificationMailer.send_initiated_notification(@dossier).deliver_later
redirect_to merci_dossier_path(@dossier)
elsif current_user.owns?(dossier)
redirect_to users_dossier_recapitulatif_path(@dossier)
if Flipflop.new_dossier_details?
redirect_to formulaire_dossier_path(@dossier)
else
redirect_to users_dossier_recapitulatif_path(@dossier)
end
else
redirect_to users_dossiers_invite_path(@dossier.invite_for_user(current_user))
end

View file

@ -2,5 +2,5 @@
= render partial: 'header', locals: { avis: @avis, dossier: @dossier }
= render partial: 'new_gestionnaire/shared/show', locals: { dossier: @dossier, demande_seen_at: nil }
= render partial: 'shared/dossiers/show', locals: { dossier: @dossier, demande_seen_at: nil }

View file

@ -3,19 +3,19 @@
%h2 Identité du demandeur
= render partial: "new_gestionnaire/dossiers/user_infos", locals: { user: @dossier.user }
= render partial: "shared/dossiers/user_infos", locals: { user: @dossier.user }
- if @dossier.etablissement.present?
= render partial: "identite_entreprise", locals: { etablissement: @dossier.etablissement }
= render partial: "shared/dossiers/identite_entreprise", locals: { etablissement: @dossier.etablissement }
- if @dossier.individual.present?
= render partial: "identite_individual", locals: { individual: @dossier.individual }
= render partial: "shared/dossiers/identite_individual", locals: { individual: @dossier.individual }
%h2 Formulaire
- champs = @dossier.ordered_champs.decorate
- if champs.any?
= render partial: "champs", locals: { champs: champs, dossier: @dossier, demande_seen_at: nil }
= render partial: "shared/dossiers/champs", locals: { champs: champs, dossier: @dossier, demande_seen_at: nil }
- if @dossier.procedure.use_api_carto
%h3 Cartographie

View file

@ -2,4 +2,4 @@
= render partial: "header", locals: { dossier: @dossier }
= render partial: 'new_gestionnaire/shared/show', locals: { dossier: @dossier, demande_seen_at: @demande_seen_at }
= render partial: "shared/dossiers/show", locals: { dossier: @dossier, demande_seen_at: @demande_seen_at }

View file

@ -1,26 +0,0 @@
.container
.tab-title Identité du demandeur
.card
= render partial: "new_gestionnaire/dossiers/user_infos", locals: { user: dossier.user }
- if dossier.etablissement.present?
= render partial: "new_gestionnaire/dossiers/identite_entreprise", locals: { etablissement: dossier.etablissement }
- if dossier.individual.present?
= render partial: "new_gestionnaire/dossiers/identite_individual", locals: { individual: dossier.individual }
.tab-title Formulaire
- champs = dossier.ordered_champs.includes(:type_de_champ).decorate
- if champs.any?
.card
= render partial: "new_gestionnaire/dossiers/champs", locals: { champs: champs, demande_seen_at: demande_seen_at }
- if dossier.procedure.use_api_carto
.tab-title Cartographie
.card
= render partial: "new_gestionnaire/dossiers/map", locals: { dossier: dossier }
- if dossier.types_de_piece_justificative.any?
.tab-title Pièces jointes
.card
= render partial: "new_gestionnaire/dossiers/pieces_jointes", locals: { dossier: dossier, demande_seen_at: demande_seen_at }

View file

@ -0,0 +1,8 @@
#dossier-show
= render partial: 'new_user/dossiers/show/header', locals: { dossier: @dossier }
= render partial: 'shared/dossiers/show', locals: { dossier: @dossier, demande_seen_at: nil }
.container
- if !@dossier.read_only?
= link_to "Modifier le dossier", modifier_dossier_path(@dossier), class: 'button primary edit-form'

View file

@ -1,4 +1,5 @@
#dossier-show
= render partial: 'new_user/dossiers/show/header', locals: { dossier: @dossier }
= render partial: 'new_user/dossiers/show/resume', locals: { dossier: @dossier }
.container
= render partial: 'new_user/dossiers/show/status_progress', locals: { dossier: @dossier }

View file

@ -8,5 +8,7 @@
%h2 Dossier nº #{dossier.id}
%ul.tabs
%li.active
%li{ class: current_page?(dossier_path(dossier)) ? 'active' : nil }
= link_to "Résumé", dossier_path(dossier)
%li{ class: current_page?(formulaire_dossier_path(dossier)) ? 'active' : nil }
= link_to "Formulaire", formulaire_dossier_path(dossier)

View file

@ -1,2 +0,0 @@
.container
= render partial: 'new_user/dossiers/show/status_progress', locals: { dossier: dossier }

View file

@ -55,7 +55,7 @@
%td.rich-text
%span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) }
- if c.etablissement.present?
= render partial: "new_gestionnaire/dossiers/identite_entreprise", locals: { etablissement: c.etablissement }
= render partial: "shared/dossiers/identite_entreprise", locals: { etablissement: c.etablissement }
- else
%th.libelle
= "#{c.libelle} :"

View file

@ -0,0 +1,26 @@
.container
.tab-title Identité du demandeur
.card
= render partial: "shared/dossiers/user_infos", locals: { user: dossier.user }
- if dossier.etablissement.present?
= render partial: "shared/dossiers/identite_entreprise", locals: { etablissement: dossier.etablissement }
- if dossier.individual.present?
= render partial: "shared/dossiers/identite_individual", locals: { individual: dossier.individual }
.tab-title Formulaire
- champs = dossier.ordered_champs.includes(:type_de_champ).decorate
- if champs.any?
.card
= render partial: "shared/dossiers/champs", locals: { champs: champs, demande_seen_at: demande_seen_at }
- if dossier.procedure.use_api_carto
.tab-title Cartographie
.card
= render partial: "shared/dossiers/map", locals: { dossier: dossier }
- if dossier.types_de_piece_justificative.any?
.tab-title Pièces jointes
.card
= render partial: "shared/dossiers/pieces_jointes", locals: { dossier: dossier, demande_seen_at: demande_seen_at }

View file

@ -274,6 +274,7 @@ Rails.application.routes.draw do
get 'modifier'
patch 'modifier', to: 'dossiers#update'
get 'merci'
get 'formulaire'
post 'ask_deletion'
get 'attestation'
end

View file

@ -509,6 +509,20 @@ describe NewUser::DossiersController, type: :controller do
end
end
describe '#formulaire' do
let(:dossier) { create(:dossier, :en_construction, user: user) }
before do
Flipflop::FeatureSet.current.test!.switch!(:new_dossier_details, true)
sign_in(user)
end
subject! { get(:formulaire, params: { id: dossier.id }) }
it { expect(assigns(:dossier)).to eq(dossier) }
it { is_expected.to render_template(:formulaire) }
end
describe '#ask_deletion' do
before { sign_in(user) }

View file

@ -1,6 +1,10 @@
describe 'Dossier details:' do
let(:user) { create(:user) }
let(:dossier) { create(:dossier, :en_construction, user: user) }
let(:simple_procedure) do
tdcs = [create(:type_de_champ, libelle: 'texte obligatoire')]
create(:procedure, :published, :for_individual, types_de_champ: tdcs)
end
let(:dossier) { create(:dossier, :en_construction, :for_individual, user: user, procedure: simple_procedure) }
before do
Flipflop::FeatureSet.current.test!.switch!(:new_dossier_details, true)
@ -14,6 +18,21 @@ describe 'Dossier details:' do
expect(page).to have_selector('.status-explanation')
end
scenario 'the user can see and edit dossier before instruction' do
visit_dossier dossier
click_on 'Formulaire'
expect(page).to have_current_path(formulaire_dossier_path(dossier))
click_on 'Modifier le dossier'
expect(page).to have_current_path(modifier_dossier_path(dossier))
fill_in('texte obligatoire', with: 'Nouveau texte')
click_on 'Enregistrer les modifications du dossier'
expect(page).to have_current_path(formulaire_dossier_path(dossier))
expect(page).to have_content('Nouveau texte')
end
private
def visit_dossier(dossier)

View file

@ -0,0 +1,31 @@
require 'spec_helper'
describe 'new_user/dossiers/formulaire.html.haml', type: :view do
let(:procedure) { create(:procedure, :published, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_type_de_champ_private) }
let(:dossier) { create(:dossier, :en_construction, :with_entreprise, procedure: procedure) }
before do
assign(:dossier, dossier)
end
subject! { render }
it 'renders the header' do
expect(rendered).to have_text("Dossier nº #{dossier.id}")
end
it 'renders the dossier infos' do
expect(rendered).to have_text('Identité')
expect(rendered).to have_text('Formulaire')
expect(rendered).to have_text('Pièces jointes')
end
context 'when the dossier is editable' do
it { is_expected.to have_link('Modifier le dossier', href: modifier_dossier_path(dossier)) }
end
context 'when the dossier is read-only' do
let(:dossier) { create(:dossier, :en_instruction, :with_entreprise, procedure: procedure) }
it { is_expected.not_to have_link('Modifier le dossier') }
end
end

View file

@ -1,7 +1,7 @@
require 'spec_helper'
describe 'new_user/dossiers/show.html.haml', type: :view do
let(:dossier) { create(:dossier, :with_service, state: 'brouillon', procedure: create(:procedure)) }
let(:dossier) { create(:dossier, :en_construction, procedure: create(:procedure)) }
before do
sign_in dossier.user
@ -10,8 +10,8 @@ describe 'new_user/dossiers/show.html.haml', type: :view do
subject! { render }
it 'affiche les informations du dossier' do
expect(rendered).to have_text(dossier.procedure.libelle)
it 'renders a summary of the dossier state' do
expect(rendered).to have_text("Dossier nº #{dossier.id}")
expect(rendered).to have_selector('.status-progress')
end
end

View file

@ -0,0 +1,15 @@
describe 'new_user/dossiers/show/header.html.haml', type: :view do
let(:dossier) { create(:dossier, :en_construction, procedure: create(:procedure)) }
subject! { render 'new_user/dossiers/show/header.html.haml', dossier: dossier }
it 'affiche les informations du dossier' do
expect(rendered).to have_text(dossier.procedure.libelle)
expect(rendered).to have_text("Dossier nº #{dossier.id}")
expect(rendered).to have_text("en construction")
expect(rendered).to have_selector("ul.tabs")
expect(rendered).to have_link("Résumé", href: dossier_path(dossier))
expect(rendered).to have_link("Formulaire", href: formulaire_dossier_path(dossier))
end
end

View file

@ -1,4 +1,4 @@
describe 'new_gestionnaire/dossiers/champs.html.haml', type: :view do
describe 'shared/dossiers/champs.html.haml', type: :view do
let(:gestionnaire) { create(:gestionnaire) }
let(:demande_seen_at) { nil }
@ -8,7 +8,7 @@ describe 'new_gestionnaire/dossiers/champs.html.haml', type: :view do
allow(view).to receive(:current_gestionnaire).and_return(gestionnaire)
end
subject { render 'new_gestionnaire/dossiers/champs.html.haml', champs: champs, demande_seen_at: demande_seen_at }
subject { render 'shared/dossiers/champs.html.haml', champs: champs, demande_seen_at: demande_seen_at }
context "there are some champs" do
let(:dossier) { create(:dossier) }

View file

@ -1,5 +1,5 @@
describe 'new_gestionnaire/dossiers/identite_entreprise.html.haml', type: :view do
before { render 'new_gestionnaire/dossiers/identite_entreprise.html.haml', etablissement: etablissement }
describe 'shared/dossiers/identite_entreprise.html.haml', type: :view do
before { render 'shared/dossiers/identite_entreprise.html.haml', etablissement: etablissement }
context "there is an association" do
let(:etablissement) { create(:etablissement, :is_association) }

View file

@ -1,8 +1,8 @@
require 'spec_helper'
describe 'new_gestionnaire/dossiers/_map.html.haml', type: :view do
describe 'shared/dossiers/map.html.haml', type: :view do
subject do
render(partial: 'new_gestionnaire/dossiers/map.html.haml', locals: { dossier: dossier })
render(partial: 'shared/dossiers/map.html.haml', locals: { dossier: dossier })
end
describe "javascript variables printing" do