From b9bbf8dff68203adf6c6a76c90a82f742a1d3f24 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Sat, 2 Sep 2023 17:08:50 +0200 Subject: [PATCH] Fermetures exceptionnelles : autoriser la suppression des fermetures futures (#977) * ClosingException: allow deleting future * also in list view --- .../closingexception/_partial/table.html.twig | 12 ++++- .../admin/closingexception/index.html.twig | 6 ++- .../admin/closingexception/list.html.twig | 2 +- app/Resources/views/process/list.html.twig | 2 +- .../AdminClosingExceptionController.php | 54 ++++++++++++++++++- src/AppBundle/Entity/ClosingException.php | 14 +++++ 6 files changed, 83 insertions(+), 7 deletions(-) diff --git a/app/Resources/views/admin/closingexception/_partial/table.html.twig b/app/Resources/views/admin/closingexception/_partial/table.html.twig index 3ddacb15c..f80071f38 100644 --- a/app/Resources/views/admin/closingexception/_partial/table.html.twig +++ b/app/Resources/views/admin/closingexception/_partial/table.html.twig @@ -1,3 +1,5 @@ +{% set delete_forms = delete_forms ?? [] %} + @@ -19,7 +21,15 @@ - + {% endfor %} diff --git a/app/Resources/views/admin/closingexception/index.html.twig b/app/Resources/views/admin/closingexception/index.html.twig index fa5fe4c3d..f3f09c0b5 100644 --- a/app/Resources/views/admin/closingexception/index.html.twig +++ b/app/Resources/views/admin/closingexception/index.html.twig @@ -11,13 +11,15 @@ {% block content %}
info - Aucun créneau ne sera généré le jour de la fermeture exceptionnelle. + Aucun créneau ne sera généré pour le jour de la fermeture exceptionnelle. +
+ ⚠️ Les créneaux étant générés à l'avance, il faut définir le jour de fermeture d'avantage en amont ⚠️

Fermetures exceptionnelles à venir ({{ closingExceptionsFuture | length }})

{% if closingExceptionsFuture | length %} - {% include "admin/closingexception/_partial/table.html.twig" with { closingExceptions: closingExceptionsFuture } %} + {% include "admin/closingexception/_partial/table.html.twig" with { closingExceptions: closingExceptionsFuture, delete_forms: delete_forms } %} {% endif %}
diff --git a/app/Resources/views/admin/closingexception/list.html.twig b/app/Resources/views/admin/closingexception/list.html.twig index fb27297dd..fdf0159d0 100644 --- a/app/Resources/views/admin/closingexception/list.html.twig +++ b/app/Resources/views/admin/closingexception/list.html.twig @@ -12,5 +12,5 @@ {% block content %}

Liste des fermetures exceptionnelles ({{ closingExceptions | length }})

-{% include "admin/closingexception/_partial/table.html.twig" with { closingExceptions: closingExceptions } %} +{% include "admin/closingexception/_partial/table.html.twig" with { closingExceptions: closingExceptions, delete_forms: delete_forms } %} {% endblock %} diff --git a/app/Resources/views/process/list.html.twig b/app/Resources/views/process/list.html.twig index e73e35705..9b40b62e4 100644 --- a/app/Resources/views/process/list.html.twig +++ b/app/Resources/views/process/list.html.twig @@ -44,7 +44,7 @@ {% if processUpdate.date < lastShiftDate and new %} - + {% set new = false %} diff --git a/src/AppBundle/Controller/AdminClosingExceptionController.php b/src/AppBundle/Controller/AdminClosingExceptionController.php index 27763d42b..a9a2aab07 100644 --- a/src/AppBundle/Controller/AdminClosingExceptionController.php +++ b/src/AppBundle/Controller/AdminClosingExceptionController.php @@ -35,9 +35,15 @@ public function indexAction(Request $request) $closingExceptionsFuture = $em->getRepository('AppBundle:ClosingException')->findFutures(); $closingExceptionsPast = $em->getRepository('AppBundle:ClosingException')->findPast(10); # only the 10 last + $delete_forms = array(); + foreach ($closingExceptionsFuture as $closingException) { + $delete_forms[$closingException->getId()] = $this->getDeleteForm($closingException)->createView(); + } + return $this->render('admin/closingexception/index.html.twig', array( 'closingExceptionsFuture' => $closingExceptionsFuture, - 'closingExceptionsPast' => $closingExceptionsPast + 'closingExceptionsPast' => $closingExceptionsPast, + 'delete_forms' => $delete_forms )); } @@ -53,8 +59,16 @@ public function listAction(Request $request) $closingExceptions = $em->getRepository('AppBundle:ClosingException')->findAll(); + $delete_forms = array(); + foreach ($closingExceptions as $closingException) { + if (!$closingException->getIsPast()) { + $delete_forms[$closingException->getId()] = $this->getDeleteForm($closingException)->createView(); + } + } + return $this->render('admin/closingexception/list.html.twig', array( - 'closingExceptions' => $closingExceptions + 'closingExceptions' => $closingExceptions, + 'delete_forms' => $delete_forms )); } @@ -90,6 +104,30 @@ public function newAction(Request $request) )); } + /** + * Closing exception delete + * + * @Route("/{id}", name="admin_closingexception_delete", methods={"DELETE"}) + * @Security("has_role('ROLE_ADMIN')") + */ + public function deleteAction(Request $request, ClosingException $closingException) + { + $session = new Session(); + $em = $this->getDoctrine()->getManager(); + + $form = $this->getDeleteForm($closingException); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em->remove($closingException); + $em->flush(); + + $session->getFlashBag()->add('success', 'La fermeture exceptionnelle a bien été supprimée !'); + } + + return $this->redirectToRoute('admin_closingexception_index'); + } + /** * Closing exception widget generator * @@ -123,4 +161,16 @@ public function widgetGeneratorAction(Request $request) 'form' => $form->createView(), )); } + + /** + * @param ClosingException $closingException + * @return \Symfony\Component\Form\FormInterface + */ + protected function getDeleteForm(ClosingException $closingException) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('admin_closingexception_delete', array('id' => $closingException->getId()))) + ->setMethod('DELETE') + ->getForm(); + } } diff --git a/src/AppBundle/Entity/ClosingException.php b/src/AppBundle/Entity/ClosingException.php index 8d924d50f..a7afd6ce6 100644 --- a/src/AppBundle/Entity/ClosingException.php +++ b/src/AppBundle/Entity/ClosingException.php @@ -151,4 +151,18 @@ public function getCreatedBy() { return $this->createdBy; } + + /** + * Return if the closingException is past for a given date + * + * @param \DateTime $date + * @return boolean + */ + public function getIsPast(\Datetime $date = null) + { + if (!$date) { + $date = new \DateTime('now'); + } + return $date > $this->date; + } }
{{ closingException.createdAt | date_short }} + {% if delete_forms and delete_forms[closingException.id] is defined %} + {{ form_start(delete_forms[closingException.id]) }} + + delete + + {{ form_end(delete_forms[closingException.id]) }} + {% endif %} +
date_range{{ lastShiftDate | date_fr_full_with_time }}⬆️ Depuis et ⬇️ Avant mon dernier créneau️⬆️ Depuis et ⬇️ Avant mon dernier créneau