Revert "Merge pull request #7280 from betagouv/move_type_de_champ_v2"
This reverts commit08b90b9173
, reversing changes made tobc9a90bd08
.
This commit is contained in:
parent
08b90b9173
commit
08caa122dd
3 changed files with 29 additions and 27 deletions
|
@ -66,15 +66,23 @@ class ProcedureRevision < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def move_type_de_champ(stable_id, position)
|
def move_type_de_champ(stable_id, position)
|
||||||
coordinate = revision_types_de_champ
|
type_de_champ = find_type_de_champ_by_stable_id(stable_id)
|
||||||
.joins(:type_de_champ)
|
|
||||||
.find_by(type_de_champ: { stable_id: stable_id })
|
|
||||||
|
|
||||||
siblings = coordinate.siblings.to_a
|
if type_de_champ.parent.present?
|
||||||
|
repetition_type_de_champ = find_or_clone_type_de_champ(stable_id).parent
|
||||||
|
|
||||||
siblings.insert(position, siblings.delete_at(siblings.index(coordinate)))
|
move_type_de_champ_hash(repetition_type_de_champ.types_de_champ.to_a, type_de_champ, position).each do |(id, position)|
|
||||||
|
type_de_champ = repetition_type_de_champ.types_de_champ.find(id)
|
||||||
|
type_de_champ.update!(order_place: position)
|
||||||
|
type_de_champ.revision_type_de_champ&.update!(position: position)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
liste = type_de_champ.private? ? types_de_champ_private : types_de_champ_public
|
||||||
|
|
||||||
reorder(siblings)
|
move_type_de_champ_hash(liste.to_a, type_de_champ, position).each do |(id, position)|
|
||||||
|
revision_types_de_champ.find_by!(type_de_champ_id: id).update!(position: position)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_type_de_champ(stable_id)
|
def remove_type_de_champ(stable_id)
|
||||||
|
@ -147,14 +155,10 @@ class ProcedureRevision < ApplicationRecord
|
||||||
private
|
private
|
||||||
|
|
||||||
def reorder(siblings)
|
def reorder(siblings)
|
||||||
siblings.to_a.compact.each.with_index do |sibling, position|
|
siblings.to_a.compact.each.with_index do |e, position|
|
||||||
sibling.update(position: position)
|
e.update(position: position)
|
||||||
|
e.type_de_champ.update!(order_place: position)
|
||||||
# FIXME: to remove when order_place is no longer used
|
end
|
||||||
if sibling.parent_id.present?
|
|
||||||
sibling.type_de_champ.update!(order_place: position)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def compare_attestation_template(from_at, to_at)
|
def compare_attestation_template(from_at, to_at)
|
||||||
|
|
|
@ -41,7 +41,7 @@ describe ProcedurePresentation do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
created_tdc0 = procedure.draft_revision.add_type_de_champ(tdc0)
|
created_tdc0 = procedure.draft_revision.add_type_de_champ(tdc0)
|
||||||
procedure.draft_revision.reload.move_type_de_champ(created_tdc0.stable_id, 0)
|
procedure.draft_revision.move_type_de_champ(created_tdc0.stable_id, 0)
|
||||||
procedure.publish_revision!
|
procedure.publish_revision!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -53,21 +53,21 @@ describe ProcedureRevision do
|
||||||
context 'with 4 types de champ publiques' do
|
context 'with 4 types de champ publiques' do
|
||||||
it 'move down' do
|
it 'move down' do
|
||||||
expect(draft.types_de_champ_public.index(type_de_champ_public)).to eq(0)
|
expect(draft.types_de_champ_public.index(type_de_champ_public)).to eq(0)
|
||||||
|
type_de_champ_public.update(order_place: nil)
|
||||||
draft.move_type_de_champ(type_de_champ_public.stable_id, 2)
|
draft.move_type_de_champ(type_de_champ_public.stable_id, 2)
|
||||||
draft.reload
|
draft.reload
|
||||||
|
|
||||||
expect(draft.types_de_champ_public.index(type_de_champ_public)).to eq(2)
|
expect(draft.types_de_champ_public.index(type_de_champ_public)).to eq(2)
|
||||||
|
expect(draft.procedure.types_de_champ.index(type_de_champ_public)).to eq(2)
|
||||||
expect(draft.procedure.types_de_champ_for_procedure_presentation.not_repetition.index(type_de_champ_public)).to eq(2)
|
expect(draft.procedure.types_de_champ_for_procedure_presentation.not_repetition.index(type_de_champ_public)).to eq(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'move up' do
|
it 'move up' do
|
||||||
expect(draft.types_de_champ_public.index(last_type_de_champ)).to eq(3)
|
expect(draft.types_de_champ_public.index(last_type_de_champ)).to eq(3)
|
||||||
|
last_type_de_champ.update(order_place: nil)
|
||||||
draft.move_type_de_champ(last_type_de_champ.stable_id, 0)
|
draft.move_type_de_champ(last_type_de_champ.stable_id, 0)
|
||||||
draft.reload
|
draft.reload
|
||||||
|
|
||||||
expect(draft.types_de_champ_public.index(last_type_de_champ)).to eq(0)
|
expect(draft.types_de_champ_public.index(last_type_de_champ)).to eq(0)
|
||||||
|
expect(draft.procedure.types_de_champ.index(last_type_de_champ)).to eq(0)
|
||||||
expect(draft.procedure.types_de_champ_for_procedure_presentation.not_repetition.index(last_type_de_champ)).to eq(0)
|
expect(draft.procedure.types_de_champ_for_procedure_presentation.not_repetition.index(last_type_de_champ)).to eq(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -92,19 +92,17 @@ describe ProcedureRevision do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'move down' do
|
it 'move down' do
|
||||||
expect(draft.children_of(type_de_champ_repetition).index(second_child)).to eq(1)
|
expect(type_de_champ_repetition.types_de_champ.index(second_child)).to eq(1)
|
||||||
|
|
||||||
draft.move_type_de_champ(second_child.stable_id, 2)
|
draft.move_type_de_champ(second_child.stable_id, 2)
|
||||||
|
type_de_champ_repetition.reload
|
||||||
expect(draft.children_of(type_de_champ_repetition).index(second_child)).to eq(2)
|
expect(type_de_champ_repetition.types_de_champ.index(second_child)).to eq(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'move up' do
|
it 'move up' do
|
||||||
expect(draft.children_of(type_de_champ_repetition).index(last_child)).to eq(2)
|
expect(type_de_champ_repetition.types_de_champ.index(last_child)).to eq(2)
|
||||||
|
|
||||||
draft.move_type_de_champ(last_child.stable_id, 0)
|
draft.move_type_de_champ(last_child.stable_id, 0)
|
||||||
|
type_de_champ_repetition.reload
|
||||||
expect(draft.children_of(type_de_champ_repetition).index(last_child)).to eq(0)
|
expect(type_de_champ_repetition.types_de_champ.index(last_child)).to eq(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue