From 45a388c344081493a6ca205e74164b0d83b9418a Mon Sep 17 00:00:00 2001 From: David mattei Date: Sun, 28 Jul 2024 09:53:47 +0200 Subject: [PATCH] refactor(datatable): jobs and extend dataTableTrait (#967) --- .../template_block_columns.html.twig | 9 ++ .../views/bootstrap5/form/fields.html.twig | 2 +- .../views/bootstrap5/form/forms.html.twig | 26 +++-- .../views/bootstrap5/job/index.html.twig | 95 ------------------ .../views/bootstrap5/schedule/index.html.twig | 16 --- .../ContentManagement/JobController.php | 61 +++++++----- .../src/Controller/Job/ScheduleController.php | 51 +++++----- .../DataTable/Type/ChannelDataTableType.php | 43 +++----- .../DataTable/Type/DashboardDataTableType.php | 39 ++------ .../src/DataTable/Type/DataTableTypeTrait.php | 58 +++++++++-- .../src/DataTable/Type/FormDataTableType.php | 37 ++----- .../DataTable/Type/Job/JobDataTableType.php | 75 ++++++++++++++ .../Type/Job/JobScheduleDataTableType.php | 63 ++++++++++++ .../Type/JobScheduleDataTableType.php | 43 -------- .../src/DataTable/Type/LogDataTableType.php | 18 +--- .../Type/Mapping/AnalyzerDataTableType.php | 31 ++---- .../Type/Mapping/FilterDataTableType.php | 35 ++----- .../Type/QuerySearchDataTableType.php | 31 ++---- .../Revision/RevisionDraftsDataTableType.php | 10 +- .../Revision/RevisionTrashDataTableType.php | 11 +-- .../UploadedAssetAdminDataTableType.php | 22 ++--- .../UploadedAssetDataTableType.php | 13 ++- .../src/Form/Data/TableAbstract.php | 14 ++- EMS/core-bundle/src/Form/Form/TableType.php | 2 +- .../src/Repository/JobRepository.php | 13 +++ .../src/Resources/config/controllers.xml | 6 +- .../src/Resources/config/datatable.xml | 7 +- .../Resources/config/routing/admin/job.xml | 10 +- .../translations/EMSCoreBundle.en.yml | 15 --- .../translations/emsco-core+intl-icu.en.yml | 22 +++++ .../Resources/translations/emsco-twigs.en.yml | 4 - .../template_block_columns.html.twig | 9 ++ .../src/Resources/views/form/forms.html.twig | 24 +++-- .../src/Resources/views/job/index.html.twig | 98 ------------------- .../Resources/views/schedule/index.html.twig | 16 --- EMS/core-bundle/src/Service/JobService.php | 8 ++ 36 files changed, 444 insertions(+), 593 deletions(-) create mode 100644 EMS/admin-ui-bundle/src/Resources/views/bootstrap5/datatable/template_block_columns.html.twig delete mode 100644 EMS/admin-ui-bundle/src/Resources/views/bootstrap5/job/index.html.twig delete mode 100644 EMS/admin-ui-bundle/src/Resources/views/bootstrap5/schedule/index.html.twig create mode 100644 EMS/core-bundle/src/DataTable/Type/Job/JobDataTableType.php create mode 100644 EMS/core-bundle/src/DataTable/Type/Job/JobScheduleDataTableType.php delete mode 100644 EMS/core-bundle/src/DataTable/Type/JobScheduleDataTableType.php create mode 100644 EMS/core-bundle/src/Resources/views/datatable/template_block_columns.html.twig delete mode 100644 EMS/core-bundle/src/Resources/views/job/index.html.twig delete mode 100644 EMS/core-bundle/src/Resources/views/schedule/index.html.twig diff --git a/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/datatable/template_block_columns.html.twig b/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/datatable/template_block_columns.html.twig new file mode 100644 index 000000000..898dd61c7 --- /dev/null +++ b/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/datatable/template_block_columns.html.twig @@ -0,0 +1,9 @@ +{% block jobStatus %} + {% set p = line.data.progress %} +
+
+ {{ "#{p}%" }} +
+
+
{{ line.data.status }}
+{% endblock jobStatus %} diff --git a/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/form/fields.html.twig b/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/form/fields.html.twig index fae512712..7cf133774 100644 --- a/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/form/fields.html.twig +++ b/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/form/fields.html.twig @@ -138,7 +138,7 @@ {%- endif -%} {%- endif -%} {% if confirm is defined and confirm != null %} -
+
{% endif %} @@ -360,24 +360,22 @@ {% if table.supportsTableActions or toolbar is defined %} {% endif %}
@@ -407,8 +405,8 @@
diff --git a/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/job/index.html.twig b/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/job/index.html.twig deleted file mode 100644 index 8243aba07..000000000 --- a/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/job/index.html.twig +++ /dev/null @@ -1,95 +0,0 @@ -{% extends '@EMSAdminUI/bootstrap5/base/admin.html.twig' %}{% trans_default_domain 'EMSCoreBundle' %} - -{% block title %}Job's list{% endblock %} -{% block pagetitle %}Job's list{% endblock %} -{% block subtitle %}Running process{% endblock %} - - -{% block body %} -
-
-
-
- -

Jobs

-
- {% include '@EMSAdminUI/bootstrap5/elements/get-button.html.twig' with { - 'url': path('job.add'), - 'label': 'New job', - 'icon': 'plus' - }%} - {% include '@EMSAdminUI/bootstrap5/elements/post-button.html.twig' with { - 'url': path('job.clean'), - 'message': 'Clean done jobs ?', - 'label': 'Clean', - 'icon': 'trash' - }%} -
- -
- -
-
- - - - - - - - - - - - {% for job in jobs %} - - - - - - - - - - {% endfor %} - -
#StartedLast updateCommandTagStatusAction
{{ from+loop.index }}{{ job.created|date(date_time_format) }}{{ job.modified|date(date_time_format) }}{{ job.command }}{{ job.tag }} -
- {{ job.status }} - {{ job.progress }}/100 - -
-
-
-
-
-
- {% include '@EMSAdminUI/bootstrap5/elements/get-button.html.twig' with { - 'url': path('job.status', {'job': job.id}), - 'label': 'Status', - 'icon': 'eye' - }%} - {% include '@EMSAdminUI/bootstrap5/elements/post-button.html.twig' with { - 'url': path('job.delete', {'job': job.id}), - 'message': 'Do you confirm ?', - 'label': 'Delete', - 'icon': 'trash' - }%} -
-
-
-
- - -
-
-
-{% endblock %} diff --git a/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/schedule/index.html.twig b/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/schedule/index.html.twig deleted file mode 100644 index e87899584..000000000 --- a/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/schedule/index.html.twig +++ /dev/null @@ -1,16 +0,0 @@ -{% extends '@EMSAdminUI/bootstrap5/schedule/abstract.html.twig' %} -{% trans_default_domain 'emsco-twigs' %} - -{% block title %}{{ 'schedule.index.title'|trans }}{% endblock %} - -{% block body %} - {% set toolbar %} - {{ 'schedule.index.add_button'|trans }} - {% endset %} - - {% form_theme form '@EMSAdminUI/bootstrap5/form/forms.html.twig' %} - {{ form(form, { - reorder_label: 'schedule.index.reorder', - toolbar: toolbar - }) }} -{% endblock %} diff --git a/EMS/core-bundle/src/Controller/ContentManagement/JobController.php b/EMS/core-bundle/src/Controller/ContentManagement/JobController.php index 1abe3bc49..d2c8f352c 100644 --- a/EMS/core-bundle/src/Controller/ContentManagement/JobController.php +++ b/EMS/core-bundle/src/Controller/ContentManagement/JobController.php @@ -2,13 +2,18 @@ namespace EMS\CoreBundle\Controller\ContentManagement; +use EMS\CommonBundle\Contracts\Log\LocalizedLoggerInterface; use EMS\CommonBundle\Helper\Text\Encoder; +use EMS\CoreBundle\Controller\CoreControllerTrait; +use EMS\CoreBundle\Core\DataTable\DataTableFactory; +use EMS\CoreBundle\DataTable\Type\Job\JobDataTableType; use EMS\CoreBundle\Entity\Job; +use EMS\CoreBundle\Form\Data\TableAbstract; use EMS\CoreBundle\Form\Form\JobType; +use EMS\CoreBundle\Form\Form\TableType; use EMS\CoreBundle\Helper\EmsCoreResponse; use EMS\CoreBundle\Service\JobService; use EMS\Helpers\Standard\Json; -use Psr\Log\LoggerInterface; use SensioLabs\AnsiConverter\AnsiToHtmlConverter; use SensioLabs\AnsiConverter\Theme\Theme; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -20,12 +25,16 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\Security\Core\User\UserInterface; +use function Symfony\Component\Translation\t; + class JobController extends AbstractController { + use CoreControllerTrait; + public function __construct( - private readonly LoggerInterface $logger, private readonly JobService $jobService, - private readonly int $pagingSize, + private readonly DataTableFactory $dataTableFactory, + private readonly LocalizedLoggerInterface $logger, private readonly bool $triggerJobFromWeb, private readonly string $templateNamespace ) { @@ -33,19 +42,30 @@ public function __construct( public function index(Request $request): Response { - $size = $this->pagingSize; - $page = $request->query->getInt('page', 1); - $from = ($page - 1) * $size; - $total = $this->jobService->count(); - $lastPage = \ceil($total / $size); - - return $this->render("@$this->templateNamespace/job/index.html.twig", [ - 'jobs' => $this->jobService->scroll($size, $from), - 'page' => $page, - 'size' => $size, - 'from' => $from, - 'lastPage' => $lastPage, - 'paginationPath' => 'job.index', + $table = $this->dataTableFactory->create(JobDataTableType::class); + $form = $this->createForm(TableType::class, $table); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + match ($this->getClickedButtonName($form)) { + TableAbstract::DELETE_ACTION => $this->jobService->deleteByIds(...$table->getSelected()), + JobDataTableType::ACTION_CLEAN => $this->jobService->clean(), + default => $this->logger->messageError(t('log.error.invalid_table_action', [], 'emsco-core')) + }; + + return $this->redirectToRoute('job.index'); + } + + return $this->render("@$this->templateNamespace/crud/overview.html.twig", [ + 'form' => $form->createView(), + 'icon' => 'fa fa-file-text-o', + 'title' => t('type.title_overview', ['type' => 'job'], 'emsco-core'), + 'subTitle' => t('type.title_sub', ['type' => 'job'], 'emsco-core'), + 'breadcrumb' => [ + 'admin' => t('key.admin', [], 'emsco-core'), + 'jobs' => t('key.jobs', [], 'emsco-core'), + 'page' => t('key.job_logs', [], 'emsco-core'), + ], ]); } @@ -96,16 +116,9 @@ public function delete(Job $job): RedirectResponse return $this->redirectToRoute('job.index'); } - public function clean(): RedirectResponse - { - $this->jobService->clean(); - - return $this->redirectToRoute('job.index'); - } - public function startJob(Job $job, Request $request, UserInterface $user): Response { - if ($job->getUser() != $user->getUserIdentifier()) { + if ($job->getUser() !== $user->getUserIdentifier()) { throw new AccessDeniedHttpException(); } diff --git a/EMS/core-bundle/src/Controller/Job/ScheduleController.php b/EMS/core-bundle/src/Controller/Job/ScheduleController.php index 3e7ac362a..3b11a65b1 100644 --- a/EMS/core-bundle/src/Controller/Job/ScheduleController.php +++ b/EMS/core-bundle/src/Controller/Job/ScheduleController.php @@ -4,27 +4,30 @@ namespace EMS\CoreBundle\Controller\Job; +use EMS\CommonBundle\Contracts\Log\LocalizedLoggerInterface; +use EMS\CoreBundle\Controller\CoreControllerTrait; use EMS\CoreBundle\Core\DataTable\DataTableFactory; use EMS\CoreBundle\Core\Job\ScheduleManager; -use EMS\CoreBundle\DataTable\Type\JobScheduleDataTableType; +use EMS\CoreBundle\DataTable\Type\Job\JobScheduleDataTableType; use EMS\CoreBundle\Entity\Schedule; -use EMS\CoreBundle\Form\Data\EntityTable; +use EMS\CoreBundle\Form\Data\TableAbstract; use EMS\CoreBundle\Form\Form\ScheduleType; use EMS\CoreBundle\Form\Form\TableType; use EMS\CoreBundle\Routes; -use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\Form\Form; -use Symfony\Component\Form\SubmitButton; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use function Symfony\Component\Translation\t; + final class ScheduleController extends AbstractController { + use CoreControllerTrait; + public function __construct( private readonly ScheduleManager $scheduleManager, - private readonly LoggerInterface $logger, private readonly DataTableFactory $dataTableFactory, + private readonly LocalizedLoggerInterface $logger, private readonly string $templateNamespace ) { } @@ -32,31 +35,33 @@ public function __construct( public function index(Request $request): Response { $table = $this->dataTableFactory->create(JobScheduleDataTableType::class); + $form = $this->createForm(TableType::class, $table, [ + 'reorder_label' => t('type.reorder', ['type' => 'job_schedule'], 'emsco-core'), + ]); - $form = $this->createForm(TableType::class, $table); $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->scheduleManager->deleteByIds($table->getSelected()); - break; - case TableType::REORDER_ACTION: - $newOrder = TableType::getReorderedKeys($form->getName(), $request); - $this->scheduleManager->reorderByIds($newOrder); - break; - default: - $this->logger->error('log.controller.schedule.unknown_action'); - } - } else { - $this->logger->error('log.controller.schedule.unknown_action'); - } + match ($this->getClickedButtonName($form)) { + TableAbstract::DELETE_ACTION => $this->scheduleManager->deleteByIds($table->getSelected()), + TableType::REORDER_ACTION => $this->scheduleManager->reorderByIds( + ids: TableType::getReorderedKeys($form->getName(), $request) + ), + default => $this->logger->messageError(t('log.error.invalid_table_action', [], 'emsco-core')) + }; return $this->redirectToRoute(Routes::SCHEDULE_INDEX); } - return $this->render("@$this->templateNamespace/schedule/index.html.twig", [ + return $this->render("@$this->templateNamespace/crud/overview.html.twig", [ 'form' => $form->createView(), + 'icon' => 'fa fa-calendar-o', + 'title' => t('type.title_overview', ['type' => 'job_schedule'], 'emsco-core'), + 'subTitle' => t('type.title_sub', ['type' => 'job_schedule'], 'emsco-core'), + 'breadcrumb' => [ + 'admin' => t('key.admin', [], 'emsco-core'), + 'jobs' => t('key.jobs', [], 'emsco-core'), + 'page' => t('key.schedule', [], 'emsco-core'), + ], ]); } diff --git a/EMS/core-bundle/src/DataTable/Type/ChannelDataTableType.php b/EMS/core-bundle/src/DataTable/Type/ChannelDataTableType.php index 56337deab..588c15465 100644 --- a/EMS/core-bundle/src/DataTable/Type/ChannelDataTableType.php +++ b/EMS/core-bundle/src/DataTable/Type/ChannelDataTableType.php @@ -8,7 +8,6 @@ use EMS\CoreBundle\Entity\Channel; use EMS\CoreBundle\Form\Data\BoolTableColumn; use EMS\CoreBundle\Form\Data\EntityTable; -use EMS\CoreBundle\Form\Data\TableAbstract; use EMS\CoreBundle\Roles; use EMS\CoreBundle\Service\Channel\ChannelService; @@ -16,6 +15,8 @@ class ChannelDataTableType extends AbstractEntityTableType { + use DataTableTypeTrait; + public function __construct(ChannelService $entityService) { parent::__construct($entityService); @@ -23,40 +24,20 @@ public function __construct(ChannelService $entityService) public function build(EntityTable $table): void { - $table->setDefaultOrder('orderKey')->setLabelAttribute('label'); - - $table->addColumn(t('key.loop_count', [], 'emsco-core'), 'orderKey'); - $table->addColumn(t('field.label', [], 'emsco-core'), 'label'); - - $column = $table->addColumn(t('field.name', [], 'emsco-core'), 'name'); - $column->setPathCallback(fn (Channel $channel, string $baseUrl = '') => $baseUrl.$channel->getEntryPath(), '_blank'); + $this->addColumnsOrderLabelName($table); + $table->getColumnByName('name')?->setPathCallback( + pathCallback: fn (Channel $channel, string $baseUrl = '') => $baseUrl.$channel->getEntryPath(), + target: '_blank' + ); $table->addColumn(t('field.alias', [], 'emsco-core'), 'alias'); $table->addColumnDefinition(new BoolTableColumn(t('field.public_access', [], 'emsco-core'), 'public')); - $table->addItemGetAction( - route: 'ems_core_channel_edit', - labelKey: t('action.edit', [], 'emsco-core'), - icon: 'pencil' - ); - $table->addItemPostAction( - route: 'ems_core_channel_delete', - labelKey: t('action.delete', [], 'emsco-core'), - icon: 'trash', - messageKey: t('type.delete_confirm', ['type' => 'channel'], 'emsco-core') - )->setButtonType('outline-danger'); - - $table->addToolbarAction( - label: t('action.add', [], 'emsco-core'), - icon: 'fa fa-plus', - routeName: 'ems_core_channel_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' => 'channel'], 'emsco-core') - )->setCssClass('btn btn-outline-danger'); + $this + ->addItemEdit($table, 'ems_core_channel_edit') + ->addItemDelete($table, 'channel', 'ems_core_channel_delete') + ->addTableToolbarActionAdd($table, 'ems_core_channel_add') + ->addTableActionDelete($table, 'channel'); } public function getRoles(): array diff --git a/EMS/core-bundle/src/DataTable/Type/DashboardDataTableType.php b/EMS/core-bundle/src/DataTable/Type/DashboardDataTableType.php index 6d9a7fa80..e73be35d5 100644 --- a/EMS/core-bundle/src/DataTable/Type/DashboardDataTableType.php +++ b/EMS/core-bundle/src/DataTable/Type/DashboardDataTableType.php @@ -9,7 +9,6 @@ use EMS\CoreBundle\Core\DataTable\Type\AbstractEntityTableType; use EMS\CoreBundle\Entity\Dashboard; use EMS\CoreBundle\Form\Data\EntityTable; -use EMS\CoreBundle\Form\Data\TableAbstract; use EMS\CoreBundle\Form\Data\TemplateBlockTableColumn; use EMS\CoreBundle\Roles; use EMS\CoreBundle\Routes; @@ -18,6 +17,8 @@ class DashboardDataTableType extends AbstractEntityTableType { + use DataTableTypeTrait; + public function __construct(DashboardManager $entityService, private readonly string $templateNamespace) { parent::__construct($entityService); @@ -25,12 +26,8 @@ public function __construct(DashboardManager $entityService, private readonly st public function build(EntityTable $table): void { - $table->setDefaultOrder('orderKey')->setLabelAttribute('label'); - - $table->addColumn(t('key.loop_count', [], 'emsco-core'), 'orderKey'); - $columnLabel = $table->addColumn(t('field.label', [], 'emsco-core'), 'label'); - $columnLabel->setItemIconCallback(fn (Dashboard $dashboard) => $dashboard->getIcon()); - $table->addColumn(t('field.name', [], 'emsco-core'), 'name'); + $this->addColumnsOrderLabelName($table); + $table->getColumnByName('label')?->setItemIconCallback(fn (Dashboard $dashboard) => $dashboard->getIcon()); $table->addColumnDefinition(new TemplateBlockTableColumn( label: t('field.type', [], 'emsco-core'), @@ -43,11 +40,7 @@ public function build(EntityTable $table): void template: "@$this->templateNamespace/dashboard/columns.html.twig") ); - $table->addItemGetAction( - route: Routes::DASHBOARD_ADMIN_EDIT, - labelKey: t('action.edit', [], 'emsco-core'), - icon: 'pencil' - ); + $this->addItemEdit($table, Routes::DASHBOARD_ADMIN_EDIT); $defineAction = $table->addItemActionCollection(t('action.define', [], 'emsco-core'), 'gear'); foreach (DashboardDefinition::cases() as $dashboardDefinition) { @@ -64,24 +57,10 @@ public function build(EntityTable $table): void icon: 'eraser' ); - $table->addItemPostAction( - route: Routes::DASHBOARD_ADMIN_DELETE, - labelKey: t('action.delete', [], 'emsco-core'), - icon: 'trash', - messageKey: t('type.delete_confirm', ['type' => 'dashboard'], 'emsco-core') - )->setButtonType('outline-danger'); - - $table->addToolbarAction( - label: t('action.add', [], 'emsco-core'), - icon: 'fa fa-plus', - routeName: Routes::DASHBOARD_ADMIN_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' => 'dashboard'], 'emsco-core') - )->setCssClass('btn btn-outline-danger'); + $this + ->addItemDelete($table, 'dashboard', Routes::DASHBOARD_ADMIN_DELETE) + ->addTableToolbarActionAdd($table, Routes::DASHBOARD_ADMIN_ADD) + ->addTableActionDelete($table, 'dashboard'); } public function getRoles(): array diff --git a/EMS/core-bundle/src/DataTable/Type/DataTableTypeTrait.php b/EMS/core-bundle/src/DataTable/Type/DataTableTypeTrait.php index 778d3e23f..cbaa39f45 100644 --- a/EMS/core-bundle/src/DataTable/Type/DataTableTypeTrait.php +++ b/EMS/core-bundle/src/DataTable/Type/DataTableTypeTrait.php @@ -10,14 +10,60 @@ trait DataTableTypeTrait { - public function addColumnsOrderLabelName(TableAbstract $table): void + public function addColumnsOrderLabelName(TableAbstract $table): self { - $table - ->setDefaultOrder('orderKey') - ->setLabelAttribute('label'); + $table->setDefaultOrder('orderKey')->setLabelAttribute('label'); $table->addColumn(t('key.loop_count', [], 'emsco-core'), 'orderKey'); - $table->addColumn(t('field.label', [], 'emsco-core'), 'label'); - $table->addColumn(t('field.name', [], 'emsco-core'), 'name'); + $table->addColumn(t('field.label', [], 'emsco-core'), 'label', 'label'); + $table->addColumn(t('field.name', [], 'emsco-core'), 'name', 'name'); + + return $this; + } + + public function addItemEdit(TableAbstract $table, string $route): self + { + $table->addItemGetAction( + route: $route, + labelKey: t('action.edit', [], 'emsco-core'), + icon: 'pencil' + )->setButtonType('primary'); + + return $this; + } + + public function addItemDelete(TableAbstract $table, string $type, string $route): self + { + $table->addItemPostAction( + route: $route, + labelKey: t('action.delete', [], 'emsco-core'), + icon: 'trash', + messageKey: t('type.delete_confirm', ['type' => $type], 'emsco-core') + )->setButtonType('outline-danger'); + + return $this; + } + + public function addTableToolbarActionAdd(TableAbstract $table, string $route): self + { + $table->addToolbarAction( + label: t('action.add', [], 'emsco-core'), + icon: 'fa fa-plus', + routeName: $route + )->setCssClass('btn btn-sm btn-primary'); + + return $this; + } + + public function addTableActionDelete(TableAbstract $table, string $type, string $name = TableAbstract::DELETE_ACTION): self + { + $table->addTableAction( + name: $name, + icon: 'fa fa-trash', + labelKey: t('action.delete_selected', [], 'emsco-core'), + confirmationKey: t('type.delete_selected_confirm', ['type' => $type], 'emsco-core') + )->setCssClass('btn btn-sm btn-outline-danger'); + + return $this; } } diff --git a/EMS/core-bundle/src/DataTable/Type/FormDataTableType.php b/EMS/core-bundle/src/DataTable/Type/FormDataTableType.php index b61d119f8..501fcc992 100644 --- a/EMS/core-bundle/src/DataTable/Type/FormDataTableType.php +++ b/EMS/core-bundle/src/DataTable/Type/FormDataTableType.php @@ -7,7 +7,6 @@ use EMS\CoreBundle\Core\DataTable\Type\AbstractEntityTableType; use EMS\CoreBundle\Core\Form\FormManager; use EMS\CoreBundle\Form\Data\EntityTable; -use EMS\CoreBundle\Form\Data\TableAbstract; use EMS\CoreBundle\Roles; use EMS\CoreBundle\Routes; @@ -15,6 +14,8 @@ class FormDataTableType extends AbstractEntityTableType { + use DataTableTypeTrait; + public function __construct(FormManager $entityService) { parent::__construct($entityService); @@ -22,40 +23,20 @@ public function __construct(FormManager $entityService) public function build(EntityTable $table): void { - $table->setDefaultOrder('orderKey')->setLabelAttribute('label'); - - $table->addColumn(t('key.loop_count', [], 'emsco-core'), 'orderKey'); - $table->addColumn(t('field.label', [], 'emsco-core'), 'label'); - $table->addColumn(t('field.name', [], 'emsco-core'), 'name'); + $this + ->addColumnsOrderLabelName($table) + ->addItemEdit($table, Routes::FORM_ADMIN_EDIT); - $table->addItemGetAction( - route: Routes::FORM_ADMIN_EDIT, - labelKey: t('action.edit', [], 'emsco-core'), - icon: 'pencil' - ); $table->addItemGetAction( route: Routes::FORM_ADMIN_REORDER, labelKey: t('action.reorder', [], 'emsco-core'), icon: 'reorder' ); - $table->addItemPostAction( - route: Routes::FORM_ADMIN_DELETE, - labelKey: t('action.delete', [], 'emsco-core'), - icon: 'trash', - messageKey: t('type.delete_confirm', ['type' => 'form'], 'emsco-core') - )->setButtonType('outline-danger'); - $table->addToolbarAction( - label: t('action.add', [], 'emsco-core'), - icon: 'fa fa-plus', - routeName: Routes::FORM_ADMIN_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' => 'form'], 'emsco-core') - )->setCssClass('btn btn-outline-danger'); + $this + ->addItemDelete($table, 'form', Routes::FORM_ADMIN_DELETE) + ->addTableToolbarActionAdd($table, Routes::FORM_ADMIN_ADD) + ->addTableActionDelete($table, 'form'); } public function getRoles(): array diff --git a/EMS/core-bundle/src/DataTable/Type/Job/JobDataTableType.php b/EMS/core-bundle/src/DataTable/Type/Job/JobDataTableType.php new file mode 100644 index 000000000..48cdf7446 --- /dev/null +++ b/EMS/core-bundle/src/DataTable/Type/Job/JobDataTableType.php @@ -0,0 +1,75 @@ +setLabelAttribute('id'); + + $table->addColumnDefinition(new DatetimeTableColumn( + titleKey: t('field.date_created', [], 'emsco-core'), + attribute: 'created' + )); + $table->addColumnDefinition(new DatetimeTableColumn( + titleKey: t('field.date_modified', [], 'emsco-core'), + attribute: 'modified' + )); + + $table->addColumn(t('field.command', [], 'emsco-core'), 'command'); + $table->addColumn(t('field.tag', [], 'emsco-core'), 'tag'); + + $table->addColumnDefinition(new TemplateBlockTableColumn( + label: t('field.status', [], 'emsco-core'), + blockName: 'jobStatus', + template: "@$this->templateNamespace/datatable/template_block_columns.html.twig", + orderField: 'progress' + )); + + $table->addItemGetAction( + route: 'emsco_job_status', + labelKey: t('action.status', [], 'emsco-core'), + icon: 'eye' + ); + + $this + ->addItemDelete($table, 'job', 'job.delete') + ->addTableToolbarActionAdd($table, 'job.add') + ->addTableActionDelete($table, 'job'); + + $table->addTableAction( + name: self::ACTION_CLEAN, + icon: 'fa fa-eraser', + labelKey: t('action.clean', [], 'emsco-core'), + confirmationKey: t('action.confirmation', [], 'emsco-core') + )->setCssClass('btn btn-sm btn-default'); + } + + public function getRoles(): array + { + return [Roles::ROLE_ADMIN]; + } +} diff --git a/EMS/core-bundle/src/DataTable/Type/Job/JobScheduleDataTableType.php b/EMS/core-bundle/src/DataTable/Type/Job/JobScheduleDataTableType.php new file mode 100644 index 000000000..3b753738d --- /dev/null +++ b/EMS/core-bundle/src/DataTable/Type/Job/JobScheduleDataTableType.php @@ -0,0 +1,63 @@ +setDefaultOrder('orderKey'); + + $table->addColumn(t('key.loop_count', [], 'emsco-core'), 'orderKey'); + $table->addColumn(t('field.name', [], 'emsco-core'), 'name'); + $table->addColumn(t('field.cron', [], 'emsco-core'), 'cron'); + $table->addColumn(t('field.command', [], 'emsco-core'), 'command'); + $table->addColumn(t('field.tag', [], 'emsco-core'), 'tag'); + + $table->addColumnDefinition(new DatetimeTableColumn( + titleKey: t('field.date_run_previous', [], 'emsco-core'), + attribute: 'previousRun' + )); + $table->addColumnDefinition(new DatetimeTableColumn( + titleKey: t('field.date_run_next', [], 'emsco-core'), + attribute: 'nextRun' + )); + + $this->addItemEdit($table, Routes::SCHEDULE_EDIT); + $table->addItemPostAction( + route: Routes::SCHEDULE_DUPLICATE, + labelKey: t('action.duplicate', [], 'emsco-core'), + icon: 'files-o', + messageKey: t('action.confirmation', [], 'emsco-core') + ); + + $this + ->addItemDelete($table, 'job_schedule', Routes::SCHEDULE_DELETE) + ->addTableToolbarActionAdd($table, Routes::SCHEDULE_ADD) + ->addTableActionDelete($table, 'job_schedule'); + } + + public function getRoles(): array + { + return [Roles::ROLE_ADMIN]; + } +} diff --git a/EMS/core-bundle/src/DataTable/Type/JobScheduleDataTableType.php b/EMS/core-bundle/src/DataTable/Type/JobScheduleDataTableType.php deleted file mode 100644 index b403f3587..000000000 --- a/EMS/core-bundle/src/DataTable/Type/JobScheduleDataTableType.php +++ /dev/null @@ -1,43 +0,0 @@ -addColumn('table.index.column.loop_count', 'orderKey'); - $table->addColumn('schedule.index.column.name', 'name'); - $table->addColumn('schedule.index.column.cron', 'cron'); - $table->addColumn('schedule.index.column.command', 'command'); - $table->addColumn('schedule.index.column.tag', 'tag'); - $table->addColumnDefinition(new DatetimeTableColumn('schedule.index.column.previous-run', 'previousRun')); - $table->addColumnDefinition(new DatetimeTableColumn('schedule.index.column.next-run', 'nextRun')); - $table->addItemGetAction(Routes::SCHEDULE_EDIT, 'view.actions.edit', 'pencil'); - $table->addItemPostAction(Routes::SCHEDULE_DUPLICATE, 'view.actions.duplicate', 'pencil', 'view.actions.duplicate_confirm'); - $table->addItemPostAction(Routes::SCHEDULE_DELETE, 'view.actions.delete', 'trash', 'view.actions.delete_confirm')->setButtonType('outline-danger'); - $table->addTableAction(TableAbstract::DELETE_ACTION, 'fa fa-trash', 'schedule.actions.delete_selected', 'schedule.actions.delete_selected_confirm') - ->setCssClass('btn btn-outline-danger'); - $table->setDefaultOrder('orderKey'); - } - - public function getRoles(): array - { - return [Roles::ROLE_ADMIN]; - } -} diff --git a/EMS/core-bundle/src/DataTable/Type/LogDataTableType.php b/EMS/core-bundle/src/DataTable/Type/LogDataTableType.php index 9e8954cb9..1d109a55b 100644 --- a/EMS/core-bundle/src/DataTable/Type/LogDataTableType.php +++ b/EMS/core-bundle/src/DataTable/Type/LogDataTableType.php @@ -9,7 +9,6 @@ use EMS\CoreBundle\Core\Log\LogManager; use EMS\CoreBundle\Form\Data\DatetimeTableColumn; use EMS\CoreBundle\Form\Data\EntityTable; -use EMS\CoreBundle\Form\Data\TableAbstract; use EMS\CoreBundle\Form\Data\UserTableColumn; use EMS\CoreBundle\Roles; use EMS\CoreBundle\Routes; @@ -18,6 +17,8 @@ class LogDataTableType extends AbstractEntityTableType { + use DataTableTypeTrait; + public function __construct(LogManager $logManager) { parent::__construct($logManager); @@ -62,19 +63,10 @@ public function build(EntityTable $table): void labelKey: t('action.details', [], 'emsco-core'), icon: 'eye' ); - $table->addItemPostAction( - route: Routes::LOG_DELETE, - labelKey: t('action.delete', [], 'emsco-core'), - icon: 'trash', - messageKey: t('type.delete_confirm', ['type' => 'log'], 'emsco-core') - )->setButtonType('outline-danger'); - $table->addTableAction( - name: TableAbstract::DELETE_ACTION, - icon: 'fa fa-trash', - labelKey: t('action.delete_selected', [], 'emsco-core'), - confirmationKey: t('type.delete_selected_confirm', ['type' => 'log'], 'emsco-core') - )->setCssClass('btn btn-outline-danger'); + $this + ->addItemDelete($table, 'log', Routes::LOG_DELETE) + ->addTableActionDelete($table, 'log'); } public function getRoles(): array diff --git a/EMS/core-bundle/src/DataTable/Type/Mapping/AnalyzerDataTableType.php b/EMS/core-bundle/src/DataTable/Type/Mapping/AnalyzerDataTableType.php index e58b50415..d06d6e469 100644 --- a/EMS/core-bundle/src/DataTable/Type/Mapping/AnalyzerDataTableType.php +++ b/EMS/core-bundle/src/DataTable/Type/Mapping/AnalyzerDataTableType.php @@ -8,7 +8,6 @@ use EMS\CoreBundle\Core\Mapping\AnalyzerManager; use EMS\CoreBundle\DataTable\Type\DataTableTypeTrait; use EMS\CoreBundle\Form\Data\EntityTable; -use EMS\CoreBundle\Form\Data\TableAbstract; use EMS\CoreBundle\Roles; use EMS\CoreBundle\Routes; @@ -25,36 +24,20 @@ public function __construct(AnalyzerManager $analyzerManager) public function build(EntityTable $table): void { - $this->addColumnsOrderLabelName($table); + $this + ->addColumnsOrderLabelName($table) + ->addItemEdit($table, Routes::ANALYZER_EDIT); - $table->addItemGetAction( - route: Routes::ANALYZER_EDIT, - labelKey: t('action.edit', [], 'emsco-core'), - icon: 'pencil' - ); $table->addItemGetAction( route: Routes::ANALYZER_EXPORT, labelKey: t('action.export', [], 'emsco-core'), icon: 'sign-out' ); - $table->addItemPostAction( - route: Routes::ANALYZER_DELETE, - labelKey: t('action.delete', [], 'emsco-core'), - icon: 'trash', - messageKey: t('type.delete_confirm', ['type' => 'analyzer'], 'emsco-core') - )->setButtonType('outline-danger'); - $table->addToolbarAction( - label: t('action.add', [], 'emsco-core'), - icon: 'fa fa-plus', - routeName: Routes::ANALYZER_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' => 'analyzer'], 'emsco-core') - )->setCssClass('btn btn-outline-danger'); + $this + ->addItemDelete($table, 'analyzer', Routes::ANALYZER_DELETE) + ->addTableToolbarActionAdd($table, Routes::ANALYZER_ADD) + ->addTableActionDelete($table, 'analyzer'); } public function getRoles(): array diff --git a/EMS/core-bundle/src/DataTable/Type/Mapping/FilterDataTableType.php b/EMS/core-bundle/src/DataTable/Type/Mapping/FilterDataTableType.php index c43438cf1..7b67dd0ee 100644 --- a/EMS/core-bundle/src/DataTable/Type/Mapping/FilterDataTableType.php +++ b/EMS/core-bundle/src/DataTable/Type/Mapping/FilterDataTableType.php @@ -8,7 +8,6 @@ use EMS\CoreBundle\Core\Mapping\FilterManager; use EMS\CoreBundle\DataTable\Type\DataTableTypeTrait; use EMS\CoreBundle\Form\Data\EntityTable; -use EMS\CoreBundle\Form\Data\TableAbstract; use EMS\CoreBundle\Roles; use EMS\CoreBundle\Routes; @@ -18,43 +17,27 @@ class FilterDataTableType extends AbstractEntityTableType { use DataTableTypeTrait; - public function __construct(FilterManager $analyzerManager) + public function __construct(FilterManager $filterManager) { - parent::__construct($analyzerManager); + parent::__construct($filterManager); } public function build(EntityTable $table): void { - $this->addColumnsOrderLabelName($table); + $this + ->addColumnsOrderLabelName($table) + ->addItemEdit($table, Routes::FILTER_EDIT); - $table->addItemGetAction( - route: Routes::FILTER_EDIT, - labelKey: t('action.edit', [], 'emsco-core'), - icon: 'pencil' - ); $table->addItemGetAction( route: Routes::FILTER_EXPORT, labelKey: t('action.export', [], 'emsco-core'), icon: 'sign-out' ); - $table->addItemPostAction( - route: Routes::FILTER_DELETE, - labelKey: t('action.delete', [], 'emsco-core'), - icon: 'trash', - messageKey: t('type.delete_confirm', ['type' => 'filter'], 'emsco-core') - )->setButtonType('outline-danger'); - $table->addToolbarAction( - label: t('action.add', [], 'emsco-core'), - icon: 'fa fa-plus', - routeName: Routes::FILTER_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' => 'filter'], 'emsco-core') - )->setCssClass('btn btn-outline-danger'); + $this + ->addItemDelete($table, 'filter', Routes::FILTER_DELETE) + ->addTableToolbarActionAdd($table, Routes::FILTER_ADD) + ->addTableActionDelete($table, 'filter'); } public function getRoles(): array diff --git a/EMS/core-bundle/src/DataTable/Type/QuerySearchDataTableType.php b/EMS/core-bundle/src/DataTable/Type/QuerySearchDataTableType.php index 703e3417d..35fe74ba9 100644 --- a/EMS/core-bundle/src/DataTable/Type/QuerySearchDataTableType.php +++ b/EMS/core-bundle/src/DataTable/Type/QuerySearchDataTableType.php @@ -6,7 +6,6 @@ use EMS\CoreBundle\Core\DataTable\Type\AbstractEntityTableType; use EMS\CoreBundle\Form\Data\EntityTable; -use EMS\CoreBundle\Form\Data\TableAbstract; use EMS\CoreBundle\Roles; use EMS\CoreBundle\Service\QuerySearchService; @@ -14,6 +13,8 @@ class QuerySearchDataTableType extends AbstractEntityTableType { + use DataTableTypeTrait; + public function __construct(QuerySearchService $entityService) { parent::__construct($entityService); @@ -26,29 +27,11 @@ public function build(EntityTable $table): void $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'); + $this + ->addItemEdit($table, 'ems_core_query_search_edit') + ->addItemDelete($table, 'query_search', 'ems_core_query_search_delete') + ->addTableToolbarActionAdd($table, 'ems_core_query_search_add') + ->addTableActionDelete($table, 'query_search'); } public function getRoles(): array diff --git a/EMS/core-bundle/src/DataTable/Type/Revision/RevisionDraftsDataTableType.php b/EMS/core-bundle/src/DataTable/Type/Revision/RevisionDraftsDataTableType.php index f48106146..566fa5380 100644 --- a/EMS/core-bundle/src/DataTable/Type/Revision/RevisionDraftsDataTableType.php +++ b/EMS/core-bundle/src/DataTable/Type/Revision/RevisionDraftsDataTableType.php @@ -7,6 +7,7 @@ use Doctrine\ORM\QueryBuilder; use EMS\CoreBundle\Core\DataTable\Type\AbstractTableType; use EMS\CoreBundle\Core\DataTable\Type\QueryServiceTypeInterface; +use EMS\CoreBundle\DataTable\Type\DataTableTypeTrait; use EMS\CoreBundle\Entity\ContentType; use EMS\CoreBundle\Form\Data\Condition\DateInFuture; use EMS\CoreBundle\Form\Data\Condition\InMyCircles; @@ -26,6 +27,8 @@ class RevisionDraftsDataTableType extends AbstractTableType implements QueryServiceTypeInterface { + use DataTableTypeTrait; + final public const DISCARD_SELECTED_DRAFT = 'DISCARD_SELECTED_DRAFT'; public function __construct( @@ -83,12 +86,7 @@ public function build(QueryTable $table): void )->addCondition($inMyCircles)->setButtonType('outline-danger'); if (null !== $contentType && (null === $contentType->getCirclesField() || '' === $contentType->getCirclesField())) { - $table->addTableAction( - name: self::DISCARD_SELECTED_DRAFT, - icon: 'fa fa-trash', - labelKey: t('action.delete_selected', [], 'emsco-core'), - confirmationKey: t('type.delete_selected_confirm', ['type' => 'draft'], 'emsco-core'), - )->setCssClass('btn btn-outline-danger'); + $this->addTableActionDelete($table, 'draft', self::DISCARD_SELECTED_DRAFT); } } diff --git a/EMS/core-bundle/src/DataTable/Type/Revision/RevisionTrashDataTableType.php b/EMS/core-bundle/src/DataTable/Type/Revision/RevisionTrashDataTableType.php index 445b605e1..a02377c00 100644 --- a/EMS/core-bundle/src/DataTable/Type/Revision/RevisionTrashDataTableType.php +++ b/EMS/core-bundle/src/DataTable/Type/Revision/RevisionTrashDataTableType.php @@ -8,6 +8,7 @@ use EMS\CoreBundle\Core\ContentType\ContentTypeRoles; use EMS\CoreBundle\Core\DataTable\Type\AbstractTableType; use EMS\CoreBundle\Core\DataTable\Type\QueryServiceTypeInterface; +use EMS\CoreBundle\DataTable\Type\DataTableTypeTrait; use EMS\CoreBundle\Entity\ContentType; use EMS\CoreBundle\Form\Data\DatetimeTableColumn; use EMS\CoreBundle\Form\Data\QueryTable; @@ -23,6 +24,8 @@ class RevisionTrashDataTableType extends AbstractTableType implements QueryServiceTypeInterface { + use DataTableTypeTrait; + public const ACTION_EMPTY_TRASH = 'empty-trash'; public const ACTION_PUT_BACK = 'put-back'; @@ -80,12 +83,8 @@ public function build(QueryTable $table): void 'ouuid' => 'ouuid', ] )->setButtonType('outline-danger'); - $table->addTableAction( - name: self::ACTION_EMPTY_TRASH, - icon: 'fa fa-trash', - labelKey: t('action.delete_selected', [], 'emsco-core'), - confirmationKey: t('type.delete_selected_confirm', ['type' => 'trash'], 'emsco-core'), - )->setCssClass('btn btn-outline-danger'); + + $this->addTableActionDelete($table, 'trash', self::ACTION_EMPTY_TRASH); } public function configureOptions(OptionsResolver $optionsResolver): void diff --git a/EMS/core-bundle/src/DataTable/Type/UploadedAsset/UploadedAssetAdminDataTableType.php b/EMS/core-bundle/src/DataTable/Type/UploadedAsset/UploadedAssetAdminDataTableType.php index f0ac26fe1..6720f8690 100644 --- a/EMS/core-bundle/src/DataTable/Type/UploadedAsset/UploadedAssetAdminDataTableType.php +++ b/EMS/core-bundle/src/DataTable/Type/UploadedAsset/UploadedAssetAdminDataTableType.php @@ -6,6 +6,7 @@ use EMS\CommonBundle\Helper\Text\Encoder; use EMS\CoreBundle\Core\DataTable\Type\AbstractEntityTableType; +use EMS\CoreBundle\DataTable\Type\DataTableTypeTrait; use EMS\CoreBundle\EMSCoreBundle; use EMS\CoreBundle\Entity\UploadedAsset; use EMS\CoreBundle\Form\Data\BoolTableColumn; @@ -22,6 +23,8 @@ class UploadedAssetAdminDataTableType extends AbstractEntityTableType { + use DataTableTypeTrait; + public const TOGGLE_VISIBILITY_ACTION = 'action_toggle_visibility'; public function __construct(FileService $entityService) @@ -88,31 +91,22 @@ public function build(EntityTable $table): void icon: 'eye', routeParameters: ['assetId' => 'id'] ); - $table->addItemPostAction( - route: Routes::UPLOAD_ASSET_ADMIN_DELETE, - labelKey: t('action.delete', [], 'emsco-core'), - icon: 'trash', - messageKey: t('type.delete_confirm', ['type' => 'uploaded_file'], 'emsco-core') - )->setButtonType('outline-danger'); + + $this->addItemDelete($table, 'uploaded_file', Routes::UPLOAD_ASSET_ADMIN_DELETE); $table->addTableAction( name: TableAbstract::DOWNLOAD_ACTION, icon: 'fa fa-download', labelKey: t('action.download_selected', [], 'emsco-core') - ); + )->setCssClass('btn btn-sm btn-default'); $table->addTableAction( name: self::TOGGLE_VISIBILITY_ACTION, icon: 'fa fa-eye', labelKey: t('action.toggle_visibility_selected', [], 'emsco-core'), - ); + )->setCssClass('btn btn-sm btn-default'); - $table->addTableAction( - name: TableAbstract::DELETE_ACTION, - icon: 'fa fa-trash', - labelKey: t('action.delete_selected', [], 'emsco-core'), - confirmationKey: t('type.delete_selected_confirm', ['type' => 'uploaded_file'], 'emsco-core') - )->setCssClass('btn btn-outline-danger'); + $this->addTableActionDelete($table, 'uploaded_file'); } public function getRoles(): array diff --git a/EMS/core-bundle/src/DataTable/Type/UploadedAsset/UploadedAssetDataTableType.php b/EMS/core-bundle/src/DataTable/Type/UploadedAsset/UploadedAssetDataTableType.php index 948f99863..6938582b1 100644 --- a/EMS/core-bundle/src/DataTable/Type/UploadedAsset/UploadedAssetDataTableType.php +++ b/EMS/core-bundle/src/DataTable/Type/UploadedAsset/UploadedAssetDataTableType.php @@ -10,6 +10,7 @@ use EMS\CommonBundle\Helper\Text\Encoder; use EMS\CoreBundle\Core\DataTable\Type\AbstractTableType; use EMS\CoreBundle\Core\DataTable\Type\QueryServiceTypeInterface; +use EMS\CoreBundle\DataTable\Type\DataTableTypeTrait; use EMS\CoreBundle\EMSCoreBundle; use EMS\CoreBundle\Form\Data\BytesTableColumn; use EMS\CoreBundle\Form\Data\DatetimeTableColumn; @@ -27,6 +28,8 @@ class UploadedAssetDataTableType extends AbstractTableType implements QueryServiceTypeInterface { + use DataTableTypeTrait; + public const HIDE_ACTION = 'hide'; public const LOCATION_WYSIWYG_BROWSER = 'wysiwyg_browser'; @@ -135,13 +138,9 @@ public function build(QueryTable $table): void name: TableAbstract::DOWNLOAD_ACTION, icon: 'fa fa-download', labelKey: t('action.download_selected', [], 'emsco-core') - ); - $table->addTableAction( - name: self::HIDE_ACTION, - icon: 'fa fa-trash', - labelKey: t('action.delete_selected', [], 'emsco-core'), - confirmationKey: t('type.delete_selected_confirm', ['type' => 'uploaded_file'], 'emsco-core'), - )->setCssClass('btn btn-outline-danger'); + )->setCssClass('btn btn-sm btn-default'); + + $this->addTableActionDelete($table, 'uploaded_file', self::HIDE_ACTION); } } diff --git a/EMS/core-bundle/src/Form/Data/TableAbstract.php b/EMS/core-bundle/src/Form/Data/TableAbstract.php index 67be6d911..c3dc80d7a 100644 --- a/EMS/core-bundle/src/Form/Data/TableAbstract.php +++ b/EMS/core-bundle/src/Form/Data/TableAbstract.php @@ -124,10 +124,20 @@ public function setReordered(array $reordered): void $this->reordered = $reordered; } - public function addColumn(string|TranslatableMessage $titleKey, string $attribute): TableColumn + public function getColumnByName(string $name): ?TableColumn + { + return $this->columns[$name] ?? null; + } + + public function addColumn(string|TranslatableMessage $titleKey, string $attribute, ?string $name = null): TableColumn { $column = new TableColumn($titleKey, $attribute); - $this->columns[] = $column; + + if ($name) { + $this->columns[$name] = $column; + } else { + $this->columns[] = $column; + } return $column; } diff --git a/EMS/core-bundle/src/Form/Form/TableType.php b/EMS/core-bundle/src/Form/Form/TableType.php index 062db8310..a9c611ae4 100644 --- a/EMS/core-bundle/src/Form/Form/TableType.php +++ b/EMS/core-bundle/src/Form/Form/TableType.php @@ -75,7 +75,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'entry_options' => [], 'data' => $choices, ])->add(self::REORDER_ACTION, SubmitEmsType::class, [ - 'attr' => ['class' => 'btn btn-default'], + 'attr' => ['class' => 'btn btn-sm btn-default'], 'icon' => 'fa fa-reorder', 'label' => t('action.reorder', [], 'emsco-core'), ]); diff --git a/EMS/core-bundle/src/Repository/JobRepository.php b/EMS/core-bundle/src/Repository/JobRepository.php index 756f77265..8f926395f 100644 --- a/EMS/core-bundle/src/Repository/JobRepository.php +++ b/EMS/core-bundle/src/Repository/JobRepository.php @@ -46,6 +46,19 @@ public function countPendingJobs(): int return \intval($qb->getQuery()->getSingleScalarResult()); } + /** + * @return Job[] + */ + public function getByIds(string ...$ids): array + { + $qb = $this->createQueryBuilder('j'); + $qb + ->andWhere($qb->expr()->in('j.id', ':ids')) + ->setParameter('ids', $ids); + + return $qb->getQuery()->getResult(); + } + public function save(Job $job): void { $this->getEntityManager()->persist($job); diff --git a/EMS/core-bundle/src/Resources/config/controllers.xml b/EMS/core-bundle/src/Resources/config/controllers.xml index 81356deae..8d889c80c 100644 --- a/EMS/core-bundle/src/Resources/config/controllers.xml +++ b/EMS/core-bundle/src/Resources/config/controllers.xml @@ -198,9 +198,9 @@ - - %ems_core.paging_size% + + %ems_core.trigger_job_from_web% %ems_core.template_namespace% @@ -293,8 +293,8 @@ - + %ems_core.template_namespace% diff --git a/EMS/core-bundle/src/Resources/config/datatable.xml b/EMS/core-bundle/src/Resources/config/datatable.xml index a923e0bc1..e9b2b6d57 100644 --- a/EMS/core-bundle/src/Resources/config/datatable.xml +++ b/EMS/core-bundle/src/Resources/config/datatable.xml @@ -109,7 +109,12 @@ - + + + %ems_core.template_namespace% + + + diff --git a/EMS/core-bundle/src/Resources/config/routing/admin/job.xml b/EMS/core-bundle/src/Resources/config/routing/admin/job.xml index d64374d26..11170776b 100644 --- a/EMS/core-bundle/src/Resources/config/routing/admin/job.xml +++ b/EMS/core-bundle/src/Resources/config/routing/admin/job.xml @@ -6,7 +6,7 @@ - - +
+ {{ "#{p}%" }} +
+ +
{{ line.data.status }}
+{% endblock jobStatus %} diff --git a/EMS/core-bundle/src/Resources/views/form/forms.html.twig b/EMS/core-bundle/src/Resources/views/form/forms.html.twig index 0f3d26e73..b38ce5168 100644 --- a/EMS/core-bundle/src/Resources/views/form/forms.html.twig +++ b/EMS/core-bundle/src/Resources/views/form/forms.html.twig @@ -291,7 +291,7 @@ {% endif %} {% if toolbar is defined or (table.sortable and table.supportsTableActions) or table.toolbarActions|length > 0 %}
-
+
{% if toolbar is defined %} {{ toolbar }} {% endif %} @@ -301,7 +301,7 @@ {% endfor %} {% if attribute(form, 'reorderAction') is defined %} - {% endif %} @@ -360,24 +360,22 @@ {% if table.supportsTableActions or toolbar is defined %} {% endif %}
@@ -407,8 +405,8 @@
diff --git a/EMS/core-bundle/src/Resources/views/job/index.html.twig b/EMS/core-bundle/src/Resources/views/job/index.html.twig deleted file mode 100644 index db1b226fb..000000000 --- a/EMS/core-bundle/src/Resources/views/job/index.html.twig +++ /dev/null @@ -1,98 +0,0 @@ -{% extends '@EMSCore/base.html.twig' %}{% trans_default_domain 'EMSCoreBundle' %} - -{% block title %}Job's list{% endblock %} -{% block pagetitle %}Job's list{% endblock %} -{% block subtitle %}Running process{% endblock %} - - -{% block body %} -
-
-
-
- -

Jobs

-
- {% include '@EMSCore/elements/get-button.html.twig' with { - 'url': path('job.add'), - 'label': 'New job', - 'icon': 'plus' - }%} - {% include '@EMSCore/elements/post-button.html.twig' with { - 'url': path('job.clean'), - 'message': 'Clean done jobs ?', - 'label': 'Clean', - 'icon': 'trash' - }%} -
- -
- -
-
- - - - - - - - - - - - {% for job in jobs %} - - - - - - - - - - {% endfor %} - -
#StartedLast updateCommandTagStatusAction
{{ from+loop.index }}{{ job.created|date(date_time_format) }}{{ job.modified|date(date_time_format) }}{{ job.command }}{{ job.tag }} -
- {{ job.status }} - {{ job.progress }}/100 - -
-
-
-
-
-
- {% include '@EMSCore/elements/get-button.html.twig' with { - 'url': path('job.status', {'job': job.id}), - 'label': 'Status', - 'icon': 'eye' - }%} - {% include '@EMSCore/elements/post-button.html.twig' with { - 'url': path('job.delete', {'job': job.id}), - 'message': 'Do you confirm ?', - 'label': 'Delete', - 'icon': 'trash' - }%} -
-
-
-
- - -
-
-
-{% include '@EMSCore/app/menu.html.twig' with { - 'item': 'job-index' -}%} -{% endblock %} \ No newline at end of file diff --git a/EMS/core-bundle/src/Resources/views/schedule/index.html.twig b/EMS/core-bundle/src/Resources/views/schedule/index.html.twig deleted file mode 100644 index e0aaa27c2..000000000 --- a/EMS/core-bundle/src/Resources/views/schedule/index.html.twig +++ /dev/null @@ -1,16 +0,0 @@ -{% extends '@EMSCore/schedule/abstract.html.twig' %} -{% trans_default_domain 'emsco-twigs' %} - -{% block title %}{{ 'schedule.index.title'|trans }}{% endblock %} - -{% block body %} - {% set toolbar %} - {{ 'schedule.index.add_button'|trans }} - {% endset %} - - {% form_theme form '@EMSCore/form/forms.html.twig' %} - {{ form(form, { - reorder_label: 'schedule.index.reorder', - toolbar: toolbar - }) }} -{% endblock %} \ No newline at end of file diff --git a/EMS/core-bundle/src/Service/JobService.php b/EMS/core-bundle/src/Service/JobService.php index 5b5b53ab7..67104108b 100644 --- a/EMS/core-bundle/src/Service/JobService.php +++ b/EMS/core-bundle/src/Service/JobService.php @@ -35,6 +35,14 @@ public function __construct( $this->em = $doctrine->getManager(); } + public function deleteByIds(string ...$ids): void + { + $analyzers = $this->repository->getByIds(...$ids); + foreach ($analyzers as $analyzer) { + $this->repository->delete($analyzer); + } + } + public function nextJob(?string $tag = null): ?Job { return $this->repository->findOneBy(