added delete timesheet record for admins #70 (#73)

This commit is contained in:
Kevin Papst
2018-01-09 21:59:32 +01:00
committed by GitHub
parent 42bf4f41f7
commit 098a1325d6
3 changed files with 30 additions and 6 deletions

View File

@@ -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

View File

@@ -42,12 +42,14 @@
<td class="hidden-xs"><a href="{{ path('profile'|route_alias, {'username' : entry.user.username}) }}">{{ widgets.label_user(entry.user) }}</a></td>
<td class="hidden-xs hidden-sm">{{ entry.description }}</td>
<td>
{% 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) }}
</td>
</tr>
{% endfor %}

View File

@@ -38,9 +38,11 @@
<td class="hidden-xs hidden-sm">{{ widgets.label_activity(entry.activity) }}</td>
<td class="hidden-xs hidden-sm">{{ entry.description }}</td>
<td>
{% 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})}) %}