feat: integrate with htmx
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Controller\Teamer\Application;
|
||||
use App\Controller\Traits\ReturnUrlTrait;
|
||||
use App\Entity\Application;
|
||||
use App\Entity\User;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@@ -27,24 +28,28 @@ class WithdrawController extends AbstractController
|
||||
#[IsGranted('WITHDRAW', subject: 'application')]
|
||||
public function index(Application $application, Request $request): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$teamer = $user->getTeamer();
|
||||
$assignment = $application->getAssignment();
|
||||
if (true === $request->isMethod('POST')) {
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$teamer = $user->getTeamer();
|
||||
$assignment = $application->getAssignment();
|
||||
|
||||
$this->entityManager->remove($application);
|
||||
$this->entityManager->flush();
|
||||
$this->entityManager->remove($application);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->logger->info('Withdraw application', [
|
||||
'teamer_id' => $teamer->getId(),
|
||||
'teamer_name' => (string) $teamer,
|
||||
'application_id' => $application->getId(),
|
||||
'assignment_id' => $assignment->getId(),
|
||||
'destination' => (string) $assignment->getDestination(),
|
||||
$this->logger->info('Withdraw application', [
|
||||
'teamer_id' => $teamer->getId(),
|
||||
'teamer_name' => (string) $teamer,
|
||||
'application_id' => $application->getId(),
|
||||
'assignment_id' => $assignment->getId(),
|
||||
'destination' => (string) $assignment->getDestination(),
|
||||
]);
|
||||
|
||||
return new HxRedirectResponse($this->getReturnUrl($request, 'app_teamer_index'));
|
||||
}
|
||||
|
||||
return $this->render('teamer/application/modal_withdraw.html.twig', [
|
||||
'application' => $application,
|
||||
]);
|
||||
|
||||
$returnUrl = $this->getReturnUrl($request, 'app_teamer_index');
|
||||
|
||||
return $this->redirect($returnUrl);
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,8 @@
|
||||
namespace App\Controller\Teamer;
|
||||
|
||||
use App\Entity\Feedback;
|
||||
use App\Model\AjaxModalResponseDto;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
@@ -13,13 +12,10 @@ class FeedbackController extends AbstractController
|
||||
{
|
||||
#[Route('/teamer/feedback/{uuid}', name: 'app_teamer_feedback')]
|
||||
#[IsGranted('VIEW', subject: 'feedback')]
|
||||
public function index(Feedback $feedback): JsonResponse
|
||||
public function index(Feedback $feedback): Response
|
||||
{
|
||||
$response = new AjaxModalResponseDto();
|
||||
$response->setContent($this->renderView('teamer/feedback/index.html.twig', [
|
||||
return $this->render('teamer/feedback/modal.html.twig', [
|
||||
'feedback' => $feedback,
|
||||
]));
|
||||
|
||||
return $this->json($response);
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,12 @@ namespace App\Controller\Teamer\Profile\Availability;
|
||||
use App\Entity\Availability;
|
||||
use App\Entity\User;
|
||||
use App\Form\AvailabilityType;
|
||||
use App\Model\AjaxModalResponseDto;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
@@ -24,14 +24,11 @@ class CreateController extends AbstractController
|
||||
|
||||
#[Route('/teamer/profile/availability/create', name: 'app_teamer_profile_availability_create')]
|
||||
#[IsGranted('ROLE_TEAMER')]
|
||||
public function index(Request $request): JsonResponse
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$response = new AjaxModalResponseDto();
|
||||
$action = $this->generateUrl('app_teamer_profile_availability_create');
|
||||
|
||||
$availability = new Availability();
|
||||
|
||||
$form = $this->createForm(AvailabilityType::class, $availability, ['action' => $action, 'ajax_submit' => true]);
|
||||
$form = $this->createForm(AvailabilityType::class, $availability);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
@@ -53,15 +50,11 @@ class CreateController extends AbstractController
|
||||
'availability' => (string) $availability,
|
||||
]);
|
||||
|
||||
$redirectUrl = $this->generateUrl('app_teamer_profile_availability_index');
|
||||
$response->setCloseAndRedirect($redirectUrl);
|
||||
} else {
|
||||
$content = $this->renderView('teamer/profile/availability/create.html.twig', [
|
||||
'form' => $form,
|
||||
]);
|
||||
$response->setContent($content);
|
||||
return new HxRedirectResponse($this->generateUrl('app_teamer_profile_availability_index'));
|
||||
}
|
||||
|
||||
return $this->json($response);
|
||||
return $this->render('teamer/profile/availability/modal_create.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,11 @@ namespace App\Controller\Teamer\Profile\Availability;
|
||||
|
||||
use App\Entity\Availability;
|
||||
use App\Entity\User;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
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;
|
||||
@@ -21,27 +23,33 @@ class DeleteController extends AbstractController
|
||||
|
||||
#[Route('/teamer/profile/availability/delete/{id}', name: 'app_teamer_profile_availability_delete')]
|
||||
#[IsGranted('DELETE', subject: 'availability')]
|
||||
public function index(Availability $availability): Response
|
||||
public function index(Availability $availability, Request $request): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$teamer = $user->getTeamer();
|
||||
if (true === $request->isMethod('POST')) {
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$teamer = $user->getTeamer();
|
||||
|
||||
if (null === $availability->getOwner()) {
|
||||
$teamer->removeAvailability($availability);
|
||||
} elseif ($teamer === $availability->getOwner()) {
|
||||
$this->entityManager->remove($availability);
|
||||
if (null === $availability->getOwner()) {
|
||||
$teamer->removeAvailability($availability);
|
||||
} elseif ($teamer === $availability->getOwner()) {
|
||||
$this->entityManager->remove($availability);
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Der Zeitraum wurde entfernt/gelöscht.');
|
||||
$this->logger->info('Delete availability', [
|
||||
'teamer_id' => $teamer->getId(),
|
||||
'teamer_name' => (string) $teamer,
|
||||
'availability' => (string) $availability,
|
||||
]);
|
||||
|
||||
return new HxRedirectResponse($this->generateUrl('app_teamer_profile_availability_index'));
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Der Zeitraum wurde entfernt/gelöscht.');
|
||||
$this->logger->info('Delete availability', [
|
||||
'teamer_id' => $teamer->getId(),
|
||||
'teamer_name' => (string) $teamer,
|
||||
'availability' => (string) $availability,
|
||||
return $this->render('teamer/profile/availability/modal_delete.html.twig', [
|
||||
'availability' => $availability,
|
||||
]);
|
||||
|
||||
return $this->redirectToRoute('app_teamer_profile_availability_index');
|
||||
}
|
||||
}
|
||||
@@ -6,14 +6,14 @@ use App\Entity\License;
|
||||
use App\Entity\Upload;
|
||||
use App\Entity\User;
|
||||
use App\Form\LicenseType;
|
||||
use App\Model\AjaxModalResponseDto;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use App\Model\UploadSessionDto;
|
||||
use App\Service\Upload\UploadHandler;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
@@ -28,11 +28,8 @@ class AddController extends AbstractController
|
||||
|
||||
#[Route('/teamer/profile/license/add', name: 'app_teamer_profile_license_add')]
|
||||
#[IsGranted('ROLE_TEAMER')]
|
||||
public function index(Request $request): JsonResponse
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$response = new AjaxModalResponseDto();
|
||||
$action = $this->generateUrl('app_teamer_profile_license_add');
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$license = new License();
|
||||
@@ -43,15 +40,7 @@ class AddController extends AbstractController
|
||||
$this->updateCertificate($user, $license, $uploadSession);
|
||||
}
|
||||
|
||||
$form = $this->createForm(
|
||||
LicenseType::class,
|
||||
$license,
|
||||
[
|
||||
'action' => $action,
|
||||
'ajax_submit' => true,
|
||||
'upload_session' => $uploadSession,
|
||||
]
|
||||
);
|
||||
$form = $this->createForm(LicenseType::class, $license, ['upload_session' => $uploadSession]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
@@ -69,16 +58,12 @@ class AddController extends AbstractController
|
||||
'license_type' => $license->getType(),
|
||||
]);
|
||||
|
||||
$redirectUrl = $this->generateUrl('app_teamer_profile_skills');
|
||||
$response->setCloseAndRedirect($redirectUrl);
|
||||
} else {
|
||||
$content = $this->renderView('teamer/profile/license/add.html.twig', [
|
||||
'form' => $form,
|
||||
]);
|
||||
$response->setContent($content);
|
||||
return new HxRedirectResponse($this->generateUrl('app_teamer_profile_skills'));
|
||||
}
|
||||
|
||||
return $this->json($response);
|
||||
return $this->render('teamer/profile/license/modal_add.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function updateCertificate(User $user, License $license, UploadSessionDto $uploadSession): void
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
namespace App\Controller\Teamer\Profile\License;
|
||||
|
||||
use App\Entity\License;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
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;
|
||||
@@ -20,20 +22,26 @@ class DeleteController extends AbstractController
|
||||
|
||||
#[Route('//teamer/profile/license/delete/{uuid}', name: 'app_teamer_profile_license_delete')]
|
||||
#[IsGranted('DELETE', subject: 'license')]
|
||||
public function index(License $license): Response
|
||||
public function index(License $license, Request $request): Response
|
||||
{
|
||||
$teamer = $license->getTeamer();
|
||||
if (true === $request->isMethod('POST')) {
|
||||
$teamer = $license->getTeamer();
|
||||
|
||||
$this->entityManager->remove($license);
|
||||
$this->entityManager->flush();
|
||||
$this->entityManager->remove($license);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Die Lizenz wurde gelöscht.');
|
||||
$this->logger->info('Delete license', [
|
||||
'teamer_id' => $teamer->getId(),
|
||||
'teamer_name' => (string) $teamer,
|
||||
'license_type' => $license->getType(),
|
||||
$this->addFlash('success', 'Die Lizenz wurde gelöscht.');
|
||||
$this->logger->info('Delete license', [
|
||||
'teamer_id' => $teamer->getId(),
|
||||
'teamer_name' => (string) $teamer,
|
||||
'license_type' => $license->getType(),
|
||||
]);
|
||||
|
||||
return new HxRedirectResponse($this->generateUrl('app_teamer_profile_skills'));
|
||||
}
|
||||
|
||||
return $this->render('teamer/profile/license/modal_delete.html.twig', [
|
||||
'license' => $license,
|
||||
]);
|
||||
|
||||
return $this->redirectToRoute('app_teamer_profile_skills');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user