Add ability to reorder server rules from admin interface (#34737)
This commit is contained in:
parent
8ed0408adb
commit
d7cb6068b1
12 changed files with 97 additions and 2 deletions
|
@ -22,4 +22,18 @@ class Rule < ApplicationRecord
|
|||
validates :text, presence: true, length: { maximum: TEXT_SIZE_LIMIT }
|
||||
|
||||
scope :ordered, -> { kept.order(priority: :asc, id: :asc) }
|
||||
|
||||
def move!(offset)
|
||||
rules = Rule.ordered.to_a
|
||||
position = rules.index(self)
|
||||
|
||||
rules.delete_at(position)
|
||||
rules.insert(position + offset, self)
|
||||
|
||||
transaction do
|
||||
rules.each.with_index do |rule, index|
|
||||
rule.update!(priority: index)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue