diff --git a/config/autoload/navigation.global.php b/config/autoload/navigation.global.php index 45a363ce..75d147ca 100644 --- a/config/autoload/navigation.global.php +++ b/config/autoload/navigation.global.php @@ -14,79 +14,49 @@ [ 'options' => [ 'label' => 'Dashboard', + 'uri' => '/', 'route' => [ 'route_name' => 'dashboard', ], - 'icon' => 'fas fa-tachometer-alt', + 'icon' => 'c-blue-500 ti-home', ], ], [ 'options' => [ 'label' => 'Manage admins', - 'route' => '', - 'icon' => 'fas fa-user-circle', + 'route' => [], + 'icon' => 'c-teal-500 ti-view-list-alt ', ], 'pages' => [ [ 'options' => [ 'label' => 'Admins', 'uri' => '/admin/manage', - 'icon' => 'fas fa-user-circle', ], ], [ 'options' => [ 'label' => 'Logins', 'uri' => '/admin/logins', - 'icon' => 'fas fa-sign-in-alt', - ], - ], - ], - ], - [ - 'options' => [ - 'label' => 'Submenu 1', - 'route' => '', - 'icon' => 'fas fa-cog', - ], - 'pages' => [ - [ - 'options' => [ - 'label' => 'Submenu link 1', - 'uri' => '#', - 'icon' => 'fas fa-square', ], ], [ 'options' => [ - 'label' => 'Submenu link 2', - 'uri' => '#', - 'icon' => 'fas fa-square', + 'label' => 'View logins v2', + 'uri' => '/admin/simple-logins', + 'icon' => 'c-pink-500 ti-palette', ], ], ], ], [ 'options' => [ - 'label' => 'Submenu 2', - 'route' => '', - 'icon' => 'fas fa-cog', - ], - 'pages' => [ - [ - 'options' => [ - 'label' => 'Submenu link 1', - 'uri' => '#', - 'icon' => 'fa fa-square', - ], - ], - [ - 'options' => [ - 'label' => 'Submenu link 2', - 'uri' => '#', - 'icon' => 'fa fa-square', - ], + 'label' => 'Components', + 'uri' => '/page/components', + 'route' => [ + 'route_name' => 'page', ], + 'icon' => 'c-pink-500 ti-palette', ], ], ], @@ -105,28 +75,19 @@ 'action' => 'account', ], ], - 'icon' => 'fas fa-user', - ], - ], - [ - 'options' => [ - 'label' => 'Settings', - 'route' => [ - 'route_name' => 'dashboard', - ], - 'icon' => 'fas fa-cog', + 'icon' => 'ti-user', ], ], [ 'options' => [ - 'label' => 'Sign Out', + 'label' => 'Logout', 'route' => [ 'route_name' => 'admin', 'route_params' => [ 'action' => 'logout', ], ], - 'icon' => 'fas fa-sign-out-alt', + 'icon' => 'ti-power-off', ], ], ], diff --git a/src/App/src/Twig/Extension/RouteExtension.php b/src/App/src/Twig/Extension/RouteExtension.php index 607d8f91..14057ff9 100644 --- a/src/App/src/Twig/Extension/RouteExtension.php +++ b/src/App/src/Twig/Extension/RouteExtension.php @@ -21,6 +21,7 @@ public function getFunctions(): array { return [ new TwigFunction('getCurrentRoute', [$this, 'getCurrentRoute']), + new TwigFunction('isRoute', [$this, 'isRoute']), ]; } @@ -28,4 +29,18 @@ public function getCurrentRoute(): ?string { return $this->urlHelper->getRequest()?->getUri()?->getPath(); } + + public function isRoute(?string $route): bool + { + if (null === $route) { + return false; + } + + $currentRoute = $this->getCurrentRoute(); + if (null === $currentRoute) { + return false; + } + + return $currentRoute === $route; + } } diff --git a/src/App/templates/partial/account-menu.html.twig b/src/App/templates/partial/account-menu.html.twig new file mode 100644 index 00000000..3f035458 --- /dev/null +++ b/src/App/templates/partial/account-menu.html.twig @@ -0,0 +1,14 @@ +{% set lastKey = container|keys|last %} +{% for page in container %} + {% if navigation.isAllowed(page) %} +
  • + + + {{ page.getOption('label') }} + +
  • + {% if loop.index0 < lastKey %} + + {% endif %} + {% endif %} +{% endfor %} diff --git a/src/App/templates/partial/left-menu.html.twig b/src/App/templates/partial/left-menu.html.twig index d7dd5e36..69d29d34 100644 --- a/src/App/templates/partial/left-menu.html.twig +++ b/src/App/templates/partial/left-menu.html.twig @@ -1,4 +1,3 @@ -{% set currentRoute = getCurrentRoute() %} + diff --git a/src/App/templates/partial/menu.html.twig b/src/App/templates/partial/menu.html.twig index 39a39fdb..8552f49d 100644 --- a/src/App/templates/partial/menu.html.twig +++ b/src/App/templates/partial/menu.html.twig @@ -1,63 +1,45 @@ - diff --git a/test/Unit/App/Twig/Extension/RouteExtensionTest.php b/test/Unit/App/Twig/Extension/RouteExtensionTest.php index 9751d009..ddd2eeb2 100644 --- a/test/Unit/App/Twig/Extension/RouteExtensionTest.php +++ b/test/Unit/App/Twig/Extension/RouteExtensionTest.php @@ -37,7 +37,7 @@ public function testWillAddExistingFunctions(): void ); $functions = $routeExtension->getFunctions(); - $this->assertCount(1, $functions); + $this->assertCount(2, $functions); $twigFunction = $functions[0]; $this->assertInstanceOf(TwigFunction::class, $twigFunction); @@ -62,4 +62,17 @@ public function testWillGetCurrentRoute(): void $routeExtension = new RouteExtension($urlHelper); $this->assertSame('/test', $routeExtension->getCurrentRoute()); } + + /** + * @throws Exception + */ + public function testIsRoute(): void + { + $router = $this->createMock(RouterInterface::class); + $request = new ServerRequest(uri: new Uri('/test')); + $urlHelper = new UrlHelper($router); + $urlHelper->setRequest($request); + $routeExtension = new RouteExtension($urlHelper); + $this->assertSame(true, $routeExtension->isRoute('/test')); + } }