Feat: Add assignment filtering for teamers

This commit is contained in:
Björn Fromme
2023-10-23 15:45:41 +02:00
parent dcf0d9af20
commit ae81c97d12
7 changed files with 88 additions and 56 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
} }
.btn--small { .btn--small {
@apply text-xs py-1 px-2 rounded-sm; @apply text-xs py-1 px-2 rounded-md;
} }
.btn--secondary { .btn--secondary {
+11 -2
View File
@@ -4,6 +4,7 @@ namespace App\Controller\Teamer;
use App\Entity\User; use App\Entity\User;
use App\Repository\AssignmentRepository; use App\Repository\AssignmentRepository;
use App\Service\Common\AssignmentFilterHandler;
use Knp\Component\Pager\PaginatorInterface; use Knp\Component\Pager\PaginatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -16,6 +17,7 @@ class IndexController extends AbstractController
{ {
public function __construct( public function __construct(
private readonly ValidatorInterface $validator, private readonly ValidatorInterface $validator,
private readonly AssignmentFilterHandler $filterHandler,
private readonly PaginatorInterface $paginator, private readonly PaginatorInterface $paginator,
private readonly AssignmentRepository $assignmentRepository private readonly AssignmentRepository $assignmentRepository
) { ) {
@@ -32,9 +34,15 @@ class IndexController extends AbstractController
// Validate teamer data to show missing data right away // Validate teamer data to show missing data right away
$errors = $this->validator->validate($teamer, null, ['profile_preflight']); $errors = $this->validator->validate($teamer, null, ['profile_preflight']);
$filterForm = $this->filterHandler->getForm('assignment_filter_teamer');
$filterDto = $this->filterHandler->handleRequest($filterForm, $request, 'assignment_filter_teamer');
if (true === $filterDto->isReset()) {
return $this->redirectToRoute('app_teamer_index');
}
$query = $this $query = $this
->assignmentRepository ->assignmentRepository
->getListQueryForTeamer($teamer) ->getListQueryForTeamer($teamer, $filterDto)
; ;
$pagination = $this->paginator->paginate( $pagination = $this->paginator->paginate(
@@ -49,8 +57,9 @@ class IndexController extends AbstractController
return $this->render('teamer/index.html.twig', [ return $this->render('teamer/index.html.twig', [
'teamer' => $teamer, 'teamer' => $teamer,
'pagination' => $pagination,
'errors' => $errors, 'errors' => $errors,
'pagination' => $pagination,
'filterForm' => $filterForm,
]); ]);
} }
} }
+6 -8
View File
@@ -17,7 +17,12 @@ class AssignmentFilterDto
private ?JobProfile $jobProfile = null; private ?JobProfile $jobProfile = null;
private ?Destination $destination = null; private ?Destination $destination = null;
private ?int $duration = null; private ?int $duration = null;
private bool $reset = false; private bool $reset;
public function __construct(bool $reset = false)
{
$this->reset = $reset;
}
public function getDateFrom(): ?\DateTimeImmutable public function getDateFrom(): ?\DateTimeImmutable
{ {
@@ -83,11 +88,4 @@ class AssignmentFilterDto
{ {
return $this->reset; return $this->reset;
} }
public function setReset(bool $reset): static
{
$this->reset = $reset;
return $this;
}
} }
+27 -18
View File
@@ -10,6 +10,7 @@ use App\Model\AssignmentFilterDto;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;
/** /**
@@ -41,6 +42,32 @@ class AssignmentRepository extends ServiceEntityRepository
->setParameter('status', Application::STATUS_REJECTED) ->setParameter('status', Application::STATUS_REJECTED)
; ;
$this->applyFilterSettings($filterDto, $qb);
return $qb->getQuery();
}
public function getListQueryForTeamer(Teamer $teamer, AssignmentFilterDto $filterDto): Query
{
$qb = $this->createQueryBuilder('assignment');
$qb
->select('assignment', 'destination', 'job_profile', 'application', 'disposition')
->innerJoin('assignment.destination', 'destination')
->innerJoin('assignment.jobProfile', 'job_profile')
->where($qb->expr()->isNull('assignment.deletedAt'))
->leftJoin('assignment.applications', 'application', Join::WITH, $qb->expr()->eq('application.teamer', ':teamer'))
->leftJoin('assignment.dispositions', 'disposition', Join::WITH, $qb->expr()->eq('disposition.teamer', ':teamer'))
->setParameter('teamer', $teamer)
;
$this->applyFilterSettings($filterDto, $qb);
return $qb->getQuery();
}
private function applyFilterSettings(AssignmentFilterDto $filterDto, QueryBuilder $qb): void
{
if (null !== $dateFrom = $filterDto->getDateFrom()) { if (null !== $dateFrom = $filterDto->getDateFrom()) {
$qb $qb
->andWhere($qb->expr()->gte('destination.dateFrom', ':dateFrom')) ->andWhere($qb->expr()->gte('destination.dateFrom', ':dateFrom'))
@@ -91,24 +118,6 @@ class AssignmentRepository extends ServiceEntityRepository
; ;
} }
} }
return $qb->getQuery();
}
public function getListQueryForTeamer(Teamer $teamer = null): Query
{
$qb = $this->createQueryBuilder('assignment');
return $qb
->select('assignment', 'destination', 'job_profile', 'application', 'disposition')
->innerJoin('assignment.destination', 'destination')
->innerJoin('assignment.jobProfile', 'job_profile')
->where($qb->expr()->isNull('assignment.deletedAt'))
->leftJoin('assignment.applications', 'application', Join::WITH, $qb->expr()->eq('application.teamer', ':teamer'))
->leftJoin('assignment.dispositions', 'disposition', Join::WITH, $qb->expr()->eq('disposition.teamer', ':teamer'))
->setParameter('teamer', $teamer)
->getQuery()
;
} }
public function getBookmarkQueryForTeamer(Teamer $teamer): Query public function getBookmarkQueryForTeamer(Teamer $teamer): Query
+18 -20
View File
@@ -23,11 +23,14 @@ class AssignmentFilterHandler
) { ) {
} }
public function getForm(): FormInterface public function getForm(string $namespace = 'assignment_filter'): FormInterface
{ {
$filterDto = $this->getFilterSettings(); $filterDto = $this->getFilterSettings($namespace);
$assignmentRepository = $this->entityManager->getRepository(Assignment::class); $assignmentRepository = $this
->entityManager
->getRepository(Assignment::class)
;
$filterOptions = $assignmentRepository->getFilterOptions(); $filterOptions = $assignmentRepository->getFilterOptions();
return $this->formFactory->create(AssignmentFilterType::class, $filterDto, [ return $this->formFactory->create(AssignmentFilterType::class, $filterDto, [
@@ -38,35 +41,30 @@ class AssignmentFilterHandler
]); ]);
} }
public function handleRequest(FormInterface $form, Request $request): AssignmentFilterDto public function handleRequest(
{ FormInterface $form,
Request $request,
string $namespace = 'assignment_filter'
): AssignmentFilterDto {
$form->handleRequest($request); $form->handleRequest($request);
$filterDto = $form->getData(); $filterDto = $form->getData();
if ($form->has('reset') && $form->get('reset')->isClicked()) { if ($form->has('reset') && $form->get('reset')->isClicked()) {
$filterDto = new AssignmentFilterDto(); $filterDto = new AssignmentFilterDto(true);
$filterDto->setReset(true); $this->getSession()->remove($namespace);
$this->getSession()->remove('assignment_filter');
} elseif ($form->has('apply') && $form->get('apply')->isClicked()) { } elseif ($form->has('apply') && $form->get('apply')->isClicked()) {
$this->saveFilterSettings($filterDto); $this->saveFilterSettings($filterDto, $namespace);
} }
return $filterDto; return $filterDto;
} }
public function getFilterSettings(): AssignmentFilterDto private function getFilterSettings(string $namespace): AssignmentFilterDto
{ {
if (null === $this->getSession()->get('assignment_filter')) { if (null === $data = $this->getSession()->get($namespace)) {
return new AssignmentFilterDto(); return new AssignmentFilterDto();
} }
return $this->loadFilterSettings();
}
public function loadFilterSettings(): AssignmentFilterDto
{
$data = $this->getSession()->get('assignment_filter');
$filterDto = new AssignmentFilterDto(); $filterDto = new AssignmentFilterDto();
if (isset($data['date_from'])) { if (isset($data['date_from'])) {
@@ -98,9 +96,9 @@ class AssignmentFilterHandler
return $filterDto; return $filterDto;
} }
public function saveFilterSettings(AssignmentFilterDto $filterDto): void private function saveFilterSettings(AssignmentFilterDto $filterDto, string $namespace): void
{ {
$this->getSession()->set('assignment_filter', [ $this->getSession()->set($namespace, [
'date_from' => $filterDto->getDateFrom()?->format('Y-m-d'), 'date_from' => $filterDto->getDateFrom()?->format('Y-m-d'),
'date_to' => $filterDto->getDateTo()?->format('Y-m-d'), 'date_to' => $filterDto->getDateTo()?->format('Y-m-d'),
'job_profile' => $filterDto->getJobProfile()?->getId(), 'job_profile' => $filterDto->getJobProfile()?->getId(),
+5 -5
View File
@@ -35,7 +35,7 @@
{%- block form_widget_simple -%} {%- block form_widget_simple -%}
{%- set type = type|default('text') -%} {%- set type = type|default('text') -%}
{%- if type != 'hidden' -%} {%- if type != 'hidden' -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset sm:text-sm sm:leading-6')|trim }) -%} {%- set attr = attr|merge({'class': (attr.class|default('') ~ ' block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset text-sm')|trim }) -%}
{%- if errors|length -%} {%- if errors|length -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' ring-red-500 placeholder-red-500 focus:ring-red-500' }) -%} {%- set attr = attr|merge({'class': attr.class|default('') ~ ' ring-red-500 placeholder-red-500 focus:ring-red-500' }) -%}
{% else %} {% else %}
@@ -52,7 +52,7 @@
{%- endblock form_widget_simple -%} {%- endblock form_widget_simple -%}
{%- block textarea_widget -%} {%- block textarea_widget -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset sm:text-sm sm:leading-6')|trim }) -%} {%- set attr = attr|merge({'class': (attr.class|default('') ~ ' block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset text-sm')|trim }) -%}
{%- if errors|length -%} {%- if errors|length -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' ring-red-500 placeholder-red-500 focus:ring-red-500' }) -%} {%- set attr = attr|merge({'class': attr.class|default('') ~ ' ring-red-500 placeholder-red-500 focus:ring-red-500' }) -%}
{% else %} {% else %}
@@ -95,7 +95,7 @@
{% endblock %} {% endblock %}
{%- block choice_widget_collapsed -%} {%- block choice_widget_collapsed -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset sm:text-sm sm:leading-6')|trim }) -%} {%- set attr = attr|merge({'class': (attr.class|default('') ~ ' block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset text-sm')|trim }) -%}
{%- if errors|length -%} {%- if errors|length -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' ring-red-500 placeholder-red-500 focus:ring-red-500' }) -%} {%- set attr = attr|merge({'class': attr.class|default('') ~ ' ring-red-500 placeholder-red-500 focus:ring-red-500' }) -%}
{% else %} {% else %}
@@ -162,7 +162,7 @@
{%- block datepicker_widget -%} {%- block datepicker_widget -%}
{%- set minDate = form.vars.min_date ? form.vars.min_date | date('Y-m-d') : null -%} {%- set minDate = form.vars.min_date ? form.vars.min_date | date('Y-m-d') : null -%}
{%- set maxDate = form.vars.max_date ? form.vars.max_date | date('Y-m-d') : null -%} {%- set maxDate = form.vars.max_date ? form.vars.max_date | date('Y-m-d') : null -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset sm:text-sm sm:leading-6')|trim }) -%} {%- set attr = attr|merge({'class': (attr.class|default('') ~ ' block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset text-sm')|trim }) -%}
{%- if errors|length -%} {%- if errors|length -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' ring-red-500 placeholder:red-500 focus:ring-red-500' }) -%} {%- set attr = attr|merge({'class': attr.class|default('') ~ ' ring-red-500 placeholder:red-500 focus:ring-red-500' }) -%}
{% else %} {% else %}
@@ -181,7 +181,7 @@
{%- endblock datepicker_widget %} {%- endblock datepicker_widget %}
{%- block autocomplete_widget -%} {%- block autocomplete_widget -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' autocomplete-input block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset sm:text-sm sm:leading-6')|trim }) -%} {%- set attr = attr|merge({'class': (attr.class|default('') ~ ' autocomplete-input block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset text-sm')|trim }) -%}
{%- if errors|length -%} {%- if errors|length -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' ring-red-500 placeholder-red-500 focus:ring-red-500' }) -%} {%- set attr = attr|merge({'class': attr.class|default('') ~ ' ring-red-500 placeholder-red-500 focus:ring-red-500' }) -%}
{% else %} {% else %}
+19 -1
View File
@@ -3,7 +3,7 @@
{% block title %}Einsatzübersicht{% endblock %} {% block title %}Einsatzübersicht{% endblock %}
{% block content %} {% block content %}
<h1 class="text-2xl font-bold pb-8"> <h1 class="text-2xl font-bold pb-4">
Einsatzübersicht Einsatzübersicht
</h1> </h1>
{% if errors|length %} {% if errors|length %}
@@ -18,6 +18,24 @@
</div> </div>
{% endif %} {% endif %}
{{ form_start(filterForm) }}
<div class="border border-gray-200 rounded-md p-2 mb-4">
<div class="grid grid-cols-2 md:grid-cols-5 gap-x-1 gap-y-2 pb-2">
{{ form_widget(filterForm.dateFrom) }}
{{ form_widget(filterForm.dateTo) }}
{{ form_widget(filterForm.jobProfile) }}
{{ form_widget(filterForm.destination) }}
{{ form_widget(filterForm.duration) }}
</div>
<div class="flex items-center space-x-2">
{{ form_widget(filterForm.apply, { 'attr': { 'class': 'btn btn--small' } }) }}
{{ form_widget(filterForm.reset, { 'attr': { 'class': 'btn btn--small btn--secondary' } }) }}
</div>
</div>
{{ form_rest(filterForm) }}
{{ form_end(filterForm) }}
<div class="grid sm:grid-cols-2 md:grid-cols-3 gap-4 pb-4"> <div class="grid sm:grid-cols-2 md:grid-cols-3 gap-4 pb-4">
{% for assignment in pagination %} {% for assignment in pagination %}
<div class="relative flex flex-col justify-between rounded-md border border-gray-200 bg-gray-100 p-4"> <div class="relative flex flex-col justify-between rounded-md border border-gray-200 bg-gray-100 p-4">