diff --git a/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/query-search/index.html.twig b/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/query-search/index.html.twig deleted file mode 100644 index 303e586b7..000000000 --- a/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/query-search/index.html.twig +++ /dev/null @@ -1,23 +0,0 @@ -{% extends '@EMSAdminUI/bootstrap5/base/admin.html.twig' %} -{% trans_default_domain 'EMSCoreBundle' %} - -{% block title %}{{ 'query_search.index.title'|trans }}{% endblock %} -{% block pagetitle %}{{ block('title') }}{% endblock %} - -{% block breadcrumb %} -
-{% endblock %} - -{% block body %} - {% set toolbar %} - {{ add_label|default(form.vars.add_label)|trans }} - {% endset %} - - {% form_theme form '@EMSAdminUI/bootstrap5/form/forms.html.twig' %} - {{ form(form, { - reorder_label: 'query_search.index.reorder', - toolbar: toolbar - }) }} -{% endblock %} diff --git a/EMS/core-bundle/src/Controller/QuerySearchController.php b/EMS/core-bundle/src/Controller/QuerySearchController.php index 1651b4388..323a0dcee 100644 --- a/EMS/core-bundle/src/Controller/QuerySearchController.php +++ b/EMS/core-bundle/src/Controller/QuerySearchController.php @@ -4,25 +4,27 @@ namespace EMS\CoreBundle\Controller; +use EMS\CommonBundle\Contracts\Log\LocalizedLoggerInterface; use EMS\CoreBundle\Core\DataTable\DataTableFactory; use EMS\CoreBundle\DataTable\Type\QuerySearchDataTableType; use EMS\CoreBundle\Entity\QuerySearch; -use EMS\CoreBundle\Form\Data\EntityTable; +use EMS\CoreBundle\Form\Data\TableAbstract; use EMS\CoreBundle\Form\Form\QuerySearchType; use EMS\CoreBundle\Form\Form\TableType; use EMS\CoreBundle\Service\QuerySearchService; -use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\Form\Form; -use Symfony\Component\Form\SubmitButton; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use function Symfony\Component\Translation\t; + final class QuerySearchController extends AbstractController { + use CoreControllerTrait; + public function __construct( - private readonly LoggerInterface $logger, + private readonly LocalizedLoggerInterface $logger, private readonly QuerySearchService $querySearchService, private readonly DataTableFactory $dataTableFactory, private readonly string $templateNamespace @@ -33,30 +35,31 @@ public function index(Request $request): Response { $table = $this->dataTableFactory->create(QuerySearchDataTableType::class); - $form = $this->createForm(TableType::class, $table); + $form = $this->createForm(TableType::class, $table, [ + 'reorder_label' => t('type.reorder', ['type' => 'query_search'], 'emsco-core'), + ]); $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { - if ($form instanceof Form && ($action = $form->getClickedButton()) instanceof SubmitButton) { - switch ($action->getName()) { - case EntityTable::DELETE_ACTION: - $this->querySearchService->deleteByIds($table->getSelected()); - break; - case TableType::REORDER_ACTION: - $newOrder = TableType::getReorderedKeys($form->getName(), $request); - $this->querySearchService->reorderByIds($newOrder); - break; - default: - $this->logger->error('log.controller.query_search.unknown_action'); - } - } else { - $this->logger->error('log.controller.query_search.unknown_action'); - } + match ($this->getClickedButtonName($form)) { + TableAbstract::DELETE_ACTION => $this->querySearchService->deleteByIds($table->getSelected()), + TableType::REORDER_ACTION => $this->querySearchService->reorderByIds( + ids: TableType::getReorderedKeys($form->getName(), $request) + ), + default => $this->logger->messageError(t('log.error.invalid_table_action', [], 'emsco-core')) + }; return $this->redirectToRoute('ems_core_query_search_index'); } - return $this->render("@$this->templateNamespace/query-search/index.html.twig", [ + return $this->render("@$this->templateNamespace/crud/overview.html.twig", [ 'form' => $form->createView(), + 'icon' => 'fa fa-list-alt', + 'title' => t('admin.query_search.overview', [], 'emsco-core'), + 'breadcrumb' => [ + 'admin' => t('admin.label', [], 'emsco-core'), + 'page' => t('admin.query_search.plural', [], 'emsco-core'), + ], ]); } diff --git a/EMS/core-bundle/src/DataTable/Type/QuerySearchDataTableType.php b/EMS/core-bundle/src/DataTable/Type/QuerySearchDataTableType.php index 4036ff007..9d88c556e 100644 --- a/EMS/core-bundle/src/DataTable/Type/QuerySearchDataTableType.php +++ b/EMS/core-bundle/src/DataTable/Type/QuerySearchDataTableType.php @@ -10,6 +10,8 @@ use EMS\CoreBundle\Roles; use EMS\CoreBundle\Service\QuerySearchService; +use function Symfony\Component\Translation\t; + class QuerySearchDataTableType extends AbstractEntityTableType { public function __construct(QuerySearchService $entityService) @@ -19,12 +21,34 @@ public function __construct(QuerySearchService $entityService) public function build(EntityTable $table): void { - $table->addColumn('query_search.index.column.label', 'label'); - $table->addColumn('query_search.index.column.name', 'name'); - $table->addItemGetAction('ems_core_query_search_edit', 'query_search.actions.edit', 'pencil'); - $table->addItemPostAction('ems_core_query_search_delete', 'query_search.actions.delete', 'trash', 'query_search.actions.delete_confirm'); - $table->addTableAction(TableAbstract::DELETE_ACTION, 'fa fa-trash', 'query_search.actions.delete_selected', 'query_search.actions.delete_selected_confirm'); $table->setDefaultOrder('label'); + + $table->addColumn(t('field.label', [], 'emsco-core'), 'label'); + $table->addColumn(t('field.name', [], 'emsco-core'), 'name'); + + $table->addItemGetAction( + route: 'ems_core_query_search_edit', + labelKey: t('action.edit', [], 'emsco-core'), + icon: 'pencil' + ); + $table->addItemPostAction( + route: 'ems_core_query_search_delete', + labelKey: t('action.delete', [], 'emsco-core'), + icon: 'trash', + messageKey: t('type.delete_confirm', ['type' => 'query_search'], 'emsco-core') + )->setButtonType('outline-danger'); + + $table->addToolbarAction( + label: t('action.add', [], 'emsco-core'), + icon: 'fa fa-plus', + routeName: 'ems_core_query_search_add' + ); + $table->addTableAction( + name: TableAbstract::DELETE_ACTION, + icon: 'fa fa-trash', + labelKey: t('action.delete_selected', [], 'emsco-core'), + confirmationKey: t('type.delete_selected_confirm', ['type' => 'query_search'], 'emsco-core') + )->setCssClass('btn btn-outline-danger'); } public function getRoles(): array diff --git a/EMS/core-bundle/src/Resources/config/controllers.xml b/EMS/core-bundle/src/Resources/config/controllers.xml index 6031523c7..e09c8c9c4 100644 --- a/EMS/core-bundle/src/Resources/config/controllers.xml +++ b/EMS/core-bundle/src/Resources/config/controllers.xml @@ -544,7 +544,7 @@