From 95462fafba7c0cab947ebf3b1ec6866dca804c9b Mon Sep 17 00:00:00 2001
From: Xbird
Date: Thu, 15 Sep 2022 17:30:31 +0200
Subject: [PATCH] remork watchdogs filter and logic
---
src/Controller/AdminController.php | 49 +++++++++++------------
templates/_cells/historyDisplay.html.twig | 2 +-
templates/admin/watchdog.html.twig | 29 +++++++++-----
3 files changed, 44 insertions(+), 36 deletions(-)
diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php
index 5bd8928..c4db8c9 100644
--- a/src/Controller/AdminController.php
+++ b/src/Controller/AdminController.php
@@ -679,48 +679,45 @@ class AdminController extends AbstractController
}
- #[Route('/watchdog', name: 'watchdog')]
- #[Route('/watchdog/view/{type}/{id}/{action}', name: 'watchdog_view')]
- #[Route('/watchdog/{type}', name: 'watchdog_type')]
- #[Route('/watchdog/{type}/{action}', name: 'watchdog_type_action')]
+ #[Route('/watchdog/{type?*}/{id?*}/{action?*}', name: 'watchdog')]
public function watchdog(
PaginatorInterface $paginator,
Request $Request,
EntityManagerInterface $EntityManagerInterface,
string $type = null,
string $action = null,
- int $id = null
+ string $id = null
): Response {
$qb = $EntityManagerInterface->createQueryBuilder();
$qbButtons = $EntityManagerInterface->createQueryBuilder();
+ $qbButtonsAction = $EntityManagerInterface->createQueryBuilder();
$qb->select('l')
->from('Gedmo\Loggable\Entity\LogEntry', 'l')
->orderBy('l.loggedAt', 'DESC');
$qbButtons->select('DISTINCT l.objectClass')
- ->from('Gedmo\Loggable\Entity\LogEntry', 'l')
- ->orderBy('l.loggedAt', 'DESC');
-
-
-
-
- if (null != $type) {
- $qb->where('l.objectClass = :type');
- $qb->setParameter('type', 'App\Entity\\' . $type);
- $qbButtonsAction = $EntityManagerInterface->createQueryBuilder();
- $qbButtonsAction->select('DISTINCT l.action')
->from('Gedmo\Loggable\Entity\LogEntry', 'l')
- ->orderBy('l.loggedAt', 'DESC');
+ ->orderBy('l.objectClass', 'ASC');
+
+ $qbButtonsAction->select('DISTINCT l.action')
+ ->from('Gedmo\Loggable\Entity\LogEntry', 'l')
+ ->orderBy('l.action', 'ASC');
- if (null != $action) {
- $qb->andWhere('l.action = :action');
- $qb->setParameter('action', $action);
- }
+
+
+ if (null != $type && '*' != $type) {
+ $qb->where('l.objectClass = :type');
+ $qb->setParameter('type', 'App\Entity\\' . $type);
}
- if (null != $id) {
+ if (null != $action && '*' != $action) {
+ $qb->andWhere('l.action = :action');
+ $qb->setParameter('action', $action);
+ }
+
+ if (null != $id && '*' != $id) {
$qb->andWhere('l.objectId = :id');
$qb->setParameter('id', $id);
}
@@ -732,11 +729,13 @@ class AdminController extends AbstractController
return $this->render('admin/watchdog.html.twig', [
'controller_name' => 'AdminController',
- 'pagination' => $pagination,
- 'buttonsType' => $qbButtons->getQuery()->getResult(),
'type' => $type,
- 'buttonsAction' => (($type != null) ? $qbButtonsAction->getQuery()->getResult() : null),
'action' => $action,
+ 'id' => $id,
+ 'buttonsType' => $qbButtons->getQuery()->getResult(),
+ 'buttonsAction' => $qbButtonsAction->getQuery()->getResult(),
+ 'pagination' => $pagination,
+
]);
}
diff --git a/templates/_cells/historyDisplay.html.twig b/templates/_cells/historyDisplay.html.twig
index e348a09..9d3c818 100644
--- a/templates/_cells/historyDisplay.html.twig
+++ b/templates/_cells/historyDisplay.html.twig
@@ -11,7 +11,7 @@
{% endif %}
{% if notype is not defined %}
- {{ i.objectClass }} (# {{ i.objectId }}) {% if is_granted('ROLE_ADMIN') %}{% endif %}
+ {{ i.objectClass }} (# {{ i.objectId }}) {% if is_granted('ROLE_ADMIN') %}{% endif %}
{% endif %}
{{ ('title_data_' ~ i.action)|trans }}
diff --git a/templates/admin/watchdog.html.twig b/templates/admin/watchdog.html.twig
index 3fa2e68..11778a8 100644
--- a/templates/admin/watchdog.html.twig
+++ b/templates/admin/watchdog.html.twig
@@ -7,30 +7,39 @@
-
Filtres
-
Type:
-
*
- {% for t in buttonsType %}
- {% set btntype = t.objectClass|replace({'App\\Entity\\': ''}) %}
-
{{ btntype }}
- {% endfor %}
+
Filtres
+
+ {% if id is null or id == '*' %}
+
Type:
+
*
+ {% for t in buttonsType %}
+ {% set btntype = t.objectClass|replace({'App\\Entity\\': ''}) %}
+
{{ btntype }}
+ {% endfor %}
+
+ {% else %}
+
back to list
+ {% endif %}
{% if buttonsAction != null %}
Action:
-
*
+
*
{% for a in buttonsAction %}
-
{{ a.action }}
+
{{ a.action }}
{% endfor %}
{% endif %}
+
{% include '_cells/historyDisplay.html.twig' with {'history': pagination} %}
+
{{ knp_pagination_render(pagination) }}
-
+
+
{% endblock %}