move_type_de_champ new style

This commit is contained in:
simon lehericey 2022-05-06 23:20:07 +02:00
parent 795513e093
commit df91fd1180
2 changed files with 7 additions and 15 deletions

View file

@ -66,23 +66,15 @@ class ProcedureRevision < ApplicationRecord
end
def move_type_de_champ(stable_id, position)
type_de_champ = find_type_de_champ_by_stable_id(stable_id)
coordinate = revision_types_de_champ
.joins(:type_de_champ)
.find_by(type_de_champ: { stable_id: stable_id })
if type_de_champ.parent.present?
repetition_type_de_champ = find_or_clone_type_de_champ(stable_id).parent
siblings = coordinate.siblings.to_a
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
siblings.insert(position, siblings.delete_at(siblings.index(coordinate)))
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
reorder(siblings)
end
def remove_type_de_champ(stable_id)

View file

@ -41,7 +41,7 @@ describe ProcedurePresentation do
before do
created_tdc0 = procedure.draft_revision.add_type_de_champ(tdc0)
procedure.draft_revision.move_type_de_champ(created_tdc0.stable_id, 0)
procedure.draft_revision.reload.move_type_de_champ(created_tdc0.stable_id, 0)
procedure.publish_revision!
end