feat: integrate with easy admin bundle
This commit is contained in:
@@ -45,7 +45,7 @@ class BookingEditDraftCrudController extends AbstractCrudController
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
return [
|
||||
IntegerField::new('bookingId', 'Buchungs ID'),
|
||||
IntegerField::new('bookingNumber', 'Vorgang'),
|
||||
AssociationField::new('user', 'Kundenaccount')->formatValue(fn (User $user) => $user->getEmail()),
|
||||
DateTimeField::new('createdAt', 'erstellt am'),
|
||||
DateTimeField::new('updatedAt', 'aktualisiert am'),
|
||||
|
||||
@@ -8,8 +8,10 @@ use App\Entity\User;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Attribute\AdminDashboard;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\UserMenu;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
#[AdminDashboard(routePath: '/admin', routeName: 'admin')]
|
||||
class DashboardController extends AbstractDashboardController
|
||||
@@ -28,11 +30,19 @@ class DashboardController extends AbstractDashboardController
|
||||
;
|
||||
}
|
||||
|
||||
public function configureUserMenu(UserInterface $user): UserMenu
|
||||
{
|
||||
return parent::configureUserMenu($user)
|
||||
->addMenuItems([
|
||||
MenuItem::linkToRoute('MyE&P', 'fa fa-user', 'app_account')
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureMenuItems(): iterable
|
||||
{
|
||||
yield MenuItem::linkToDashboard('Dashboard', 'fa fa-home');
|
||||
yield MenuItem::linkToCrud('Log', 'fa fa-list', LogEntry::class);
|
||||
yield MenuItem::linkToCrud('Buchungsentwürfe', 'fa fa-pen-to-square', BookingEditDraft::class);
|
||||
yield MenuItem::linkToCrud('Kundenaccounts', 'fa fa-users', User::class);
|
||||
yield MenuItem::linkToCrud('Benutzeraccounts', 'fa fa-users', User::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\LogEntry;
|
||||
@@ -7,10 +9,7 @@ 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\ArrayField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||
|
||||
class LogEntryCrudController extends AbstractCrudController
|
||||
@@ -22,8 +21,14 @@ class LogEntryCrudController extends AbstractCrudController
|
||||
|
||||
public function configureActions(Actions $actions): Actions
|
||||
{
|
||||
$viewDumps = Action::new('viewDumps', 'XML Dumps', 'fa fa-file-code')
|
||||
->linkToRoute('admin_xml_dump_list', static fn (LogEntry $entity): array => ['id' => $entity->getId()])
|
||||
->displayIf(static fn (LogEntry $entity): bool => 'bpn' === $entity->getChannel());
|
||||
|
||||
return $actions
|
||||
->add(Crud::PAGE_INDEX, Action::DETAIL)
|
||||
->add(Crud::PAGE_INDEX, $viewDumps)
|
||||
->add(Crud::PAGE_DETAIL, $viewDumps)
|
||||
->remove(Crud::PAGE_INDEX, Action::NEW)
|
||||
->remove(Crud::PAGE_INDEX, Action::EDIT)
|
||||
->remove(Crud::PAGE_INDEX, Action::DELETE)
|
||||
@@ -45,8 +50,9 @@ class LogEntryCrudController extends AbstractCrudController
|
||||
return [
|
||||
DateTimeField::new('createdAt', 'Zeitstempel'),
|
||||
TextField::new('username', 'Benutzer'),
|
||||
TextField::new('requestId', 'Request ID'),
|
||||
TextField::new('message', 'Aktion'),
|
||||
TextField::new('requestId', 'Request ID'),
|
||||
TextField::new('uri', 'URI'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ class UserCrudController extends AbstractCrudController
|
||||
public function configureCrud(Crud $crud): Crud
|
||||
{
|
||||
return $crud
|
||||
->setEntityLabelInSingular('Kundenaccount')
|
||||
->setEntityLabelInPlural('Kundenaccounts')
|
||||
->setEntityLabelInSingular('Benutzeraccount')
|
||||
->setEntityLabelInPlural('Benutzeraccounts')
|
||||
->setDefaultSort(['lastLoginAt' => 'DESC']);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Repository\LogEntryRepository;
|
||||
use App\Service\XmlDumpService;
|
||||
use League\Flysystem\FilesystemException;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
#[Route('/admin/xml-dump')]
|
||||
#[IsGranted('ROLE_ADMIN')]
|
||||
class XmlDumpController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly XmlDumpService $xmlDumpService,
|
||||
private readonly LogEntryRepository $logEntryRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'admin_xml_dump_list', methods: ['GET'])]
|
||||
public function list(int $id): Response
|
||||
{
|
||||
$logEntry = $this->logEntryRepository->find($id);
|
||||
|
||||
if (null === $logEntry) {
|
||||
throw new NotFoundHttpException('Log entry not found.');
|
||||
}
|
||||
|
||||
if ('bpn' !== $logEntry->getChannel()) {
|
||||
throw new NotFoundHttpException('XML dumps are only available for BPN channel entries.');
|
||||
}
|
||||
|
||||
$requestId = $logEntry->getRequestId();
|
||||
$dumps = [];
|
||||
|
||||
try {
|
||||
$dumps = $this->xmlDumpService->findDumpsForRequestId($requestId);
|
||||
} catch (FilesystemException) {
|
||||
// Dumps directory may not exist or be inaccessible
|
||||
}
|
||||
|
||||
return $this->render('admin/xml_dump/list.html.twig', [
|
||||
'logEntry' => $logEntry,
|
||||
'requestId' => $requestId,
|
||||
'dumps' => $dumps,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/download/{filename}', name: 'admin_xml_dump_download', methods: ['GET'], requirements: ['filename' => '.+'])]
|
||||
public function download(string $filename): Response
|
||||
{
|
||||
try {
|
||||
if (false === $this->xmlDumpService->fileExists($filename)) {
|
||||
throw new NotFoundHttpException('Dump file not found. It may have been cleaned up.');
|
||||
}
|
||||
|
||||
$content = $this->xmlDumpService->getContent($filename);
|
||||
} catch (FilesystemException $e) {
|
||||
throw new NotFoundHttpException('Failed to read dump file: '.$e->getMessage());
|
||||
}
|
||||
|
||||
$response = new Response($content);
|
||||
$response->headers->set('Content-Type', 'application/xml');
|
||||
|
||||
$disposition = $response->headers->makeDisposition(
|
||||
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
|
||||
basename($filename)
|
||||
);
|
||||
$response->headers->set('Content-Disposition', $disposition);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user