chore(patron): build real demarche and dossier for page patron

This commit is contained in:
Paul Chavard 2024-04-23 17:30:13 +02:00
parent 6c70a3db28
commit ea42dec5a4
2 changed files with 43 additions and 60 deletions

View file

@ -1,4 +1,5 @@
class RootController < ApplicationController class RootController < ApplicationController
before_action :authenticate_administrateur!, only: :patron
include ApplicationHelper include ApplicationHelper
def index def index
@ -25,72 +26,51 @@ class RootController < ApplicationController
def patron def patron
description = "Allez voir le super site : #{Current.application_base_url}" description = "Allez voir le super site : #{Current.application_base_url}"
all_champs = TypeDeChamp.type_champs procedure = Procedure.create_with(for_individual: true,
.map.with_index { |(name, _), i| TypeDeChamp.new(type_champ: name, private: false, libelle: name.humanize, description:, mandatory: true, stable_id: i) } administrateurs: [current_administrateur],
.map.with_index { |type_de_champ, i| type_de_champ.champ.build(id: i) } duree_conservation_dossiers_dans_ds: 1,
max_duree_conservation_dossiers_dans_ds: Expired::DEFAULT_DOSSIER_RENTENTION_IN_MONTH,
cadre_juridique: 'http://www.legifrance.gouv.fr',
description:).find_or_initialize_by(libelle: 'Démarche de demo pour la page patron')
all_champs if procedure.new_record?
.filter { |champ| champ.type_champ == TypeDeChamp.type_champs.fetch(:header_section) } Procedure.transaction do
.each { |champ| champ.type_de_champ.libelle = 'Un super titre de section' } procedure.draft_revision = procedure.revisions.build
procedure.save!
after_stable_id = nil
TypeDeChamp.type_champs.values.sort.each do |type_champ|
type_de_champ = procedure.draft_revision
.add_type_de_champ(type_champ:, libelle: type_champ.humanize, description:, mandatory: true, private: false, after_stable_id:)
after_stable_id = type_de_champ.stable_id
all_champs if type_de_champ.repetition?
.filter { |champ| champ.type_de_champ.drop_down_list? } repetition_after_stable_id = nil
.each do |champ| ['text', 'integer_number', 'checkbox'].each do |type_champ|
if champ.type_de_champ.linked_drop_down_list? repetition_type_de_champ = procedure.draft_revision
champ.type_de_champ.drop_down_list_value = .add_type_de_champ(type_champ:, libelle: type_champ.humanize, description:, mandatory: true, private: false, parent_stable_id: type_de_champ.stable_id, after_stable_id: repetition_after_stable_id)
"-- section 1 -- repetition_after_stable_id = repetition_type_de_champ.stable_id
option A end
option B elsif type_de_champ.linked_drop_down_list?
-- section 2 -- type_de_champ.drop_down_list_value =
option C" "-- section 1 --
else option A
champ.type_de_champ.drop_down_list_value = option B
"option A -- section 2 --
option B option C"
-- avant l'option C -- type_de_champ.save
option C" elsif type_de_champ.drop_down_list?
champ.value = '["option B", "option C"]' type_de_champ.drop_down_list_value =
champ.type_de_champ.drop_down_other = "1" "option A
option B
-- avant l'option C --
option C"
type_de_champ.save
end
end end
end end
all_champs
.filter { |champ| champ.type_champ == TypeDeChamp.type_champs.fetch(:repetition) }
.each do |champ_repetition|
libelles = ['Prénom', 'Nom'];
champ_repetition.champs << libelles.map.with_index do |libelle, i|
text_tdc = TypeDeChamp.new(type_champ: :text, private: false, libelle: libelle, description: description, mandatory: true)
text_tdc.champ.build(id: all_champs.length + i)
end
end
type_champ_values = {
TypeDeChamp.type_champs.fetch(:date) => '2016-07-26',
TypeDeChamp.type_champs.fetch(:datetime) => '26/07/2016 07:35',
TypeDeChamp.type_champs.fetch(:textarea) => 'Une description de mon projet'
}
type_champ_values.each do |(type_champ, value)|
all_champs
.filter { |champ| champ.type_champ == type_champ }
.each { |champ| champ.value = value }
end end
@dossier = Dossier.new(champs: all_champs) @dossier = procedure.draft_revision.dossier_for_preview(current_user)
@dossier.association(:procedure).target = Procedure.new
all_champs.each do |champ|
champ.association(:dossier).target = @dossier
champ.champs.each do |champ|
champ.association(:dossier).target = @dossier
end
end
draft_revision = @dossier.procedure.build_draft_revision(types_de_champ: all_champs.map(&:type_de_champ))
@dossier.association(:revision).target = draft_revision
@dossier.champs_public.map(&:type_de_champ).map do |tdc|
tdc.association(:revision_type_de_champ).target = tdc.build_revision_type_de_champ(revision: draft_revision)
tdc.association(:revision).target = draft_revision
end
end end
def suivi def suivi

View file

@ -1,4 +1,7 @@
describe 'Accessing the /patron page:' do describe 'Accessing the /patron page:' do
let(:administrateur) { create(:administrateur) }
before { sign_in administrateur.user }
scenario 'I can display a page with all form fields and UI elements' do scenario 'I can display a page with all form fields and UI elements' do
visit patron_path visit patron_path
expect(page).to have_text('Icônes') expect(page).to have_text('Icônes')