re-design the menu builder page
This commit is contained in:
@@ -29,9 +29,7 @@ class NavbarService
|
||||
$allowedIds = $this->mapModel->getNavItemIdsForRoles($roles);
|
||||
if (empty($allowedIds)) return [];
|
||||
|
||||
// Load all enabled items, then filter.
|
||||
// The displayed sidebar is alphabetized after the tree is built so
|
||||
// new menu items fall into place without relying on manual sort_order.
|
||||
// Load all enabled items, then filter. The builder controls this order.
|
||||
$rows = $this->navModel->where('is_enabled', 1)
|
||||
->orderBy('sort_order', 'ASC')
|
||||
->orderBy('label', 'ASC')
|
||||
@@ -59,22 +57,34 @@ class NavbarService
|
||||
}
|
||||
unset($node);
|
||||
|
||||
$this->sortTreeAlphabetically($tree);
|
||||
$this->sortTreeByOrder($tree);
|
||||
|
||||
$this->cache->save($cacheKey, $tree, 300); // 5 minutes
|
||||
return $tree;
|
||||
}
|
||||
|
||||
private function sortTreeAlphabetically(array &$nodes): void
|
||||
private function sortTreeByOrder(array &$nodes): void
|
||||
{
|
||||
usort($nodes, fn ($a, $b) => strnatcasecmp(
|
||||
$this->labelSortKey((string) ($a['label'] ?? '')),
|
||||
$this->labelSortKey((string) ($b['label'] ?? ''))
|
||||
));
|
||||
usort($nodes, function ($a, $b) {
|
||||
$order = ((int) ($a['sort_order'] ?? 0)) <=> ((int) ($b['sort_order'] ?? 0));
|
||||
if ($order !== 0) {
|
||||
return $order;
|
||||
}
|
||||
|
||||
$label = strnatcasecmp(
|
||||
$this->labelSortKey((string) ($a['label'] ?? '')),
|
||||
$this->labelSortKey((string) ($b['label'] ?? ''))
|
||||
);
|
||||
if ($label !== 0) {
|
||||
return $label;
|
||||
}
|
||||
|
||||
return ((int) ($a['id'] ?? 0)) <=> ((int) ($b['id'] ?? 0));
|
||||
});
|
||||
|
||||
foreach ($nodes as &$node) {
|
||||
if (!empty($node['children']) && is_array($node['children'])) {
|
||||
$this->sortTreeAlphabetically($node['children']);
|
||||
$this->sortTreeByOrder($node['children']);
|
||||
}
|
||||
}
|
||||
unset($node);
|
||||
|
||||
Reference in New Issue
Block a user