feat: filter timeline by date range and hotels

This commit is contained in:
Björn Fromme
2025-03-21 11:52:29 +01:00
parent 9ffada111c
commit 06c32fd597
14 changed files with 316 additions and 28 deletions
@@ -2,9 +2,9 @@
namespace App\Controller\Administrative\Assignment;
use App\Model\AssignmentFilterDto;
use App\Repository\AssignmentRepository;
use App\Service\Assignment\TimelineService;
use App\Service\Common\TimelineFilterHandler;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
@@ -14,7 +14,8 @@ class TimelineController extends AbstractController
{
public function __construct(
private readonly AssignmentRepository $assignmentRepository,
private readonly TimelineService $timelineService
private readonly TimelineService $timelineService,
private readonly TimelineFilterHandler $filterHandler
) {
}
@@ -23,12 +24,9 @@ class TimelineController extends AbstractController
public function index(): Response
{
$period = $this->timelineService->getActiveWindow();
$filterDto = new AssignmentFilterDto();
$filterDto
->setDateFrom($period->first()->toDateTimeImmutable())
->setDateTo($period->last()->toDateTimeImmutable())
->setIncludePast(true)
;
$this->filterHandler->setPeriod($period);
$filterDto = $this->filterHandler->getFilterSettings();
$assignments = $this
->assignmentRepository
@@ -40,6 +38,7 @@ class TimelineController extends AbstractController
return $this->render('administrative/assignment/timeline.html.twig', [
'data' => $timelineData,
'period' => $period,
'filterDto' => $filterDto,
]);
}
}
@@ -0,0 +1,62 @@
<?php
namespace App\Controller\Common;
use App\Controller\Traits\ReturnUrlTrait;
use App\Form\TimelineFilterType;
use App\Htmx\HxRedirectResponse;
use App\Service\Assignment\TimelineService;
use App\Service\Common\TimelineFilterHandler;
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;
class TimelineFilterController extends AbstractController
{
use ReturnUrlTrait;
public function __construct(
private readonly TimelineFilterHandler $filterHandler,
private readonly TimelineService $timelineService,
) {
$period = $this->timelineService->getActiveWindow();
$this->filterHandler->setPeriod($period);
}
#[Route('/common/timeline/filter', name: 'app_common_timeline_filter')]
#[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(Request $request): Response
{
$formData = $this->filterHandler->getFilterSettings();
$formOptions = [
'min_date' => $formData->getPeriod()->first()->toDateTimeImmutable(),
'max_date' => $formData->getPeriod()->last()->toDateTimeImmutable(),
];
$form = $this->createForm(TimelineFilterType::class, $formData, $formOptions);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->filterHandler->handleRequest($form);
$returnUrl = $this->getReturnUrl($request, 'app_administrative_assignment_timeline');
return new HxRedirectResponse($returnUrl);
}
return $this->render('common/modal_timeline_filter.html.twig', [
'filterForm' => $form->createView(),
'filterDto' => $form->getData(),
]);
}
#[Route('/common/timeline/filter/reset', name: 'app_common_timeline_filter_reset')]
public function reset(Request $request): Response
{
$this->filterHandler->resetFilterSettings();
$returnUrl = $this->getReturnUrl($request, 'app_administrative_assignment_timeline');
return $this->redirect($returnUrl);
}
}