diff --git a/src/TimesheetBundle/Controller/Admin/TimesheetController.php b/src/TimesheetBundle/Controller/Admin/TimesheetController.php index c4002ecf..4d959e9e 100644 --- a/src/TimesheetBundle/Controller/Admin/TimesheetController.php +++ b/src/TimesheetBundle/Controller/Admin/TimesheetController.php @@ -108,6 +108,26 @@ class TimesheetController extends AbstractController return $this->create($request, 'admin_timesheet', 'TimesheetBundle:admin:timesheet_edit.html.twig'); } + /** + * The route to delete an existing entry. + * + * @Route("/{id}/delete", name="admin_timesheet_delete") + * @Method({"GET", "POST"}) + * @Security("is_granted('delete', entry)") + * + * @param Timesheet $entry + * @param Request $request + * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response + */ + public function deleteAction(Timesheet $entry, Request $request) + { + $entityManager = $this->getDoctrine()->getManager(); + $entityManager->remove($entry); + $entityManager->flush(); + + return $this->redirectToRoute('admin_timesheet_paginated', ['page' => $request->get('page')]); + } + /** * @param Timesheet $entry * @return \Symfony\Component\Form\FormInterface diff --git a/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig b/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig index 872a5235..6f77bbc8 100644 --- a/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig +++ b/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig @@ -42,12 +42,14 @@ {{ widgets.label_user(entry.user) }} {{ entry.description }} + {% set actionButtons = {'edit': path('admin_timesheet_edit', {'id' : entry.id, 'page': page})} %} {% if entry.end %} - {{ widgets.button_group({'edit': path('admin_timesheet_edit', {'id' : entry.id, 'page': page}), 'trash': '#'}) }} - {% else %} - {{ widgets.button_group({'stop': path('admin_timesheet_stop', {'id' : entry.id}), 'edit': path('admin_timesheet_edit', {'id' : entry.id, 'page': page}), 'trash': '#'}) }} + {% set actionButtons = {'stop': path('admin_timesheet_stop', {'id' : entry.id})}|merge(actionButtons) %} {% endif %} - + {% if is_granted('delete', entry) %} + {% set actionButtons = actionButtons|merge({'trash': path('admin_timesheet_delete', {'id' : entry.id, 'page': page})}) %} + {% endif %} + {{ widgets.button_group(actionButtons) }} {% endfor %} diff --git a/src/TimesheetBundle/Resources/views/timesheet/index.html.twig b/src/TimesheetBundle/Resources/views/timesheet/index.html.twig index 9c4b284b..e5926ed2 100644 --- a/src/TimesheetBundle/Resources/views/timesheet/index.html.twig +++ b/src/TimesheetBundle/Resources/views/timesheet/index.html.twig @@ -38,9 +38,11 @@ {{ widgets.label_activity(entry.activity) }} {{ entry.description }} - {% set actionButtons = {'repeat': path('timesheet_start', {'id' : entry.activity.id}), 'edit': path('timesheet_edit', {'id' : entry.id, 'page': page})} %} + {% set actionButtons = {'edit': path('timesheet_edit', {'id' : entry.id, 'page': page})} %} {% if entry.end %} - {% set actionButtons = {'stop': path('timesheet_stop', {'id' : entry.id}), 'edit': path('timesheet_edit', {'id' : entry.id, 'page': page})} %} + {% set actionButtons = {'repeat': path('timesheet_start', {'id' : entry.activity.id})}|merge(actionButtons) %} + {% else %} + {% set actionButtons = {'stop': path('timesheet_stop', {'id' : entry.id})}|merge(actionButtons) %} {% endif %} {% if is_granted('delete', entry) %} {% set actionButtons = actionButtons|merge({'trash': path('timesheet_delete', {'id' : entry.id, 'page': page})}) %}