move_type_de_champ new style
This commit is contained in:
parent
795513e093
commit
df91fd1180
2 changed files with 7 additions and 15 deletions
|
@ -66,23 +66,15 @@ class ProcedureRevision < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def move_type_de_champ(stable_id, position)
|
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?
|
siblings = coordinate.siblings.to_a
|
||||||
repetition_type_de_champ = find_or_clone_type_de_champ(stable_id).parent
|
|
||||||
|
|
||||||
move_type_de_champ_hash(repetition_type_de_champ.types_de_champ.to_a, type_de_champ, position).each do |(id, position)|
|
siblings.insert(position, siblings.delete_at(siblings.index(coordinate)))
|
||||||
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
|
|
||||||
|
|
||||||
move_type_de_champ_hash(liste.to_a, type_de_champ, position).each do |(id, position)|
|
reorder(siblings)
|
||||||
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)
|
||||||
|
|
|
@ -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.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!
|
procedure.publish_revision!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue