Merge pull request #9556 from demarches-simplifiees/fix_conditionnal
Administrateur : correction de l'affichage du bouton "logique conditionnelle" dans l'éditeur de champ
This commit is contained in:
commit
e3b05f7e20
4 changed files with 37 additions and 10 deletions
|
@ -56,13 +56,7 @@ module Administrateurs
|
|||
def retrieve_coordinate_and_uppers
|
||||
@tdc = draft_revision.find_and_ensure_exclusive_use(params[:stable_id])
|
||||
@coordinate = draft_revision.coordinate_for(@tdc)
|
||||
|
||||
upper_coordinates = @coordinate.upper_siblings
|
||||
if @coordinate.child?
|
||||
upper_coordinates += @coordinate.parent.upper_siblings
|
||||
end
|
||||
|
||||
@upper_tdcs = upper_coordinates.map(&:type_de_champ)
|
||||
@upper_tdcs = @coordinate.upper_coordinates.map(&:type_de_champ)
|
||||
end
|
||||
|
||||
def draft_revision
|
||||
|
|
|
@ -105,7 +105,7 @@ module Administrateurs
|
|||
def champ_component_from(coordinate, focused: false, errors: '')
|
||||
TypesDeChampEditor::ChampComponent.new(
|
||||
coordinate:,
|
||||
upper_coordinates: coordinate.upper_siblings,
|
||||
upper_coordinates: coordinate.upper_coordinates,
|
||||
focused: focused,
|
||||
errors:
|
||||
)
|
||||
|
|
|
@ -39,8 +39,14 @@ class ProcedureRevisionTypeDeChamp < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def upper_siblings
|
||||
siblings.filter { |s| s.position < position }
|
||||
def upper_coordinates
|
||||
upper = siblings.filter { |s| s.position < position }
|
||||
|
||||
if child?
|
||||
upper += parent.upper_coordinates
|
||||
end
|
||||
|
||||
upper
|
||||
end
|
||||
|
||||
def siblings_starting_at(offset)
|
||||
|
|
27
spec/models/procedure_revision_type_de_champ_spec.rb
Normal file
27
spec/models/procedure_revision_type_de_champ_spec.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
describe ProcedureRevisionTypeDeChamp do
|
||||
describe '#upper_coordinates' do
|
||||
context 'when the coordinate is in a bloc bellow another coordinate' do
|
||||
let(:procedure) do
|
||||
create(:procedure,
|
||||
types_de_champ_public: [
|
||||
{ libelle: 'l1' },
|
||||
{
|
||||
type: :repetition, children: [
|
||||
{ libelle: 'l2.1' },
|
||||
{ libelle: 'l2.2' }
|
||||
]
|
||||
}
|
||||
])
|
||||
end
|
||||
|
||||
let(:l2_2) do
|
||||
procedure
|
||||
.draft_revision
|
||||
.revision_types_de_champ.joins(:type_de_champ)
|
||||
.find_by(type_de_champ: { libelle: 'l2.2' })
|
||||
end
|
||||
|
||||
it { expect(l2_2.upper_coordinates.map(&:libelle)).to match_array(["l1", "l2.1"]) }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue