diff --git a/app/components/types_de_champ_editor/add_champ_button_component.rb b/app/components/types_de_champ_editor/add_champ_button_component.rb index b162ecbdd..ad23aaf41 100644 --- a/app/components/types_de_champ_editor/add_champ_button_component.rb +++ b/app/components/types_de_champ_editor/add_champ_button_component.rb @@ -33,8 +33,8 @@ class TypesDeChampEditor::AddChampButtonComponent < ApplicationComponent libelle: champ_libelle, type_champ: TypeDeChamp.type_champs.fetch(:text), private: annotations? ? true : nil, - parent_id: @parent&.stable_id, - after_id: '' + parent_stable_id: @parent&.stable_id, + after_stable_id: '' }.compact } } diff --git a/app/components/types_de_champ_editor/champ_component.rb b/app/components/types_de_champ_editor/champ_component.rb index 1c23a50dd..6cd02e2ee 100644 --- a/app/components/types_de_champ_editor/champ_component.rb +++ b/app/components/types_de_champ_editor/champ_component.rb @@ -28,14 +28,14 @@ class TypesDeChampEditor::ChampComponent < ApplicationComponent type_de_champ_editor_move_url_value: move_admin_procedure_type_de_champ_path(procedure, type_de_champ.stable_id), type_de_champ_editor_move_up_url_value: move_up_admin_procedure_type_de_champ_path(procedure, type_de_champ.stable_id), type_de_champ_editor_move_down_url_value: move_down_admin_procedure_type_de_champ_path(procedure, type_de_champ.stable_id), - type_de_champ_editor_type_de_champ_id_value: coordinate.stable_id + type_de_champ_editor_type_de_champ_stable_id_value: type_de_champ.stable_id } } end def form_options { - url: type_de_champ_path, + url: admin_procedure_type_de_champ_path(procedure, type_de_champ.stable_id), multipart: true, html: { id: nil, class: 'form width-100' } } diff --git a/app/controllers/administrateurs/types_de_champ_controller.rb b/app/controllers/administrateurs/types_de_champ_controller.rb index 1b982c871..1f56605a9 100644 --- a/app/controllers/administrateurs/types_de_champ_controller.rb +++ b/app/controllers/administrateurs/types_de_champ_controller.rb @@ -16,7 +16,7 @@ module Administrateurs end def update - type_de_champ = @procedure.draft_revision.find_and_ensure_exclusive_use(params[:id]) + type_de_champ = @procedure.draft_revision.find_and_ensure_exclusive_use(params[:stable_id]) if type_de_champ.update(type_de_champ_update_params) if params[:should_render] @@ -31,21 +31,21 @@ module Administrateurs def move flash.notice = "Formulaire enregistré" - @procedure.draft_revision.move_type_de_champ(params[:id], params[:position].to_i) + @procedure.draft_revision.move_type_de_champ(params[:stable_id], params[:position].to_i) end def move_up flash.notice = "Formulaire enregistré" - @coordinate = @procedure.draft_revision.move_up_type_de_champ(params[:id]) + @coordinate = @procedure.draft_revision.move_up_type_de_champ(params[:stable_id]) end def move_down flash.notice = "Formulaire enregistré" - @coordinate = @procedure.draft_revision.move_down_type_de_champ(params[:id]) + @coordinate = @procedure.draft_revision.move_down_type_de_champ(params[:stable_id]) end def destroy - @coordinate = @procedure.draft_revision.remove_type_de_champ(params[:id]) + @coordinate = @procedure.draft_revision.remove_type_de_champ(params[:stable_id]) reset_procedure flash.notice = "Formulaire enregistré" end @@ -55,7 +55,7 @@ module Administrateurs def type_de_champ_create_params params .required(:type_de_champ) - .permit(:type_champ, :parent_id, :private, :libelle, :after_id) + .permit(:type_champ, :parent_stable_id, :private, :libelle, :after_stable_id) end def type_de_champ_update_params diff --git a/app/javascript/controllers/type_de_champ_editor_controller.ts b/app/javascript/controllers/type_de_champ_editor_controller.ts index e9e472533..dd821ae19 100644 --- a/app/javascript/controllers/type_de_champ_editor_controller.ts +++ b/app/javascript/controllers/type_de_champ_editor_controller.ts @@ -7,7 +7,7 @@ import { ApplicationController } from './application_controller'; export class TypeDeChampEditorController extends ApplicationController { static values = { - typeDeChampId: String, + typeDeChampStableId: String, moveUrl: String, moveUpUrl: String, moveDownUrl: String @@ -16,7 +16,7 @@ export class TypeDeChampEditorController extends ApplicationController { declare readonly moveUrlValue: string; declare readonly moveUpUrlValue: string; declare readonly moveDownUrlValue: string; - declare readonly typeDeChampIdValue: string; + declare readonly typeDeChampStableIdValue: string; declare readonly isVisible: boolean; #latestPromise = Promise.resolve(); @@ -139,16 +139,17 @@ export class TypeDeChampEditorController extends ApplicationController { ? '.add-to-block' : '.add-to-root'; const input = parent.querySelector( - `${selector} ${AFTER_ID_INPUT_SELECTOR}` + `${selector} ${AFTER_STABLE_ID_INPUT_SELECTOR}` ); if (input) { - input.value = this.typeDeChampIdValue; + input.value = this.typeDeChampStableIdValue; } } } } -const AFTER_ID_INPUT_SELECTOR = 'input[name="type_de_champ[after_id]"]'; +const AFTER_STABLE_ID_INPUT_SELECTOR = + 'input[name="type_de_champ[after_stable_id]"]'; function createForm(action: string, method: string) { const form = document.createElement('form'); diff --git a/app/models/procedure_revision.rb b/app/models/procedure_revision.rb index 58a7c4cc8..8d366ca8a 100644 --- a/app/models/procedure_revision.rb +++ b/app/models/procedure_revision.rb @@ -43,8 +43,8 @@ class ProcedureRevision < ApplicationRecord end def add_type_de_champ(params) - parent_stable_id = params.delete(:parent_id) - after_stable_id = params.delete(:after_id) + parent_stable_id = params.delete(:parent_stable_id) + after_stable_id = params.delete(:after_stable_id) coordinate = {} diff --git a/config/routes.rb b/config/routes.rb index 68fc69258..250a612c7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -464,7 +464,7 @@ Rails.application.routes.draw do resources :experts, controller: 'experts_procedures', only: [:index, :create, :update, :destroy] - resources :types_de_champ, only: [:create, :update, :destroy] do + resources :types_de_champ, only: [:create, :update, :destroy], param: :stable_id do collection do get :estimate_fill_duration end diff --git a/spec/models/champ_spec.rb b/spec/models/champ_spec.rb index 8b57b1d13..7c8be9a92 100644 --- a/spec/models/champ_spec.rb +++ b/spec/models/champ_spec.rb @@ -78,7 +78,7 @@ describe Champ do procedure.active_revision.add_type_de_champ( libelle: 'header', type_champ: 'header_section', - parent_id: procedure.types_de_champ.find(&:repetition?).stable_id + parent_stable_id: procedure.types_de_champ.find(&:repetition?).stable_id ) end end @@ -524,7 +524,7 @@ describe Champ do let(:champ_text_attrs) { attributes_for(:champ_text, type_de_champ: tdc_text, row: 1) } before do - procedure.active_revision.add_type_de_champ(libelle: 'sub integer', type_champ: 'integer_number', parent_id: tdc_repetition.stable_id) + procedure.active_revision.add_type_de_champ(libelle: 'sub integer', type_champ: 'integer_number', parent_stable_id: tdc_repetition.stable_id) end context 'when creating the model directly' do diff --git a/spec/models/champs/header_section_champ_spec.rb b/spec/models/champs/header_section_champ_spec.rb index 1a823e4b0..a32602c4a 100644 --- a/spec/models/champs/header_section_champ_spec.rb +++ b/spec/models/champs/header_section_champ_spec.rb @@ -38,7 +38,7 @@ describe Champs::HeaderSectionChamp do revision.add_type_de_champ( libelle: tdc.libelle, type_champ: tdc.type_champ, - parent_id: tdc_repetition.stable_id + parent_stable_id: tdc_repetition.stable_id ) end end diff --git a/spec/models/concern/tags_substitution_concern_spec.rb b/spec/models/concern/tags_substitution_concern_spec.rb index be992abde..5b489c8b3 100644 --- a/spec/models/concern/tags_substitution_concern_spec.rb +++ b/spec/models/concern/tags_substitution_concern_spec.rb @@ -163,8 +163,8 @@ describe TagsSubstitutionConcern, type: :model do let(:template) { '--Répétition--' } let(:repetition) do repetition_tdc = procedure.active_revision.add_type_de_champ(type_champ: 'repetition', libelle: 'Répétition') - procedure.active_revision.add_type_de_champ(type_champ: 'text', libelle: 'Nom', parent_id: repetition_tdc.stable_id) - procedure.active_revision.add_type_de_champ(type_champ: 'text', libelle: 'Prénom', parent_id: repetition_tdc.stable_id) + procedure.active_revision.add_type_de_champ(type_champ: 'text', libelle: 'Nom', parent_stable_id: repetition_tdc.stable_id) + procedure.active_revision.add_type_de_champ(type_champ: 'text', libelle: 'Prénom', parent_stable_id: repetition_tdc.stable_id) repetition_tdc end diff --git a/spec/models/dossier_rebase_concern_spec.rb b/spec/models/dossier_rebase_concern_spec.rb index 640ef84fd..1ddf4f535 100644 --- a/spec/models/dossier_rebase_concern_spec.rb +++ b/spec/models/dossier_rebase_concern_spec.rb @@ -182,7 +182,7 @@ describe Dossier do procedure.draft_revision.add_type_de_champ({ type_champ: TypeDeChamp.type_champs.fetch(:checkbox), libelle: "oui ou non", - parent_id: repetition_type_de_champ.stable_id + parent_stable_id: repetition_type_de_champ.stable_id }) procedure.draft_revision.remove_type_de_champ(yes_no_type_de_champ.stable_id) @@ -365,8 +365,8 @@ describe Dossier do let!(:procedure) do create(:procedure).tap do |p| repetition = p.draft_revision.add_type_de_champ(type_champ: :repetition, libelle: 'p1') - p.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'c1', parent_id: repetition.stable_id) - p.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'c2', parent_id: repetition.stable_id) + p.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'c1', parent_stable_id: repetition.stable_id) + p.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'c2', parent_stable_id: repetition.stable_id) p.publish! end end @@ -377,7 +377,7 @@ describe Dossier do context 'when a child tdc is added in the middle' do before do - added_tdc = procedure.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'c3', parent_id: repetition_stable_id) + added_tdc = procedure.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'c3', parent_stable_id: repetition_stable_id) procedure.draft_revision.move_type_de_champ(added_tdc.stable_id, 1) end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 18108847f..9f528c3c7 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -1477,7 +1477,7 @@ describe Dossier do draft = proc_test.draft_revision tdc_repetition = draft.add_type_de_champ(type_champ: :repetition, libelle: "repetition") - draft.add_type_de_champ(type_champ: :communes, libelle: "communes", parent_id: tdc_repetition.stable_id) + draft.add_type_de_champ(type_champ: :communes, libelle: "communes", parent_stable_id: tdc_repetition.stable_id) dossier_test = create(:dossier, procedure: proc_test) repetition = proc_test.types_de_champ_for_procedure_presentation.repetition.first diff --git a/spec/models/procedure_revision_spec.rb b/spec/models/procedure_revision_spec.rb index 2ac3d6e69..7e01495da 100644 --- a/spec/models/procedure_revision_spec.rb +++ b/spec/models/procedure_revision_spec.rb @@ -34,7 +34,7 @@ describe ProcedureRevision do end context 'with a repetition child' do - let(:tdc_params) { text_params.merge(parent_id: type_de_champ_repetition.stable_id) } + let(:tdc_params) { text_params.merge(parent_stable_id: type_de_champ_repetition.stable_id) } it do expect { subject }.to change { draft.reload.types_de_champ.count }.from(4).to(5) @@ -93,7 +93,7 @@ describe ProcedureRevision do draft.add_type_de_champ({ type_champ: TypeDeChamp.type_champs.fetch(:text), libelle: "second child", - parent_id: type_de_champ_repetition.stable_id + parent_stable_id: type_de_champ_repetition.stable_id }) end @@ -101,7 +101,7 @@ describe ProcedureRevision do draft.add_type_de_champ({ type_champ: TypeDeChamp.type_champs.fetch(:text), libelle: "last child", - parent_id: type_de_champ_repetition.stable_id + parent_stable_id: type_de_champ_repetition.stable_id }) end @@ -159,7 +159,7 @@ describe ProcedureRevision do draft.add_type_de_champ({ type_champ: TypeDeChamp.type_champs.fetch(:text), libelle: "second child", - parent_id: type_de_champ_repetition.stable_id + parent_stable_id: type_de_champ_repetition.stable_id }) end @@ -167,7 +167,7 @@ describe ProcedureRevision do draft.add_type_de_champ({ type_champ: TypeDeChamp.type_champs.fetch(:text), libelle: "last child", - parent_id: type_de_champ_repetition.stable_id + parent_stable_id: type_de_champ_repetition.stable_id }) end