re-design the menu builder page
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 48s
Tests / PHPUnit (push) Successful in 1m24s

This commit is contained in:
root
2026-09-06 21:29:38 -04:00
parent 485341875a
commit ede7fd947a
4 changed files with 1441 additions and 390 deletions
+20 -10
View File
@@ -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);