Merge pull request #1844 from betagouv/fix_1824_link_to_preview
Fix 1824 link to preview
This commit is contained in:
commit
fe0aafdd44
12 changed files with 191 additions and 64 deletions
|
@ -0,0 +1,7 @@
|
|||
module NewAdministrateur
|
||||
class AdministrateurController < ApplicationController
|
||||
layout 'new_application'
|
||||
|
||||
before_action :authenticate_administrateur!
|
||||
end
|
||||
end
|
18
app/controllers/new_administrateur/procedures_controller.rb
Normal file
18
app/controllers/new_administrateur/procedures_controller.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
module NewAdministrateur
|
||||
class ProceduresController < AdministrateurController
|
||||
def apercu
|
||||
@dossier = procedure_without_control.new_dossier
|
||||
@tab = apercu_tab
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def apercu_tab
|
||||
params[:tab] || 'dossier'
|
||||
end
|
||||
|
||||
def procedure_without_control
|
||||
Procedure.find(params[:id])
|
||||
end
|
||||
end
|
||||
end
|
|
@ -47,6 +47,20 @@ class Procedure < ApplicationRecord
|
|||
validates :description, presence: true, allow_blank: false, allow_nil: false
|
||||
validates :organisation, presence: true, allow_blank: false, allow_nil: false
|
||||
|
||||
# Warning: dossier after_save build_default_champs must be removed
|
||||
# to save a dossier created from this method
|
||||
def new_dossier
|
||||
champs = types_de_champ
|
||||
.ordered
|
||||
.map { |tdc| tdc.champ.build }
|
||||
|
||||
champs_private = types_de_champ_private
|
||||
.ordered
|
||||
.map { |tdc| tdc.champ.build }
|
||||
|
||||
Dossier.new(procedure: self, champs: champs, champs_private: champs_private)
|
||||
end
|
||||
|
||||
def hide!
|
||||
now = DateTime.now
|
||||
self.update(hidden_at: now)
|
||||
|
|
|
@ -28,6 +28,7 @@ class TypeDeChamp < ApplicationRecord
|
|||
|
||||
scope :public_only, -> { where(private: false) }
|
||||
scope :private_only, -> { where(private: true) }
|
||||
scope :ordered, -> { order(order_place: :asc) }
|
||||
|
||||
has_many :champ, inverse_of: :type_de_champ, dependent: :destroy do
|
||||
def build(params = {})
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
= procedure.libelle
|
||||
%td{ style: 'padding-right: 10px; padding-left: 10px; width: 60px;' }
|
||||
- if !procedure.archivee?
|
||||
= link_to('Consulter', commencer_path(procedure_path: procedure.path), target: "_blank")
|
||||
= link_to('Consulter', apercu_procedure_path(id: procedure.id), target: "_blank")
|
||||
%td
|
||||
= link_to('Cloner', admin_procedure_clone_path(procedure.id, from_new_from_existing: true), 'data-method' => :put, class: 'btn-sm btn-primary clone-btn')
|
||||
%td{ style: 'padding-left: 10px;' }
|
||||
|
|
22
app/views/new_administrateur/procedures/apercu.html.haml
Normal file
22
app/views/new_administrateur/procedures/apercu.html.haml
Normal file
|
@ -0,0 +1,22 @@
|
|||
.dossiers-headers.accompagnateur-header
|
||||
.container
|
||||
%h1.page-title Prévisualisation de la procédure #{@dossier.procedure.libelle}
|
||||
|
||||
%ul.tabs
|
||||
%li{ class: (@tab == 'dossier') ? 'active' : nil }>
|
||||
= link_to(apercu_procedure_path(@dossier.procedure, tab: 'dossier')) do
|
||||
le dossier
|
||||
- if @dossier.champs_private.size > 0
|
||||
%li{ class: (@tab == 'annotations-privees') ? 'active' : nil }>
|
||||
= link_to(apercu_procedure_path(@dossier.procedure, tab: 'annotations-privees')) do
|
||||
les annotations privees
|
||||
|
||||
- if @tab == 'dossier'
|
||||
= render partial: "shared/dossiers/edit", locals: { dossier: @dossier, apercu: true }
|
||||
- else
|
||||
.container
|
||||
= form_for @dossier, url: '', method: :get, html: { class: 'form' } do |f|
|
||||
= f.fields_for :champs_private, @dossier.champs_private do |champ_form|
|
||||
- champ = champ_form.object
|
||||
= render partial: "shared/dossiers/editable_champs/editable_champ",
|
||||
locals: { champ: champ, form: champ_form }
|
|
@ -3,66 +3,4 @@
|
|||
.container
|
||||
%h1= @dossier.procedure.libelle
|
||||
|
||||
.container
|
||||
- if notice_url(@dossier.procedure).present?
|
||||
%p
|
||||
Pour vous aider à remplir votre dossier, vous pouvez consulter
|
||||
= link_to 'le guide de cette démarche', notice_url(@dossier.procedure), { target: '_blank' }
|
||||
|
||||
%p.thanks Les champs avec une asterisque (*) sont obligatoires.
|
||||
|
||||
= form_for @dossier, html: { class: 'form', multipart: true } do |f|
|
||||
= f.fields_for :champs, @dossier.champs do |champ_form|
|
||||
- champ = champ_form.object
|
||||
= render partial: "shared/dossiers/editable_champs/editable_champ",
|
||||
locals: { champ: champ, form: champ_form }
|
||||
|
||||
- tpjs = @dossier.types_de_piece_justificative.order('order_place ASC')
|
||||
- if tpjs.present?
|
||||
.card.featured
|
||||
.card-title
|
||||
Pièces-jointes
|
||||
|
||||
- tpjs.each do |tpj|
|
||||
.pj-input
|
||||
%label{ for: "piece_justificative_#{tpj.id}" }
|
||||
= tpj.libelle
|
||||
- if tpj.mandatory?
|
||||
%span.mandatory *
|
||||
|
||||
%p.piece-description= tpj.description
|
||||
|
||||
- if tpj.lien_demarche.present?
|
||||
%p.piece-description
|
||||
Récupérer le formulaire vierge pour mon dossier :
|
||||
= link_to "Télécharger", tpj.lien_demarche, target: :blank
|
||||
|
||||
- if @dossier.was_piece_justificative_uploaded_for_type_id?(tpj.id)
|
||||
- pj = @dossier.retrieve_last_piece_justificative_by_type(tpj.id)
|
||||
%p
|
||||
Pièce-jointe déjà importée :
|
||||
= link_to pj.original_filename, pj.content_url, target: :blank
|
||||
|
||||
= file_field_tag "piece_justificative_#{tpj.id}",
|
||||
accept: PieceJustificative.accept_format,
|
||||
max_file_size: 6.megabytes,
|
||||
required: (tpj.mandatory? && !@dossier.was_piece_justificative_uploaded_for_type_id?(tpj.id))
|
||||
|
||||
.send-wrapper
|
||||
= hidden_field_tag 'submit_action', 'draft'
|
||||
|
||||
- if @dossier.brouillon?
|
||||
= f.button 'Enregistrer le brouillon',
|
||||
formnovalidate: true,
|
||||
class: 'button send',
|
||||
data: { action: 'draft', disable_with: 'Envoi...' }
|
||||
|
||||
- if @dossier.user == current_user
|
||||
= f.button 'Soumettre le dossier',
|
||||
class: 'button send primary',
|
||||
data: { action: 'submit', disable_with: 'Envoi...' }
|
||||
|
||||
- else
|
||||
= f.button 'Modifier le dossier',
|
||||
class: 'button send primary',
|
||||
data: { action: 'submit', disable_with: 'Envoi...' }
|
||||
= render partial: "shared/dossiers/edit", locals: { dossier: @dossier, apercu: false }
|
||||
|
|
69
app/views/shared/dossiers/_edit.html.haml
Normal file
69
app/views/shared/dossiers/_edit.html.haml
Normal file
|
@ -0,0 +1,69 @@
|
|||
.container
|
||||
- if notice_url(dossier.procedure).present?
|
||||
%p
|
||||
Pour vous aider à remplir votre dossier, vous pouvez consulter
|
||||
= link_to 'le guide de cette démarche', notice_url(dossier.procedure), { target: '_blank' }
|
||||
|
||||
%p.thanks Les champs avec une asterisque (*) sont obligatoires.
|
||||
|
||||
- if apercu
|
||||
- form_options = { url: '', method: :get, html: { class: 'form', multipart: true } }
|
||||
- else
|
||||
- form_options = { html: { class: 'form', multipart: true } }
|
||||
|
||||
= form_for dossier, form_options do |f|
|
||||
= f.fields_for :champs, dossier.champs do |champ_form|
|
||||
- champ = champ_form.object
|
||||
= render partial: "shared/dossiers/editable_champs/editable_champ",
|
||||
locals: { champ: champ, form: champ_form }
|
||||
|
||||
- tpjs = dossier.types_de_piece_justificative.order('order_place ASC')
|
||||
- if tpjs.present?
|
||||
.card.featured
|
||||
.card-title
|
||||
Pièces-jointes
|
||||
|
||||
- tpjs.each do |tpj|
|
||||
.pj-input
|
||||
%label{ for: "piece_justificative_#{tpj.id}" }
|
||||
= tpj.libelle
|
||||
- if tpj.mandatory?
|
||||
%span.mandatory *
|
||||
|
||||
%p.piece-description= tpj.description
|
||||
|
||||
- if tpj.lien_demarche.present?
|
||||
%p.piece-description
|
||||
Récupérer le formulaire vierge pour mon dossier :
|
||||
= link_to "Télécharger", tpj.lien_demarche, target: :blank
|
||||
|
||||
- if dossier.was_piece_justificative_uploaded_for_type_id?(tpj.id)
|
||||
- pj = dossier.retrieve_last_piece_justificative_by_type(tpj.id)
|
||||
%p
|
||||
Pièce-jointe déjà importée :
|
||||
= link_to pj.original_filename, pj.content_url, target: :blank
|
||||
|
||||
= file_field_tag "piece_justificative_#{tpj.id}",
|
||||
accept: PieceJustificative.accept_format,
|
||||
max_file_size: 6.megabytes,
|
||||
required: (tpj.mandatory? && !dossier.was_piece_justificative_uploaded_for_type_id?(tpj.id))
|
||||
|
||||
- if !apercu
|
||||
.send-wrapper
|
||||
= hidden_field_tag 'submit_action', 'draft'
|
||||
|
||||
- if dossier.brouillon?
|
||||
= f.button 'Enregistrer le brouillon',
|
||||
formnovalidate: true,
|
||||
class: 'button send',
|
||||
data: { action: 'draft', disable_with: 'Envoi...' }
|
||||
|
||||
- if dossier.user == current_user
|
||||
= f.button 'Soumettre le dossier',
|
||||
class: 'button send primary',
|
||||
data: { action: 'submit', disable_with: 'Envoi...' }
|
||||
|
||||
- else
|
||||
= f.button 'Modifier le dossier',
|
||||
class: 'button send primary',
|
||||
data: { action: 'submit', disable_with: 'Envoi...' }
|
|
@ -274,6 +274,14 @@ Rails.application.routes.draw do
|
|||
get "recherche" => "recherche#index"
|
||||
end
|
||||
|
||||
scope module: 'new_administrateur' do
|
||||
resources :procedures, only: [] do
|
||||
member do
|
||||
get 'apercu'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
apipie
|
||||
|
||||
# Legacy routes
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
describe NewAdministrateur::AdministrateurController, type: :controller do
|
||||
describe 'before actions: authenticate_administrateur!' do
|
||||
it 'is present' do
|
||||
before_actions = NewAdministrateur::AdministrateurController
|
||||
._process_action_callbacks
|
||||
.find_all{ |process_action_callbacks| process_action_callbacks.kind == :before }
|
||||
.map(&:filter)
|
||||
|
||||
expect(before_actions).to include(:authenticate_administrateur!)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
describe NewAdministrateur::ProceduresController, type: :controller do
|
||||
let(:admin) { create(:administrateur) }
|
||||
|
||||
describe '#apercu' do
|
||||
let(:procedure) { create(:procedure) }
|
||||
|
||||
before do
|
||||
sign_in admin
|
||||
get :apercu, params: { id: procedure.id }
|
||||
end
|
||||
|
||||
it { expect(response).to have_http_status(:ok) }
|
||||
end
|
||||
end
|
|
@ -636,4 +636,28 @@ describe Procedure do
|
|||
it { is_expected.to eq("dossiers_procedure-#{procedure.id}_2018-01-02_23-11") }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#new_dossier' do
|
||||
let(:procedure) do
|
||||
procedure = create(:procedure)
|
||||
|
||||
create(:type_de_champ_text, procedure: procedure, order_place: 1)
|
||||
create(:type_de_champ_number, procedure: procedure, order_place: 2)
|
||||
create(:type_de_champ_textarea, :private, procedure: procedure)
|
||||
|
||||
procedure
|
||||
end
|
||||
|
||||
let(:dossier) { procedure.new_dossier }
|
||||
|
||||
it { expect(dossier.procedure).to eq(procedure) }
|
||||
|
||||
it { expect(dossier.champs.size).to eq(2) }
|
||||
it { expect(dossier.champs[0].type).to eq("Champs::TextChamp") }
|
||||
|
||||
it { expect(dossier.champs_private.size).to eq(1) }
|
||||
it { expect(dossier.champs_private[0].type).to eq("Champs::TextareaChamp") }
|
||||
|
||||
it { expect(Champ.count).to eq(0) }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue