add admin panel #20

Merged
csimonis merged 12 commits from feature/admin-panel into main 2025-02-09 14:59:31 +00:00
16 changed files with 1348 additions and 14 deletions
Showing only changes of commit 584901f413 - Show all commits

View File

@ -1,15 +1,15 @@
{
"controllers": {
"@symfony/ux-turbo": {
"turbo-core": {
"enabled": true,
"fetch": "eager"
},
"mercure-turbo-stream": {
"enabled": false,
"fetch": "eager"
}
}
},
"entrypoints": []
"controllers": {
"@symfony/ux-turbo": {
"turbo-core": {
"enabled": true,
"fetch": "eager"
},
"mercure-turbo-stream": {
"enabled": false,
"fetch": "eager"
}
}
},
"entrypoints": []
}

View File

@ -12,6 +12,7 @@
"doctrine/doctrine-bundle": "^2.13",
"doctrine/doctrine-migrations-bundle": "^3.4",
"doctrine/orm": "^3.3",
"easycorp/easyadmin-bundle": "^4.24",
"php-flasher/flasher-noty-symfony": "^2.1",
"phpdocumentor/reflection-docblock": "^5.6",
"stripe/stripe-php": "^16.4",

1050
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -15,4 +15,6 @@ return [
Symfony\UX\Turbo\TurboBundle::class => ['all' => true],
Symfony\UX\TwigComponent\TwigComponentBundle::class => ['all' => true],
Symfony\UX\Icons\UXIconsBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
EasyCorp\Bundle\EasyAdminBundle\EasyAdminBundle::class => ['all' => true],
];

View File

@ -0,0 +1,39 @@
security:
# https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
password_hashers:
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
providers:
users_in_memory: { memory: null }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
lazy: true
provider: users_in_memory
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#the-firewall
# https://symfony.com/doc/current/security/impersonating_user.html
# switch_user: true
# 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: ^/profile, roles: ROLE_USER }
when@test:
security:
password_hashers:
# By default, password hashers are resource intensive and take time. This is
# important to generate secure password hashes. In tests however, secure hashes
# are not important, waste resources and increase test times. The following
# reduces the work factor to the lowest possible values.
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
algorithm: auto
cost: 4 # Lowest possible value for bcrypt
time_cost: 3 # Lowest possible value for argon
memory_cost: 10 # Lowest possible value for argon

View File

@ -0,0 +1,7 @@
framework:
default_locale: en
translator:
default_path: '%kernel.project_dir%/translations'
fallbacks:
- en
providers:

View File

@ -0,0 +1,3 @@
_security_logout:
resource: security.route_loader.logout
type: service

View File

@ -0,0 +1,42 @@
<?php
namespace App\Controller\Admin;
use App\Entity\Customer;
use App\Entity\Payment;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
class CustomerCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Customer::class;
}
public function configureFields(string $pageName): iterable
{
yield TextField::new('firstname', 'Vorname');
yield TextField::new('lastname', 'Nachname');
yield TextField::new('email', 'E-Mail');
yield TextField::new('phone', 'Telefon');
yield AssociationField::new('payment', 'Zahlung')
->setCrudController(PaymentCrudController::class)
->formatValue(fn(?Payment $payment) => ($payment?->getTotal() ?? 'N/A') . ' €');
yield
}
public function configureActions(Actions $actions): Actions
{
return $actions
->add(Crud::PAGE_INDEX, Action::DETAIL)
->disable(Action::DELETE)
->disable(Action::NEW)
->disable(Action::EDIT);
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace App\Controller\Admin;
use App\Entity\Payment;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
class PaymentCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Payment::class;
}
public function configureFields(string $pageName): iterable
{
yield AssociationField::new('customer', 'Customer')
->setCrudController(CustomerCrudController::class)
->formatValue(fn($value, $payment) => $payment->getCustomer()->getEmail());
yield BooleanField::new('completed', 'Completed')->renderAsSwitch(false);
}
public function configureActions(Actions $actions): Actions
{
return $actions
->add(Crud::PAGE_INDEX, Action::DETAIL)
->disable(Action::DELETE)
->disable(Action::NEW)
->disable(Action::EDIT);
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace App\Controller\Admin;
use App\Entity\Customer;
use App\Entity\Ticket;
use App\Enum\FoodData;
use App\Enum\TicketData;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
class TicketCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Ticket::class;
}
public function configureFields(string $pageName): iterable
{
yield ChoiceField::new('type', 'Name')
->setChoices(TicketData::TYPES);
yield ChoiceField::new('foodType', 'Ernährung')
->setChoices(FoodData::TYPES);
yield AssociationField::new('customer', 'Kunde')
->setCrudController(CustomerCrudController::class)
->formatValue(fn(Customer $customer) => $customer->getEmail());
}
public function configureActions(Actions $actions): Actions
{
return $actions
->add(Crud::PAGE_INDEX, Action::DETAIL)
->disable(Action::DELETE)
->disable(Action::NEW)
->disable(Action::EDIT);
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace App\Controller\Admin;
use App\Entity\Customer;
use App\Entity\Payment;
use App\Entity\Ticket;
use EasyCorp\Bundle\EasyAdminBundle\Attribute\AdminDashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
#[AdminDashboard(routePath: '/admin', routeName: 'admin')]
class ViewController extends AbstractDashboardController
{
public function __construct(private AdminUrlGenerator $adminUrlGenerator)
{
}
#[Route('/admin', name: 'admin')]
public function index(): Response
{
return $this->redirect($this->adminUrlGenerator->setController(CustomerCrudController::class)->generateUrl());
}
public function configureDashboard(): Dashboard
{
return Dashboard::new()->setTitle('Abiball Admin Interface');
}
public function configureMenuItems(): iterable
{
yield MenuItem::linkToCrud('Customers', 'fa fa-users', Customer::class);
yield MenuItem::linkToCrud('Tickets', 'fa fa-ticket', Ticket::class);
yield MenuItem::linkToCrud('Payments', 'fa fa-money', Payment::class);
}
}

View File

@ -2,6 +2,7 @@
namespace App\Entity;
use App\Enum\TicketData;
use App\Repository\PaymentRepository;
use Doctrine\ORM\Mapping as ORM;
@ -63,4 +64,11 @@ class Payment
return $this;
}
public function getTotal(): float
{
return $this->customer->getTickets()->reduce(function (float $total, Ticket $ticket) {
return $total + TicketData::TICKET_DATA[$ticket->getType()]['price'];
}, 0);
}
}

12
src/Enum/FoodData.php Normal file
View File

@ -0,0 +1,12 @@
<?php
namespace App\Enum;
class FoodData
{
public const TYPES = [
'Mit Fleisch' => 1,
'Vegetarisch' => 2,
'Vegan' => 3,
];
}

View File

@ -22,4 +22,11 @@ class TicketData
'price' => 0,
],
];
public const TYPES = [
'Ticket' => 1,
'After-Show Ticket' => 2,
'Kind (6-12 Jahre)' => 3,
'Kind (0-6 Jahre)' => 4,
];
}

View File

@ -35,6 +35,15 @@
"migrations/.gitignore"
]
},
"easycorp/easyadmin-bundle": {
"version": "4.24",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "3.0",
"ref": "b131e6cbfe1b898a508987851963fff485986285"
}
},
"php-flasher/flasher-noty-symfony": {
"version": "v2.1.2"
},
@ -146,6 +155,19 @@
"config/routes.yaml"
]
},
"symfony/security-bundle": {
"version": "7.2",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "6.4",
"ref": "2ae08430db28c8eb4476605894296c82a642028f"
},
"files": [
"config/packages/security.yaml",
"config/routes/security.yaml"
]
},
"symfony/stimulus-bundle": {
"version": "2.22",
"recipe": {
@ -161,6 +183,19 @@
"assets/controllers/hello_controller.js"
]
},
"symfony/translation": {
"version": "7.2",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "6.3",
"ref": "e28e27f53663cc34f0be2837aba18e3a1bef8e7b"
},
"files": [
"config/packages/translation.yaml",
"translations/.gitignore"
]
},
"symfony/twig-bundle": {
"version": "7.2",
"recipe": {
@ -174,6 +209,15 @@
"templates/base.html.twig"
]
},
"symfony/uid": {
"version": "7.2",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "7.0",
"ref": "0df5844274d871b37fc3816c57a768ffc60a43a5"
}
},
"symfony/ux-icons": {
"version": "2.22",
"recipe": {

0
translations/.gitignore vendored Normal file
View File