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
|
@ -50,6 +50,22 @@ module Admin
|
|||
redirect_to admin_rules_path
|
||||
end
|
||||
|
||||
def move_up
|
||||
authorize @rule, :update?
|
||||
|
||||
@rule.move!(-1)
|
||||
|
||||
redirect_to admin_rules_path
|
||||
end
|
||||
|
||||
def move_down
|
||||
authorize @rule, :update?
|
||||
|
||||
@rule.move!(+1)
|
||||
|
||||
redirect_to admin_rules_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_rule
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M440-800v487L216-537l-56 57 320 320 320-320-56-57-224 224v-487h-80Z"/></svg>
|
After Width: | Height: | Size: 173 B |
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M440-800v487L216-537l-56 57 320 320 320-320-56-57-224 224v-487h-80Z"/></svg>
|
After Width: | Height: | Size: 173 B |
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M440-160v-487L216-423l-56-57 320-320 320 320-56 57-224-224v487h-80Z"/></svg>
|
After Width: | Height: | Size: 173 B |
1
app/javascript/material-icons/400-24px/arrow_upward.svg
Normal file
1
app/javascript/material-icons/400-24px/arrow_upward.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M440-160v-487L216-423l-56-57 320-320 320 320-56 57-224-224v487h-80Z"/></svg>
|
After Width: | Height: | Size: 173 B |
|
@ -1127,6 +1127,15 @@ a.name-tag,
|
|||
}
|
||||
}
|
||||
|
||||
.rule-actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
a.table-action-link {
|
||||
padding-inline-start: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.dashboard__counters.admin-account-counters {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -7,5 +7,7 @@
|
|||
.announcements-list__item__meta
|
||||
= rule.hint
|
||||
|
||||
%div
|
||||
.rule-actions
|
||||
= table_link_to 'arrow_upward', t('admin.rules.move_up'), move_up_admin_rule_path(rule), method: :post if can?(:update, rule) && !rule_iteration.first?
|
||||
= table_link_to 'delete', t('admin.rules.delete'), admin_rule_path(rule), method: :delete, data: { confirm: t('admin.accounts.are_you_sure') } if can?(:destroy, rule)
|
||||
= table_link_to 'arrow_downward', t('admin.rules.move_down'), move_down_admin_rule_path(rule), method: :post if can?(:update, rule) && !rule_iteration.last?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue