remork watchdogs filter and logic

This commit is contained in:
Xbird
2022-09-15 17:30:31 +02:00
parent 2c76f0fd89
commit 95462fafba
3 changed files with 44 additions and 36 deletions

View File

@@ -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,
]);
}

View File

@@ -11,7 +11,7 @@
{% endif %}
</p>
{% if notype is not defined %}
<p>{{ i.objectClass }} (# {{ i.objectId }}) {% if is_granted('ROLE_ADMIN') %}<a href="{{ path('admin_watchdog_view', {'type':i.objectClass|replace({'App\\Entity\\': ''}), 'id': i.objectId}) }}" class="btn btn-warning btn-sm" data-bs-toggle="tooltip" data-placement="top" title="{% trans %}tooltip_directory_history{% endtrans %} (Admin)"><i class="fas fa-clock"></i></a>{% endif %}</p>
<p>{{ i.objectClass }} (# {{ i.objectId }}) {% if is_granted('ROLE_ADMIN') %}<a href="{{ path('admin_watchdog', {'type':i.objectClass|replace({'App\\Entity\\': ''}), 'id': i.objectId}) }}" class="btn btn-warning btn-sm" data-bs-toggle="tooltip" data-placement="top" title="{% trans %}tooltip_directory_history{% endtrans %} (Admin)"><i class="fas fa-clock"></i></a>{% endif %}</p>
{% endif %}
<p>{{ ('title_data_' ~ i.action)|trans }}</p>
<div class="table-responsive">

View File

@@ -7,30 +7,39 @@
<div class="row">
<div class="col mb-5">
<h4>Filtres</h4>
<h5>Type: </h5>
<a href="{{ path('admin_watchdog') }}" class="btn btn-{{type == null ? 'info' : 'primary'}} m-1">*</a>
{% for t in buttonsType %}
{% set btntype = t.objectClass|replace({'App\\Entity\\': ''}) %}
<a href="{{ path('admin_watchdog_type',{type: btntype}) }}" class="btn btn-{{type == btntype ? 'info' : 'primary'}} m-1">{{ btntype }}</a>
{% endfor %}
<h4>Filtres</h4>
{% if id is null or id == '*' %}
<h5>Type: </h5>
<a href="{{ path('admin_watchdog', {type:'*', id: id, action: action}) }}" class="btn btn-{{type == '*' ? 'info' : 'primary'}} m-1">*</a>
{% for t in buttonsType %}
{% set btntype = t.objectClass|replace({'App\\Entity\\': ''}) %}
<a href="{{ path('admin_watchdog',{type: btntype, id: id, action: action}) }}" class="btn btn-{{type == btntype ? 'info' : 'primary'}} m-1">{{ btntype }}</a>
{% endfor %}
{% else %}
<a href="{{ path('admin_watchdog', {type: type, id: '*', action: action}) }}" class="btn btn-warning m-1">back to list</a>
{% endif %}
{% if buttonsAction != null %}
<h5>Action: </h5>
<a href="{{ path('admin_watchdog_type',{type: type}) }}" class="btn btn-{{action == null ? 'info' : 'primary'}} m-1">*</a>
<a href="{{ path('admin_watchdog',{type: type, id: id, action: '*'}) }}" class="btn btn-{{action == '*' ? 'info' : 'primary'}} m-1">*</a>
{% for a in buttonsAction %}
<a href="{{ path('admin_watchdog_type_action',{type: type, action: a.action }) }}" class="btn btn-{{action == a.action ? 'info' : 'primary'}} m-1">{{ a.action }}</a>
<a href="{{ path('admin_watchdog',{type: type, id: id, action: a.action }) }}" class="btn btn-{{action == a.action ? 'info' : 'primary'}} m-1">{{ a.action }}</a>
{% endfor %}
{% endif %}
</div>
</div>
<div class="row">
<div class="col">
{% include '_cells/historyDisplay.html.twig' with {'history': pagination} %}
</div>
</div>
<div class="row">
{{ knp_pagination_render(pagination) }}
</div>
</div>
{% endblock %}