feat(help-center): enable drag-and-drop category reordering (#13706)
This commit is contained in:
@@ -132,11 +132,13 @@ class Article < ApplicationRecord
|
||||
# rubocop:enable Rails/SkipsModelValidations
|
||||
end
|
||||
|
||||
def self.update_positions(positions_hash)
|
||||
positions_hash.each do |article_id, new_position|
|
||||
# Find the article by its ID and update its position
|
||||
article = Article.find(article_id)
|
||||
article.update!(position: new_position)
|
||||
def self.update_positions(portal:, positions_hash:)
|
||||
return if positions_hash.blank?
|
||||
|
||||
transaction do
|
||||
positions_hash.each do |article_id, new_position|
|
||||
portal.articles.find(article_id).update!(position: new_position)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -73,6 +73,16 @@ class Category < ApplicationRecord
|
||||
params[:page] || 1
|
||||
end
|
||||
|
||||
def self.update_positions(portal:, positions_hash:)
|
||||
return if positions_hash.blank?
|
||||
|
||||
transaction do
|
||||
positions_hash.each do |category_id, new_position|
|
||||
portal.categories.find(category_id).update!(position: new_position)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ensure_account_id
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
class Portal < ApplicationRecord
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
DEFAULT_COLOR = '#1f93ff'.freeze
|
||||
|
||||
belongs_to :account
|
||||
has_many :categories, dependent: :destroy_async
|
||||
has_many :folders, through: :categories
|
||||
@@ -62,6 +64,10 @@ class Portal < ApplicationRecord
|
||||
config['default_locale'] || 'en'
|
||||
end
|
||||
|
||||
def color
|
||||
self[:color].presence || DEFAULT_COLOR
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def config_json_format
|
||||
|
||||
Reference in New Issue
Block a user