From a60403942641b49a7be72b9309925f040220cda1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Mon, 23 Oct 2023 16:19:10 +0200 Subject: [PATCH] Feat: Add filter toggle and info about active filters for teamer --- src/Controller/Teamer/IndexController.php | 1 + src/Model/AssignmentFilterDto.php | 21 ++++++++++++++ templates/teamer/index.html.twig | 34 ++++++++++++++--------- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/Controller/Teamer/IndexController.php b/src/Controller/Teamer/IndexController.php index 486d81a..92d0b3d 100644 --- a/src/Controller/Teamer/IndexController.php +++ b/src/Controller/Teamer/IndexController.php @@ -60,6 +60,7 @@ class IndexController extends AbstractController 'errors' => $errors, 'pagination' => $pagination, 'filterForm' => $filterForm, + 'filterDto' => $filterDto, ]); } } \ No newline at end of file diff --git a/src/Model/AssignmentFilterDto.php b/src/Model/AssignmentFilterDto.php index 047cd78..dc2c3f9 100644 --- a/src/Model/AssignmentFilterDto.php +++ b/src/Model/AssignmentFilterDto.php @@ -24,6 +24,27 @@ class AssignmentFilterDto $this->reset = $reset; } + public function isActive(): bool + { + return $this->getActiveFiltersCount() > 0; + } + + public function getActiveFiltersCount(): int + { + $freshInstance = new static(); + $filterCount = 0; + $reflection = new \ReflectionClass(static::class); + + foreach ($reflection->getProperties() as $property) { + $name = $property->getName(); + if ($this->$name !== $freshInstance->$name) { + ++$filterCount; + } + } + + return $filterCount; + } + public function getDateFrom(): ?\DateTimeImmutable { return $this->dateFrom; diff --git a/templates/teamer/index.html.twig b/templates/teamer/index.html.twig index 510f211..6a06d98 100644 --- a/templates/teamer/index.html.twig +++ b/templates/teamer/index.html.twig @@ -19,24 +19,32 @@ {% endif %} {{ form_start(filterForm) }} -
-
- {{ form_row(filterForm.dateFrom) }} - {{ form_row(filterForm.dateTo) }} - {{ form_row(filterForm.jobProfile) }} - {{ form_row(filterForm.destination) }} - {{ form_row(filterForm.duration) }} -
-
- {{ form_widget(filterForm.apply, { 'attr': { 'class': 'btn btn--small' } }) }} - {{ form_widget(filterForm.reset, { 'attr': { 'class': 'btn btn--small btn--secondary' } }) }} +
+ +
{{ form_rest(filterForm) }} {{ form_end(filterForm) }} - -
+ {{ knp_pagination_render(pagination, 'paginator/sliding_boxes.html.twig') }} +
{% for assignment in pagination %}