Make stuff sortable
This commit is contained in:
parent
50e853098b
commit
ee5dbcf33e
21 changed files with 161 additions and 28 deletions
|
|
@ -15,6 +15,7 @@ class SuccessCriterion < ApplicationRecord
|
|||
enum :level, %i[A AA AAA]
|
||||
|
||||
before_save :set_position
|
||||
before_update :update_positions, if: :position_changed?
|
||||
|
||||
def level_value
|
||||
return nil unless level
|
||||
|
|
@ -26,9 +27,20 @@ class SuccessCriterion < ApplicationRecord
|
|||
"HEADER"
|
||||
end
|
||||
|
||||
def number
|
||||
[ page.position, element.position, position ].join(".")
|
||||
end
|
||||
|
||||
private
|
||||
def set_position
|
||||
self.position ||= (element.success_criteria.pluck(:position).max || 0) + 1
|
||||
Rails.logger.debug("set position: "+position.to_s)
|
||||
end
|
||||
|
||||
def update_positions
|
||||
if position_was
|
||||
element.success_criteria.where("position > ?", position_was).update_all("position = position - 1")
|
||||
end
|
||||
element.success_criteria.where(position: position..).update_all("position = position + 1")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue