From 2fa0183b421b7bcd024d09f92b6cb35109dfe757 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Tue, 16 Jul 2024 16:10:51 +0200 Subject: [PATCH] add admin dashboard --- .idea/workspace.xml | 47 +-- composer.json | 2 + composer.lock | 297 ++++++++++++++++++- config/bundles.php | 2 + config/packages/reset_password.yaml | 5 + config/packages/security.yaml | 2 +- src/Controller/Admin/DashboardController.php | 56 ++++ src/Controller/Admin/UserCrudController.php | 49 +++ src/DataFixtures/AppFixtures.php | 13 +- symfony.lock | 21 ++ templates/admin/dashboard.html.twig | 7 + 11 files changed, 475 insertions(+), 26 deletions(-) create mode 100644 config/packages/reset_password.yaml create mode 100644 src/Controller/Admin/DashboardController.php create mode 100644 src/Controller/Admin/UserCrudController.php create mode 100644 templates/admin/dashboard.html.twig diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b0a6d9e5..fd5ef67c 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -23,13 +23,13 @@ - - - + + + + + - - - + { + "customColor": "", + "associatedIndex": 4 +} @@ -248,21 +248,22 @@ - { + "keyToString": { + "dart.analysis.tool.window.visible": "false", + "git-widget-placeholder": "master", + "last_opened_file_path": "/home/poule/encrypted/stockage-syncable/www/development/html/caisse", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "yarn", + "vue.rearranger.settings.migration": "true" } -}]]> +} @@ -311,7 +312,9 @@ - + + + diff --git a/composer.json b/composer.json index a7e966bb..7886b383 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ "doctrine/doctrine-bundle": "^2.12", "doctrine/doctrine-migrations-bundle": "^3.3", "doctrine/orm": "^3.1", + "easycorp/easyadmin-bundle": "^4.10", "phpdocumentor/reflection-docblock": "^5.4", "phpstan/phpdoc-parser": "^1.28", "symfony/asset": "6.1.*", @@ -42,6 +43,7 @@ "symfony/web-link": "6.1.*", "symfony/webpack-encore-bundle": "^1.17", "symfony/yaml": "6.1.*", + "symfonycasts/reset-password-bundle": "^1.22", "symfonycasts/verify-email-bundle": "^1.17", "twig/extra-bundle": "^2.12|^3.0", "twig/twig": "^2.12|^3.0" diff --git a/composer.lock b/composer.lock index 201ac48e..ba00aedf 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f9827a90d38bc8fd6f97e651d6298db0", + "content-hash": "fbec70f426422bb2239be4fa6216fb5a", "packages": [ { "name": "amphp/amp", @@ -2203,6 +2203,101 @@ }, "time": "2023-08-16T21:49:04+00:00" }, + { + "name": "easycorp/easyadmin-bundle", + "version": "v4.10.4", + "source": { + "type": "git", + "url": "https://github.com/EasyCorp/EasyAdminBundle.git", + "reference": "8c697782e59dfbd76e6a8cae69d8d3b96dcdbfa1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/EasyCorp/EasyAdminBundle/zipball/8c697782e59dfbd76e6a8cae69d8d3b96dcdbfa1", + "reference": "8c697782e59dfbd76e6a8cae69d8d3b96dcdbfa1", + "shasum": "" + }, + "require": { + "doctrine/doctrine-bundle": "^2.5", + "doctrine/orm": "^2.10|^3.0", + "ext-json": "*", + "php": ">=8.0.2", + "symfony/asset": "^5.4|^6.0|^7.0", + "symfony/cache": "^5.4|^6.0|^7.0", + "symfony/config": "^5.4|^6.0|^7.0", + "symfony/dependency-injection": "^5.4|^6.0|^7.0", + "symfony/deprecation-contracts": "^3.0", + "symfony/doctrine-bridge": "^5.4|^6.0|^7.0", + "symfony/event-dispatcher": "^5.4|^6.0|^7.0", + "symfony/filesystem": "^5.4|^6.0|^7.0", + "symfony/form": "^5.4|^6.0|^7.0", + "symfony/framework-bundle": "^5.4|^6.0|^7.0", + "symfony/http-foundation": "^5.4|^6.0|^7.0", + "symfony/http-kernel": "^5.4|^6.0|^7.0", + "symfony/intl": "^5.4|^6.0|^7.0", + "symfony/property-access": "^5.4|^6.0|^7.0", + "symfony/security-bundle": "^5.4|^6.0|^7.0", + "symfony/string": "^5.4|^6.0|^7.0", + "symfony/translation": "^5.4|^6.0|^7.0", + "symfony/twig-bundle": "^5.4|^6.0|^7.0", + "symfony/uid": "^5.4|^6.0|^7.0", + "symfony/validator": "^5.4|^6.0|^7.0" + }, + "require-dev": { + "doctrine/doctrine-fixtures-bundle": "^3.4|3.5.x-dev", + "phpstan/extension-installer": "^1.2", + "phpstan/phpstan": "^1.9", + "phpstan/phpstan-phpunit": "^1.2", + "phpstan/phpstan-strict-rules": "^1.4", + "phpstan/phpstan-symfony": "^1.2", + "psr/log": "^1.0", + "symfony/browser-kit": "^5.4|^6.0|^7.0", + "symfony/css-selector": "^5.4|^6.0|^7.0", + "symfony/debug-bundle": "^5.4|^6.0|^7.0", + "symfony/dom-crawler": "^5.4|^6.0|^7.0", + "symfony/expression-language": "^5.4|^6.0|^7.0", + "symfony/phpunit-bridge": "^5.4|^6.0|^7.0" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "4.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "EasyCorp\\Bundle\\EasyAdminBundle\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Project Contributors", + "homepage": "https://github.com/EasyCorp/EasyAdminBundle/graphs/contributors" + } + ], + "description": "Admin generator for Symfony applications", + "homepage": "https://github.com/EasyCorp/EasyAdminBundle", + "keywords": [ + "admin", + "backend", + "generator" + ], + "support": { + "issues": "https://github.com/EasyCorp/EasyAdminBundle/issues", + "source": "https://github.com/EasyCorp/EasyAdminBundle/tree/v4.10.4" + }, + "funding": [ + { + "url": "https://github.com/javiereguiluz", + "type": "github" + } + ], + "time": "2024-07-12T18:15:07+00:00" + }, { "name": "egulias/email-validator", "version": "4.0.2", @@ -6361,6 +6456,85 @@ ], "time": "2024-01-29T20:11:03+00:00" }, + { + "name": "symfony/polyfill-uuid", + "version": "v1.30.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-uuid.git", + "reference": "2ba1f33797470debcda07fe9dce20a0003df18e9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-uuid/zipball/2ba1f33797470debcda07fe9dce20a0003df18e9", + "reference": "2ba1f33797470debcda07fe9dce20a0003df18e9", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "provide": { + "ext-uuid": "*" + }, + "suggest": { + "ext-uuid": "For best performance" + }, + "type": "library", + "extra": { + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Uuid\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Grégoire Pineau", + "email": "lyrixx@lyrixx.info" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for uuid functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "uuid" + ], + "support": { + "source": "https://github.com/symfony/polyfill-uuid/tree/v1.30.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-05-31T15:07:36+00:00" + }, { "name": "symfony/process", "version": "v6.1.11", @@ -7881,6 +8055,80 @@ ], "time": "2023-01-01T08:36:55+00:00" }, + { + "name": "symfony/uid", + "version": "v6.1.11", + "source": { + "type": "git", + "url": "https://github.com/symfony/uid.git", + "reference": "7c53913df24517eb5e0fab4caf294e84fcecc277" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/uid/zipball/7c53913df24517eb5e0fab4caf294e84fcecc277", + "reference": "7c53913df24517eb5e0fab4caf294e84fcecc277", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/polyfill-uuid": "^1.15" + }, + "require-dev": { + "symfony/console": "^5.4|^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Uid\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Grégoire Pineau", + "email": "lyrixx@lyrixx.info" + }, + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides an object-oriented API to generate and represent UIDs", + "homepage": "https://symfony.com", + "keywords": [ + "UID", + "ulid", + "uuid" + ], + "support": { + "source": "https://github.com/symfony/uid/tree/v6.1.11" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-01-01T08:36:55+00:00" + }, { "name": "symfony/validator", "version": "v6.1.11", @@ -8387,6 +8635,53 @@ ], "time": "2023-01-10T18:53:01+00:00" }, + { + "name": "symfonycasts/reset-password-bundle", + "version": "v1.22.0", + "source": { + "type": "git", + "url": "https://github.com/SymfonyCasts/reset-password-bundle.git", + "reference": "d9cf4395c0a19a3093bc51b10f508b38f98117f5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/SymfonyCasts/reset-password-bundle/zipball/d9cf4395c0a19a3093bc51b10f508b38f98117f5", + "reference": "d9cf4395c0a19a3093bc51b10f508b38f98117f5", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": ">=8.1.10", + "symfony/config": "^5.4 | ^6.0 | ^7.0", + "symfony/dependency-injection": "^5.4 | ^6.0 | ^7.0", + "symfony/deprecation-contracts": "^2.2 | ^3.0", + "symfony/http-kernel": "^5.4 | ^6.0 | ^7.0" + }, + "require-dev": { + "doctrine/annotations": "^1.0", + "doctrine/doctrine-bundle": "^2.8", + "doctrine/orm": "^2.13", + "phpstan/phpstan": "^1.11.x-dev", + "symfony/framework-bundle": "^5.4 | ^6.0 | ^7.0", + "symfony/phpunit-bridge": "^5.4 | ^6.0 | ^7.0" + }, + "type": "symfony-bundle", + "autoload": { + "psr-4": { + "SymfonyCasts\\Bundle\\ResetPassword\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Symfony bundle that adds password reset functionality.", + "support": { + "issues": "https://github.com/SymfonyCasts/reset-password-bundle/issues", + "source": "https://github.com/SymfonyCasts/reset-password-bundle/tree/v1.22.0" + }, + "time": "2024-06-06T11:59:57+00:00" + }, { "name": "symfonycasts/verify-email-bundle", "version": "v1.17.0", diff --git a/config/bundles.php b/config/bundles.php index a479e797..6f19cff4 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -14,4 +14,6 @@ return [ SymfonyCasts\Bundle\VerifyEmail\SymfonyCastsVerifyEmailBundle::class => ['all' => true], Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true], + EasyCorp\Bundle\EasyAdminBundle\EasyAdminBundle::class => ['all' => true], + SymfonyCasts\Bundle\ResetPassword\SymfonyCastsResetPasswordBundle::class => ['all' => true], ]; diff --git a/config/packages/reset_password.yaml b/config/packages/reset_password.yaml new file mode 100644 index 00000000..bd37a3a5 --- /dev/null +++ b/config/packages/reset_password.yaml @@ -0,0 +1,5 @@ +symfonycasts_reset_password: + # Replace symfonycasts.reset_password.fake_request_repository with the full + # namespace of the password reset request repository after it has been created. + # i.e. App\Repository\ResetPasswordRequestRepository + request_password_repository: symfonycasts.reset_password.fake_request_repository diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 8f488e7f..00f4b098 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -52,7 +52,7 @@ security: # Easy way to control access for large sections of your site # Note: Only the *first* access control that matches will be used access_control: - - { path: ^/admin, roles: ROLE_ADMIN } +# - { path: ^/admin, roles: ROLE_ADMIN } - { path: ^/profile, roles: ROLE_USER } - { path: ^/account, roles: ROLE_USER } diff --git a/src/Controller/Admin/DashboardController.php b/src/Controller/Admin/DashboardController.php new file mode 100644 index 00000000..3e41c1b5 --- /dev/null +++ b/src/Controller/Admin/DashboardController.php @@ -0,0 +1,56 @@ +container->get(AdminUrlGenerator::class); + + // Option 1. Make your dashboard redirect to the same page for all users +// return $this->redirect($adminUrlGenerator->setController(UserCrudController::class)->generateUrl()); + + + // Option 2. You can make your dashboard redirect to different pages depending on the user + // + // if ('jane' === $this->getUser()->getUsername()) { + // return $this->redirect('...'); + // } + + // Option 3. You can render some custom template to display a proper dashboard with widgets, etc. + // (tip: it's easier if your template extends from @EasyAdmin/page/content.html.twig) + // + return $this->render('admin/dashboard.html.twig'); + } + + public function configureDashboard(): Dashboard + { + return Dashboard::new() + ->setTitle('Caisse'); + } + public function configureMenuItems(): iterable + { + return [ + MenuItem::linkToDashboard('Dashboard', 'fa fa-home'), + MenuItem::section('Users'), + MenuItem::linkToCrud('Users', 'fa fa-user', User::class), + ]; + } + + + +} diff --git a/src/Controller/Admin/UserCrudController.php b/src/Controller/Admin/UserCrudController.php new file mode 100644 index 00000000..8a8af08c --- /dev/null +++ b/src/Controller/Admin/UserCrudController.php @@ -0,0 +1,49 @@ +renderContentMaximized() + + // set this option if you prefer the sidebar (which contains the main menu) + // to be displayed as a narrow column instead of the default expanded design +// ->renderSidebarMinimized() + ; + } + public function configureMenuItems(): iterable + { + return[ + MenuItem::linkToCrud('Categories', 'fa fa-tags', Category::class), + MenuItem::section('Users'), + ]; + } + + public function configureFields(string $pageName): iterable + { + return [ + IdField::new('id'), + TextField::new('email'), + TextEditorField::new('description'), + TextEditorField::new('last_login'), + ]; + } +} diff --git a/src/DataFixtures/AppFixtures.php b/src/DataFixtures/AppFixtures.php index 987f6fe9..579269de 100644 --- a/src/DataFixtures/AppFixtures.php +++ b/src/DataFixtures/AppFixtures.php @@ -9,8 +9,17 @@ class AppFixtures extends Fixture { public function load(ObjectManager $manager): void { - // $product = new Product(); - // $manager->persist($product); + $product = new Product(); + + $product->setName('Un Livre d\'exemple'); + + $demo_user = new User(); + + $demo_user->setEmail('contact+admin@cipherbliss.com')->setRoles('ROLE_ADMIN')->addProduct($product); + + + $manager->persist($product); + $manager->persist($demo_user); $manager->flush(); } diff --git a/symfony.lock b/symfony.lock index 2180074b..63dd9029 100644 --- a/symfony.lock +++ b/symfony.lock @@ -38,6 +38,15 @@ "migrations/.gitignore" ] }, + "easycorp/easyadmin-bundle": { + "version": "4.10", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "3.0", + "ref": "b131e6cbfe1b898a508987851963fff485986285" + } + }, "phpstan/phpstan": { "version": "1.11", "recipe": { @@ -298,6 +307,18 @@ "webpack.config.js" ] }, + "symfonycasts/reset-password-bundle": { + "version": "1.22", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "1.0", + "ref": "97c1627c0384534997ae1047b93be517ca16de43" + }, + "files": [ + "config/packages/reset_password.yaml" + ] + }, "symfonycasts/verify-email-bundle": { "version": "v1.17.0" }, diff --git a/templates/admin/dashboard.html.twig b/templates/admin/dashboard.html.twig new file mode 100644 index 00000000..7ef8e713 --- /dev/null +++ b/templates/admin/dashboard.html.twig @@ -0,0 +1,7 @@ +{% extends '@EasyAdmin/layout.html.twig' %} + +{% block main %} + +

Coucou le dashboard

+ +{% endblock main %}