FEATURE: ability to reorder links in custom sidebar sections (#20626)

Drag and drop to reorder custom sidebar sections
This commit is contained in:
Krzysztof Kotlarek
2023-03-21 12:23:28 +11:00
committed by GitHub
parent 53cadac4b8
commit db74e9484b
17 changed files with 343 additions and 46 deletions

View File

@ -13,6 +13,12 @@ class SidebarSectionLink < ActiveRecord::Base
SUPPORTED_LINKABLE_TYPES = %w[Category Tag SidebarUrl]
before_validation { self.user_id ||= self.sidebar_section&.user_id }
before_create do
if self.user_id && self.sidebar_section
self.position = self.sidebar_section.sidebar_section_links.maximum(:position).to_i + 1
end
end
after_destroy { self.linkable.destroy! if self.linkable_type == "SidebarUrl" }
private def ensure_supported_linkable_type
@ -37,9 +43,11 @@ end
# created_at :datetime not null
# updated_at :datetime not null
# sidebar_section_id :integer
# position :integer default(0), not null
#
# Indexes
#
# idx_unique_sidebar_section_links (user_id,linkable_type,linkable_id) UNIQUE
# index_sidebar_section_links_on_linkable_type_and_linkable_id (linkable_type,linkable_id)
# links_user_id_section_id_position (user_id,sidebar_section_id,position) UNIQUE
#