A lot :)
Some checks failed
/ Run tests (push) Successful in 8m56s
/ Run system tests (push) Failing after 1h0m48s
/ Build, push and deploy image (push) Successful in 7m47s

This commit is contained in:
david 2024-09-05 22:54:38 +02:00
parent aad67af0d1
commit 63fc206c27
153 changed files with 2043 additions and 646 deletions

View file

@ -1,12 +1,15 @@
# frozen_string_literal: true
class ChecklistEntry < ApplicationRecord
belongs_to :checklist
belongs_to :check
before_validation :set_position
after_validation :normalize_positions
before_create :update_positions
before_update :update_positions, if: :position_changed?
def set_position
self.position ||= checklist.checklist_entries.maximum(:position).to_i + 1
self.position ||= (checklist.checklist_entries.pluck(:position).max || 0) + 1
end
def normalize_positions
@ -15,4 +18,11 @@ class ChecklistEntry < ApplicationRecord
# entry.update_column(:position, index + 1) if entry.position != index + 1
# end
end
def update_positions
if position_was
checklist.checklist_entries.where("position > ?", position_was).update_all("position = position - 1")
end
checklist.checklist_entries.where(position: position..).update_all("position = position + 1")
end
end