Skip to content

Commit

Permalink
Fermetures exceptionnelles : autoriser la suppression des fermetures …
Browse files Browse the repository at this point in the history
…futures (elefan-grenoble#977)

* ClosingException: allow deleting future

* also in list view
  • Loading branch information
raphodn authored and OursDesCavernes committed Jan 20, 2024
1 parent ef10e3d commit b9bbf8d
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% set delete_forms = delete_forms ?? [] %}

<table class="responsive-table">
<thead>
<tr>
Expand All @@ -19,7 +21,15 @@
<td title="{{ closingException.createdAt | date_time }}">
{{ closingException.createdAt | date_short }}
</td>
<td></td>
<td>
{% if delete_forms and delete_forms[closingException.id] is defined %}
{{ form_start(delete_forms[closingException.id]) }}
<a href="#" class="btn-floating waves-effect waves-light red" onclick="var r = confirm('Etes-vous sûr de vouloir supprimer cette fermeture exceptionnelle ?!'); if (r == true) {$(this).closest('form').submit();}; event.stopPropagation();" title="⚠️ Supprimer la fermeture exceptionnelle ⚠️">
<i class="material-icons left">delete</i>
</a>
{{ form_end(delete_forms[closingException.id]) }}
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
Expand Down
6 changes: 4 additions & 2 deletions app/Resources/views/admin/closingexception/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
{% block content %}
<div class="card-panel blue lighten-3">
<i class="material-icons left">info</i>
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.
<br />
⚠️ Les créneaux étant générés à l'avance, il faut définir le jour de fermeture d'avantage en amont ⚠️
</div>

<h4>Fermetures exceptionnelles à venir ({{ closingExceptionsFuture | length }})</h4>

{% 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 %}

<br />
Expand Down
2 changes: 1 addition & 1 deletion app/Resources/views/admin/closingexception/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
{% block content %}
<h4>Liste des fermetures exceptionnelles ({{ closingExceptions | length }})</h4>

{% 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 %}
2 changes: 1 addition & 1 deletion app/Resources/views/process/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
{% if processUpdate.date < lastShiftDate and new %}
<tr class="last-shift">
<td><i class="material-icons left">date_range</i>{{ lastShiftDate | date_fr_full_with_time }}</td>
<td colspan="{% if is_granted("ROLE_PROCESS_MANAGER") %}3{% endif %}" style="text-align: center">⬆️ Depuis et ⬇️ Avant mon dernier créneau️</td>
<td colspan="{% if is_granted("ROLE_PROCESS_MANAGER") %}3{% endif %}" style="text-align: center">⬆️ Depuis et ⬇️ Avant mon dernier créneau</td>
<td></td>
</tr>
{% set new = false %}
Expand Down
54 changes: 52 additions & 2 deletions src/AppBundle/Controller/AdminClosingExceptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
));
}

Expand All @@ -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
));
}

Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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();
}
}
14 changes: 14 additions & 0 deletions src/AppBundle/Entity/ClosingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit b9bbf8d

Please sign in to comment.