Skip to content

Commit

Permalink
Init dashboard page (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 authored Oct 3, 2024
2 parents 474799c + 095ec03 commit 13093be
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 3 deletions.
4 changes: 3 additions & 1 deletion app/Menu/AdminMenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
;
Expand Down
11 changes: 10 additions & 1 deletion src/AdminUi/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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',
])
;
};
9 changes: 9 additions & 0 deletions src/AdminUi/templates/dashboard/index.html.twig
Original file line number Diff line number Diff line change
@@ -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 %}
1 change: 1 addition & 0 deletions src/BootstrapAdminUi/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
63 changes: 63 additions & 0 deletions src/BootstrapAdminUi/config/app/twig_hooks/dashboard/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return static function (ContainerConfigurator $container): void {
$container->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,
],
],
],
]);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<header class="navbar d-print-none">
<div class="container-xl d-flex">
{% hook 'sylius_admin.common.component.navbar' with { _prefixes: [] } %}
</div>
</header>
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
security:
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
1 change: 0 additions & 1 deletion tests/Functional/BookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
40 changes: 40 additions & 0 deletions tests/Functional/DashboardTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace MainTests\Sylius\Functional;

use App\Factory\UserFactory;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;

final class DashboardTest extends WebTestCase
{
Use Factories;
use ResetDatabase;

private KernelBrowser $client;

protected function setUp(): void
{
$this->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');
}
}

0 comments on commit 13093be

Please sign in to comment.