refactor: reorder -> renumber

This commit is contained in:
simon lehericey 2022-07-11 10:14:18 +02:00
parent 3eadff9111
commit 256d4e4fda

View file

@ -59,7 +59,7 @@ class ProcedureRevision < ApplicationRecord
h = { type_de_champ: tdc, parent_id: parent_id, position: position } h = { type_de_champ: tdc, parent_id: parent_id, position: position }
coordinate = revision_types_de_champ.create!(h) coordinate = revision_types_de_champ.create!(h)
reorder(coordinate.reload.siblings) renumber(coordinate.reload.siblings)
end end
# they are not aware of the addition # they are not aware of the addition
@ -88,7 +88,7 @@ class ProcedureRevision < ApplicationRecord
siblings.insert(position, siblings.delete_at(siblings.index(coordinate))) siblings.insert(position, siblings.delete_at(siblings.index(coordinate)))
reorder(siblings) renumber(siblings)
coordinate.reload coordinate.reload
coordinate coordinate
@ -107,7 +107,7 @@ class ProcedureRevision < ApplicationRecord
types_de_champ_public.reset types_de_champ_public.reset
types_de_champ_private.reset types_de_champ_private.reset
reorder(coordinate.siblings) renumber(coordinate.siblings)
coordinate coordinate
end end
@ -224,7 +224,7 @@ class ProcedureRevision < ApplicationRecord
[coordinate, coordinate.type_de_champ] [coordinate, coordinate.type_de_champ]
end end
def reorder(siblings) def renumber(siblings)
siblings.to_a.compact.each.with_index do |sibling, position| siblings.to_a.compact.each.with_index do |sibling, position|
sibling.update_column(:position, position) sibling.update_column(:position, position)
end end