feat: admin list filtering and search
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin\Log;
|
||||
|
||||
use App\Controller\Traits\ListFilterTrait;
|
||||
use App\Form\Admin\Filter\LogEntryFilterType;
|
||||
use App\Form\Model\Filter\LogEntryFilterDto;
|
||||
use App\Repository\LogEntryRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
#[IsGranted('ROLE_ADMIN')]
|
||||
class FilterController extends AbstractController
|
||||
{
|
||||
use ListFilterTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly LogEntryRepository $logEntryRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/log/filter', name: 'app_admin_log_filter', methods: ['GET'])]
|
||||
public function filter(Request $request): Response
|
||||
{
|
||||
$filterView = $this->createListFilterView(
|
||||
$request,
|
||||
LogEntryFilterType::class,
|
||||
new LogEntryFilterDto(),
|
||||
'app_admin_log',
|
||||
['channels' => $this->logEntryRepository->findChannels()],
|
||||
);
|
||||
|
||||
return $this->render('admin/_modal_filter.html.twig', [
|
||||
'form' => $filterView,
|
||||
'route' => 'app_admin_log',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin\Log;
|
||||
|
||||
use App\Controller\Traits\ListFilterTrait;
|
||||
use App\Form\Admin\Filter\LogEntryFilterType;
|
||||
use App\Form\Model\Filter\LogEntryFilterDto;
|
||||
use App\Repository\LogEntryRepository;
|
||||
use Knp\Component\Pager\PaginatorInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@@ -15,6 +18,8 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
#[IsGranted('ROLE_ADMIN')]
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
use ListFilterTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly LogEntryRepository $logEntryRepository,
|
||||
private readonly PaginatorInterface $paginator,
|
||||
@@ -24,13 +29,18 @@ class IndexController extends AbstractController
|
||||
#[Route('/admin/log', name: 'app_admin_log')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$qb = $this
|
||||
->logEntryRepository
|
||||
->createQueryBuilder('log_entry')
|
||||
;
|
||||
$filter = new LogEntryFilterDto();
|
||||
|
||||
$filterView = $this->createListFilterView(
|
||||
$request,
|
||||
LogEntryFilterType::class,
|
||||
$filter,
|
||||
'app_admin_log',
|
||||
['channels' => $this->logEntryRepository->findChannels()],
|
||||
);
|
||||
|
||||
$pagination = $this->paginator->paginate(
|
||||
$qb,
|
||||
$this->logEntryRepository->createFilteredQueryBuilder($filter),
|
||||
$request->query->getInt('page', 1),
|
||||
$request->query->getInt('limit', 50),
|
||||
[
|
||||
@@ -41,6 +51,8 @@ class IndexController extends AbstractController
|
||||
|
||||
return $this->render('admin/log/index.html.twig', [
|
||||
'pagination' => $pagination,
|
||||
'filter' => $filter,
|
||||
'filter_form' => $filterView,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user