From 095ec0352d4af9e886824731fd69f72d7db3083f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 3 Oct 2024 17:28:54 +0200 Subject: [PATCH] Init admin dashboard page --- app/Menu/AdminMenuBuilder.php | 4 +- src/AdminUi/config/routes.php | 11 +++- .../templates/dashboard/index.html.twig | 9 +++ src/BootstrapAdminUi/composer.json | 1 + .../config/app/twig_hooks/dashboard/index.php | 63 +++++++++++++++++++ .../shared/crud/common/navbar.html.twig | 5 ++ .../.application/config/bundles.php | 1 + .../config/packages/security.yaml | 4 ++ tests/Functional/BookTest.php | 1 - tests/Functional/DashboardTest.php | 40 ++++++++++++ 10 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 src/AdminUi/templates/dashboard/index.html.twig create mode 100644 src/BootstrapAdminUi/config/app/twig_hooks/dashboard/index.php create mode 100644 src/BootstrapAdminUi/templates/shared/crud/common/navbar.html.twig create mode 100644 src/BootstrapAdminUi/tests/Functional/.application/config/packages/security.yaml create mode 100644 tests/Functional/DashboardTest.php diff --git a/app/Menu/AdminMenuBuilder.php b/app/Menu/AdminMenuBuilder.php index 9c6a09a3..eb583618 100644 --- a/app/Menu/AdminMenuBuilder.php +++ b/app/Menu/AdminMenuBuilder.php @@ -29,7 +29,9 @@ public function createMenu(array $options): ItemInterface $menu = $this->menuBuilder->createMenu($options); $menu - ->addChild('dashboard') + ->addChild('dashboard', [ + 'route' => 'sylius_admin_ui_dashboard', + ]) ->setLabel('sylius.ui.dashboard') ->setLabelAttribute('icon', 'dashboard') ; diff --git a/src/AdminUi/config/routes.php b/src/AdminUi/config/routes.php index a02e4abe..18f91d45 100644 --- a/src/AdminUi/config/routes.php +++ b/src/AdminUi/config/routes.php @@ -13,6 +13,7 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator; +use Symfony\Bundle\FrameworkBundle\Controller\TemplateController; use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; return function (RoutingConfigurator $routes): void { @@ -22,5 +23,13 @@ $routes->add('sylius_admin_ui_login_check', '/login_check'); $routes->add('sylius_admin_ui_logout', '/logout') - ->methods(['GET']); + ->methods(['GET']) + ; + + $routes->add('sylius_admin_ui_dashboard', '/') + ->controller(TemplateController::class) + ->defaults([ + 'template' => '@SyliusAdminUi/dashboard/index.html.twig', + ]) + ; }; diff --git a/src/AdminUi/templates/dashboard/index.html.twig b/src/AdminUi/templates/dashboard/index.html.twig new file mode 100644 index 00000000..b7597092 --- /dev/null +++ b/src/AdminUi/templates/dashboard/index.html.twig @@ -0,0 +1,9 @@ +{% extends '@SyliusAdminUi/base.html.twig' %} + +{% block title %} +{{ 'sylius.ui.dashboard'|trans }} {{ parent() }} +{% endblock %} + +{% block body %} +{% hook ['sylius_admin.dashboard.index', 'sylius_admin.common.index'] %} +{% endblock %} diff --git a/src/BootstrapAdminUi/composer.json b/src/BootstrapAdminUi/composer.json index b736e21a..0685288a 100644 --- a/src/BootstrapAdminUi/composer.json +++ b/src/BootstrapAdminUi/composer.json @@ -11,6 +11,7 @@ "sylius/twig-hooks": "^0.3 || dev-main", "symfony/asset": "^6.4 || ^7.0", "symfony/http-kernel": "^6.4 || ^7.0", + "symfony/security-bundle": "^6.4 || ^7.0", "symfony/ux-autocomplete": "^2.17", "symfony/ux-live-component": "^2.17" }, diff --git a/src/BootstrapAdminUi/config/app/twig_hooks/dashboard/index.php b/src/BootstrapAdminUi/config/app/twig_hooks/dashboard/index.php new file mode 100644 index 00000000..1c7450fb --- /dev/null +++ b/src/BootstrapAdminUi/config/app/twig_hooks/dashboard/index.php @@ -0,0 +1,63 @@ +extension('sylius_twig_hooks', [ + 'hooks' => [ + 'sylius_admin.dashboard.index' => [ + 'sidebar' => [ + 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/sidebar.html.twig', + ], + 'navbar' => [ + 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/navbar.html.twig', + ], + 'content' => [ + 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/content.html.twig', + ], + ], + + 'sylius_admin.dashboard.index.content' => [ + 'header' => [ + 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/content/header.html.twig', + ], + 'grid' => [ + 'enabled' => false, + ], + ], + + 'sylius_admin.dashboard.index.content.header' => [ + 'breadcrumbs' => [ + 'enabled' => false, + ], + 'title_block' => [ + 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/content/header/title_block.html.twig', + ], + ], + + 'sylius_admin.dashboard.index.content.header.title_block' => [ + 'title' => [ + 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/content/header/title_block/title.html.twig', + 'configuration' => [ + 'title' => 'sylius.ui.dashboard', + 'sylius_test_html_attribute' => 'dashboard-header', + ], + ], + 'actions' => [ + 'enabled' => false, + ], + ], + ], + ]); +}; diff --git a/src/BootstrapAdminUi/templates/shared/crud/common/navbar.html.twig b/src/BootstrapAdminUi/templates/shared/crud/common/navbar.html.twig new file mode 100644 index 00000000..a83a22eb --- /dev/null +++ b/src/BootstrapAdminUi/templates/shared/crud/common/navbar.html.twig @@ -0,0 +1,5 @@ + diff --git a/src/BootstrapAdminUi/tests/Functional/.application/config/bundles.php b/src/BootstrapAdminUi/tests/Functional/.application/config/bundles.php index 7791cd48..92a574b7 100644 --- a/src/BootstrapAdminUi/tests/Functional/.application/config/bundles.php +++ b/src/BootstrapAdminUi/tests/Functional/.application/config/bundles.php @@ -15,6 +15,7 @@ Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], + Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], Symfony\UX\TwigComponent\TwigComponentBundle::class => ['all' => true], Sylius\TwigHooks\SyliusTwigHooksBundle::class => ['all' => true], Sylius\BootstrapAdminUi\Symfony\SyliusBootstrapAdminUiBundle::class => ['all' => true], diff --git a/src/BootstrapAdminUi/tests/Functional/.application/config/packages/security.yaml b/src/BootstrapAdminUi/tests/Functional/.application/config/packages/security.yaml new file mode 100644 index 00000000..fbd7d5fa --- /dev/null +++ b/src/BootstrapAdminUi/tests/Functional/.application/config/packages/security.yaml @@ -0,0 +1,4 @@ +security: + firewalls: + dev: + pattern: ^/(_(profiler|wdt)|css|images|js)/ diff --git a/tests/Functional/BookTest.php b/tests/Functional/BookTest.php index 2b329a58..129607b9 100644 --- a/tests/Functional/BookTest.php +++ b/tests/Functional/BookTest.php @@ -7,7 +7,6 @@ use App\Entity\Book; use App\Factory\BookFactory; use App\Factory\UserFactory; -use App\Story\DefaultUsersStory; use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\HttpFoundation\Response; diff --git a/tests/Functional/DashboardTest.php b/tests/Functional/DashboardTest.php new file mode 100644 index 00000000..f4e1d6d4 --- /dev/null +++ b/tests/Functional/DashboardTest.php @@ -0,0 +1,40 @@ +client = self::createClient(); + + $user = UserFactory::new() + ->admin() + ->create() + ; + + $this->client->loginUser($user->_real()); + } + + public function testDashboard(): void + { + $this->client->request('GET', '/admin/'); + + self::assertResponseIsSuccessful(); + + self::assertSelectorTextContains('h1.page-title', 'Dashboard'); + } +}