diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 07ad980..df2761b 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -36,8 +36,8 @@ security: access_control: # - { path: ^/, roles: ROLE_USER } + - { path: ^/logout, roles: IS_AUTHENTICATED } - { path: ^/login, roles: PUBLIC_ACCESS } - - { path: ^/logout, roles: ROLE_USER } - { path: ^/index, roles: [ROLE_ADMIN, ROLE_CUISINIER, ROLE_SERVEUR]} - { path: ^/user, roles: ROLE_ADMIN } diff --git a/public/js/GestionPromotion/GestionPromotion.js b/public/js/GestionPromotion/GestionPromotion.js new file mode 100644 index 0000000..d4eac67 --- /dev/null +++ b/public/js/GestionPromotion/GestionPromotion.js @@ -0,0 +1,77 @@ +document.querySelector('.btn-gestion-promotion').addEventListener('click', function(event) { + event.preventDefault(); + + document.getElementById('container_modal'); + + fetch('/reductions') + .then(response => { + if (!response.ok) { + throw new Error('Erreur de chargement de la section Promotions'); + } + return response.text(); + }) + .then(html => { + // Insérer le HTML dans le conteneur et l'afficher + container_modal.innerHTML = html; + container_modal.style.display = 'block'; + }) + .catch(error => { + console.error('Erreur:', error); + }); +}); + +function addPromotion (event) { + document.getElementById('container_modal'); + + fetch(`/reductions/new`) + .then(response => { + return response.text(); + }) + .then(html => { + // Insérer le HTML dans le conteneur et l'afficher + container_modal.innerHTML = html; + container_modal.style.display = 'block'; + }) + .catch(error => { + console.error('Erreur:', error); + }); +} + + +function updatePromotion (event) { + document.getElementById('container_modal'); + const reductionsIdString = event.getAttribute('data-id'); + let reductionsId = parseInt(reductionsIdString); + + fetch(`/reductions/${reductionsId}/edit`) + .then(response => { + return response.text(); + }) + .then(html => { + // Insérer le HTML dans le conteneur et l'afficher + container_modal.innerHTML = html; + container_modal.style.display = 'block'; + }) + .catch(error => { + console.error('Erreur:', error); + }); +} + +function deletePromotion (event) { + document.getElementById('container_modal'); + const reductionsIdString = event.getAttribute('data-id'); + let reductionsId = parseInt(reductionsIdString); + + fetch(`/reductions/${reductionsId}`) + .then(response => { + return response.text(); + }) + .then(html => { + // Insérer le HTML dans le conteneur et l'afficher + container_modal.innerHTML = html; + container_modal.style.display = 'block'; + }) + .catch(error => { + console.error('Erreur:', error); + }); +} \ No newline at end of file diff --git a/src/Controller/ReductionsController.php b/src/Controller/ReductionsController.php index da7cdeb..6c99bdd 100644 --- a/src/Controller/ReductionsController.php +++ b/src/Controller/ReductionsController.php @@ -26,14 +26,17 @@ final class ReductionsController extends AbstractController public function new(Request $request, EntityManagerInterface $entityManager): Response { $reduction = new Reductions(); - $form = $this->createForm(ReductionsType::class, $reduction); + $form = $this->createForm(ReductionsType::class, $reduction, [ + 'action' => $this->generateUrl('app_reductions_new') + ] ); $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { $entityManager->persist($reduction); $entityManager->flush(); - return $this->redirectToRoute('app_reductions_index', [], Response::HTTP_SEE_OTHER); + return $this->redirectToRoute('app_index', [], Response::HTTP_SEE_OTHER); } return $this->render('reductions/new.html.twig', [ @@ -46,13 +49,15 @@ final class ReductionsController extends AbstractController #[Route('/{id}/edit', name: 'app_reductions_edit', methods: ['GET', 'POST'])] public function edit(Request $request, Reductions $reduction, EntityManagerInterface $entityManager): Response { - $form = $this->createForm(ReductionsType::class, $reduction); + $form = $this->createForm(ReductionsType::class, $reduction, [ + 'action' => $this->generateUrl('app_reductions_edit', ['id' => $reduction->getId()]) + ]); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $entityManager->flush(); - return $this->redirectToRoute('app_reductions_index', [], Response::HTTP_SEE_OTHER); + return $this->redirectToRoute('app_index', [], Response::HTTP_SEE_OTHER); } return $this->render('reductions/edit.html.twig', [ @@ -69,6 +74,6 @@ final class ReductionsController extends AbstractController $entityManager->flush(); } - return $this->redirectToRoute('app_reductions_index', [], Response::HTTP_SEE_OTHER); + return $this->redirectToRoute('app_index', [], Response::HTTP_SEE_OTHER); } } diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index c99f38c..544e59d 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -26,7 +26,9 @@ class UserController extends AbstractController public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, Security $security, EntityManagerInterface $entityManager): Response { $user = new Utilisateurs(); - $form = $this->createForm(AddUserFormType::class, $user); + $form = $this->createForm(AddUserFormType::class, $user, [ + 'action' => $this->generateUrl('add_user') + ]); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { @@ -53,7 +55,9 @@ class UserController extends AbstractController public function update(Request $request, UserPasswordHasherInterface $userPasswordHasher, Security $security, EntityManagerInterface $entityManager, int $id): Response { $user = $this->utilisateursRepository->find($id); - $form = $this->createForm(UpdateUserType::class, $user); + $form = $this->createForm(UpdateUserType::class, $user , [ + 'action' => $this->generateUrl('update-user', ['id' => $user->getId()]) + ]); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { @@ -66,7 +70,7 @@ class UserController extends AbstractController $entityManager->persist($user); $entityManager->flush(); - return $this->redirectToRoute('app_index'); + return $security->login($user, LoginAuthenticator::class, 'main'); } return $this->render('user/update.html.twig', [ diff --git a/templates/index/admin.html.twig b/templates/index/admin.html.twig index 9c6d107..11cb279 100644 --- a/templates/index/admin.html.twig +++ b/templates/index/admin.html.twig @@ -53,7 +53,7 @@
  • -
    +
    {{ ux_icon('lsicon:badge-promotion-outline') }} Gestion Promotion
    @@ -119,7 +119,7 @@
    - +
    + {% endblock %} \ No newline at end of file diff --git a/templates/reductions/index.html.twig b/templates/reductions/index.html.twig index 9eef75b..600d45b 100644 --- a/templates/reductions/index.html.twig +++ b/templates/reductions/index.html.twig @@ -32,11 +32,11 @@ {{ reduction.DateDebut ? reduction.DateDebut|date('Y-m-d H:i:s') : '' }} {{ reduction.DateFin ? reduction.DateFin|date('Y-m-d H:i:s') : '' }} -
    + {{ include('reductions/_delete_form.html.twig') }}
    - Modifier + {% else %} @@ -47,5 +47,9 @@ - Créer une réduction + {% endblock %} + +{% block javascripts %} + +{% endblock %} \ No newline at end of file