Feat: Refactor assignment filter to modal
This commit is contained in:
@@ -24,12 +24,7 @@ class IndexController extends AbstractController
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$this->filterHandler->setNamespace('filter:assignment:admin');
|
||||
$filterForm = $this->filterHandler->getForm();
|
||||
$filterDto = $this->filterHandler->handleRequest($filterForm, $request);
|
||||
if (true === $filterDto->isReset()) {
|
||||
return $this->redirectToRoute('app_admin_assignment_index');
|
||||
}
|
||||
$filterDto = $this->filterHandler->getFilterSettings();
|
||||
|
||||
$query = $this
|
||||
->assignmentRepository
|
||||
@@ -48,7 +43,6 @@ class IndexController extends AbstractController
|
||||
|
||||
return $this->render('admin/assignment/index.html.twig', [
|
||||
'pagination' => $pagination,
|
||||
'filterForm' => $filterForm,
|
||||
'filterDto' => $filterDto,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Common;
|
||||
|
||||
use App\Controller\Traits\ReturnUrlTrait;
|
||||
use App\Form\AssignmentFilterType;
|
||||
use App\Model\AjaxModalResponseDto;
|
||||
use App\Repository\AssignmentRepository;
|
||||
use App\Service\Common\AssignmentFilterHandler;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class AssignmentFilterController extends AbstractController
|
||||
{
|
||||
use ReturnUrlTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly AssignmentFilterHandler $filterHandler,
|
||||
private readonly AssignmentRepository $assignmentRepository
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/common/assignment/filter', name: 'app_common_assignment_filter')]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$response = new AjaxModalResponseDto();
|
||||
$formAction = $this->generateUrl('app_common_assignment_filter', ['r' => $request->query->get('r')]);
|
||||
$formData = $this->filterHandler->getFilterSettings();
|
||||
$filterOptions = $this->assignmentRepository->getFilterOptions();
|
||||
$formOptions = [
|
||||
'action' => $formAction,
|
||||
'ajax_submit' => true,
|
||||
'min_date' => $filterOptions['minDate'],
|
||||
'max_date' => $filterOptions['maxDate'],
|
||||
'job_profiles' => $filterOptions['jobProfiles'],
|
||||
'destinations' => $filterOptions['destinations'],
|
||||
];
|
||||
|
||||
$form = $this->createForm(AssignmentFilterType::class, $formData, $formOptions);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->filterHandler->handleRequest($form);
|
||||
$returnUrl = $this->getReturnUrl($request, 'app_admin_assignment_index');
|
||||
$response->setCloseAndRedirect($returnUrl);
|
||||
} else {
|
||||
$response->setContent($this->renderView('common/assignment_filter.html.twig', [
|
||||
'filterForm' => $form,
|
||||
'filterDto' => $form->getData(),
|
||||
]));
|
||||
}
|
||||
|
||||
return $this->json($response);
|
||||
}
|
||||
}
|
||||
@@ -34,12 +34,7 @@ class IndexController extends AbstractController
|
||||
// Validate teamer data to show missing data right away
|
||||
$errors = $this->validator->validate($teamer, null, ['profile_preflight']);
|
||||
|
||||
$this->filterHandler->setNamespace('filter:assignment:teamer');
|
||||
$filterForm = $this->filterHandler->getForm();
|
||||
$filterDto = $this->filterHandler->handleRequest($filterForm, $request);
|
||||
if (true === $filterDto->isReset()) {
|
||||
return $this->redirectToRoute('app_teamer_index');
|
||||
}
|
||||
$filterDto = $this->filterHandler->getFilterSettings();
|
||||
|
||||
$query = $this
|
||||
->assignmentRepository
|
||||
@@ -60,7 +55,6 @@ class IndexController extends AbstractController
|
||||
'teamer' => $teamer,
|
||||
'errors' => $errors,
|
||||
'pagination' => $pagination,
|
||||
'filterForm' => $filterForm,
|
||||
'filterDto' => $filterDto,
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user