Add menu sections, icons and order, and the simple view
PR CI / ledger (pull_request) Successful in 4s
PR CI / flow (pull_request) Successful in 4s
PR CI / ui (pull_request) Successful in 16s
PR CI / security (pull_request) Failing after 38s
PR CI / test (lowest) (pull_request) Successful in 42s
PR CI / test (stable) (pull_request) Successful in 43s
PR CI / pr-ci (pull_request) Failing after 1s
PR CI / release-automerge (pull_request) Skipped
PR CI / ledger (pull_request) Successful in 4s
PR CI / flow (pull_request) Successful in 4s
PR CI / ui (pull_request) Successful in 16s
PR CI / security (pull_request) Failing after 38s
PR CI / test (lowest) (pull_request) Successful in 42s
PR CI / test (stable) (pull_request) Successful in 43s
PR CI / pr-ci (pull_request) Failing after 1s
PR CI / release-automerge (pull_request) Skipped
This commit is contained in:
1 parent
362a5bce2e
commit
6f31a54818
23 files changed
+393
-45
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace IriksIT\Manager\Support;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use IriksIT\Manager\Contracts\Module;
|
||||
use IriksIT\Manager\Exceptions\ModuleException;
|
||||
|
||||
@@ -76,6 +77,11 @@ final class ModuleRegistry
|
||||
}
|
||||
}
|
||||
|
||||
if (config('manager.simple_view')) {
|
||||
$permissions['manager.full'] = new Permission('manager.full', 'See the whole manager, not only the simple screens', 'Manager');
|
||||
$permissions['manager.switch'] = new Permission('manager.switch', 'Switch between the simple and the whole manager', 'Manager');
|
||||
}
|
||||
|
||||
return $permissions;
|
||||
}
|
||||
|
||||
@@ -131,16 +137,49 @@ final class ModuleRegistry
|
||||
return $catalogue;
|
||||
}
|
||||
|
||||
/** @return list<array{label: string, route: string, permission: string}> */
|
||||
/**
|
||||
* The menu: what the modules give, changed by config `manager.menu`, in order. An item has `label`,
|
||||
* `route` (or `url` for a link of the site's own) and `permission`, and may add `section` (a heading),
|
||||
* `icon`, `order` (lower comes first; default 100), `simple` (shown in the simple view) and `new_tab`.
|
||||
*
|
||||
* @return list<array{label: string, route?: string, url?: string, permission: ?string, section?: string, icon?: string, order: int, simple: bool, new_tab?: bool}>
|
||||
*/
|
||||
public function navigation(): array
|
||||
{
|
||||
$changes = (array) config('manager.menu.items', []);
|
||||
$items = [];
|
||||
|
||||
foreach ($this->active() as $module) {
|
||||
array_push($items, ...array_map(fn (array $item) => [...$item, 'label' => __($item['label'])], $module->navigation()));
|
||||
foreach ($module->navigation() as $item) {
|
||||
$short = isset($item['route']) ? Str::after($item['route'], Names::routePrefix()) : '';
|
||||
$item = [...$item, ...(array) ($changes[$short] ?? [])];
|
||||
|
||||
if (($item['hidden'] ?? false) === true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$items[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
foreach ((array) config('manager.menu.links', []) as $link) {
|
||||
if (is_array($link) && isset($link['label'], $link['url'])) {
|
||||
$items[] = $link + ['permission' => null];
|
||||
}
|
||||
}
|
||||
|
||||
$items = array_map(fn (array $item) => [
|
||||
...$item,
|
||||
'label' => __($item['label']),
|
||||
...(isset($item['section']) ? ['section' => __($item['section'])] : []),
|
||||
'order' => (int) ($item['order'] ?? 100),
|
||||
'simple' => (bool) ($item['simple'] ?? false),
|
||||
], $items);
|
||||
|
||||
// PHP's sort is stable: items with the same order keep the order of the modules.
|
||||
usort($items, fn (array $a, array $b) => $a['order'] <=> $b['order']);
|
||||
|
||||
return array_values($items);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,7 +189,7 @@ final class ModuleRegistry
|
||||
*/
|
||||
public function actions(): array
|
||||
{
|
||||
$actions = ['profile.update' => ['Changed own account']];
|
||||
$actions = ['profile.update' => ['Changed own account'], 'profile.view' => ['Switched between the simple and the whole manager']];
|
||||
|
||||
foreach ($this->active() as $module) {
|
||||
$actions = [...$actions, ...$module->actions()];
|
||||
|
||||
Reference in new issue
Block a user