timesheet controller refactoring (#796)

This commit is contained in:
Kevin Papst
2019-05-19 23:52:43 +02:00
committed by GitHub
parent 46ff78a4c4
commit ec174a38a9
15 changed files with 304 additions and 396 deletions

View File

@@ -31,6 +31,7 @@ import KimaiEvent from "./plugins/KimaiEvent";
import KimaiAPILink from "./plugins/KimaiAPILink";
import KimaiAlert from "./plugins/KimaiAlert";
import KimaiAutocomplete from "./plugins/KimaiAutocomplete";
import KimaiToolbarAction from "./plugins/KimaiToolbarAction";
export default class KimaiLoader {
@@ -61,6 +62,7 @@ export default class KimaiLoader {
kimai.registerPlugin(new KimaiActiveRecords('li.messages-menu', 'li.messages-menu-empty'));
kimai.registerPlugin(new KimaiAPILink('api-link'));
kimai.registerPlugin(new KimaiAutocomplete('.js-autocomplete'));
kimai.registerPlugin(new KimaiToolbarAction('toolbar-action'));
//kimai.registerPlugin(new KimaiPauseRecord('li.messages-menu ul.menu li'));
// notify all listeners that Kimai plugins can now be registered

View File

@@ -0,0 +1,56 @@
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import KimaiPlugin from '../KimaiPlugin';
/**
* Needs to be initialized with a class name.
*
* A link like <a href=# class=remoteLink> can be activated with:
* new KimaiToolbarAction('remoteLink')
*
* @param selector
*/
export default class KimaiToolbarAction extends KimaiPlugin {
constructor(selector) {
super();
this.selector = selector;
}
init() {
const self = this;
document.addEventListener('click', function(event) {
let target = event.target;
while (!target.matches('body')) {
if (target.classList.contains(self.selector)) {
const form = document.querySelector('div.toolbar form.navbar-form');
if (form === null) {
return;
}
const prevAction = form.action;
const prevMethod = form.method;
form.target = '_blank';
form.action = target.href;
if (target.dataset.method !== undefined) {
form.method = target.dataset.method;
}
form.submit();
form.target = '';
form.action = prevAction;
form.method = prevMethod;
event.preventDefault();
event.stopPropagation();
}
target = target.parentNode;
}
});
}
}

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,5 @@
{
"build/app.js": "./app.js?748657cabe85b735a003",
"build/app.js": "./app.js?4d1c16b6cec885d40370",
"build/app.css": "./app.css?e4b4080f26821060103657b889a6b1cd",
"build/fonts/fa-solid-900.woff2": "./fonts/fa-solid-900.woff2?e8a92a29",
"build/images/fa-solid-900.svg": "./images/fa-solid-900.svg?666a82cb",

View File

@@ -10,21 +10,22 @@
namespace App\Controller;
use App\Configuration\TimesheetConfiguration;
use App\Entity\Tag;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Form\TimesheetEditForm;
use App\Form\Toolbar\TimesheetToolbarForm;
use App\Repository\ActivityRepository;
use App\Repository\ProjectRepository;
use App\Repository\Query\TimesheetQuery;
use App\Repository\TimesheetRepository;
use App\Timesheet\UserDateTimeFactory;
use Doctrine\Common\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Doctrine\Common\Collections\ArrayCollection;
use Pagerfanta\Pagerfanta;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Helper functions for Timesheet controller
*/
trait TimesheetControllerTrait
abstract class TimesheetAbstractController extends AbstractController
{
/**
* @var UserDateTimeFactory
@@ -61,14 +62,56 @@ trait TimesheetControllerTrait
return $this->getDoctrine()->getRepository(Timesheet::class);
}
protected function index($page, Request $request, string $renderTemplate)
{
$query = new TimesheetQuery();
$query->setPage($page);
$form = $this->getToolbarForm($query);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/** @var TimesheetQuery $query */
$query = $form->getData();
if (null !== $query->getBegin()) {
$query->getBegin()->setTime(0, 0, 0);
}
if (null !== $query->getEnd()) {
$query->getEnd()->setTime(23, 59, 59);
}
}
if (!$this->includeUserInForms()) {
$query->setUser($this->getUser());
}
if ($query->hasTags()) {
$query->setTags(
new ArrayCollection(
$this->getDoctrine()->getRepository(Tag::class)->findIdsByTagNameList(implode(',', $query->getTags()->toArray()))
)
);
}
/* @var $entries Pagerfanta */
$entries = $this->getRepository()->findByQuery($query);
return $this->render($renderTemplate, [
'entries' => $entries,
'page' => $query->getPage(),
'query' => $query,
'showFilter' => $form->isSubmitted(),
'toolbarForm' => $form->createView(),
'showSummary' => $this->includeSummary(),
]);
}
/**
* @param Timesheet $entry
* @param Request $request
* @param string $redirectRoute
* @param string $renderTemplate
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
protected function edit(Timesheet $entry, Request $request, $redirectRoute, $renderTemplate)
protected function edit(Timesheet $entry, Request $request, string $renderTemplate)
{
$editForm = $this->getEditForm($entry, $request->get('page'));
$editForm->handleRequest($request);
@@ -80,7 +123,7 @@ trait TimesheetControllerTrait
$this->flashSuccess('action.update.success');
return $this->redirectToRoute($redirectRoute, ['page' => $request->get('page', 1)]);
return $this->redirectToRoute($this->getTimesheetRoute(), ['page' => $request->get('page', 1)]);
}
return $this->render($renderTemplate, [
@@ -91,13 +134,12 @@ trait TimesheetControllerTrait
/**
* @param Request $request
* @param string $redirectRoute
* @param string $renderTemplate
* @param ProjectRepository $projectRepository
* @param ActivityRepository $activityRepository
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
protected function create(Request $request, $redirectRoute, $renderTemplate, ProjectRepository $projectRepository, ActivityRepository $activityRepository)
protected function create(Request $request, string $renderTemplate, ProjectRepository $projectRepository, ActivityRepository $activityRepository)
{
$entry = new Timesheet();
$entry->setUser($this->getUser());
@@ -173,7 +215,7 @@ trait TimesheetControllerTrait
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
}
return $this->redirectToRoute($redirectRoute);
return $this->redirectToRoute($this->getTimesheetRoute());
}
return $this->render($renderTemplate, [
@@ -182,57 +224,119 @@ trait TimesheetControllerTrait
]);
}
/**
* @param Request $request
* @param string $renderTemplate
* @return Response
*/
protected function export(Request $request, string $renderTemplate)
{
$query = new TimesheetQuery();
$query->setResultType(TimesheetQuery::RESULT_TYPE_OBJECTS);
$form = $this->getToolbarForm($query);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/** @var TimesheetQuery $query */
$query = $form->getData();
}
// by default the current month is exported, but it can be overwritten
// this should not be removed, otherwise we would export EVERY available record in the admin section
// as the default toolbar query does neither limit the user nor the date-range!
if (null === $query->getBegin()) {
$query->setBegin($this->dateTime->createDateTime('first day of this month'));
}
$query->getBegin()->setTime(0, 0, 0);
if (null === $query->getEnd()) {
$query->setEnd($this->dateTime->createDateTime('last day of this month'));
}
$query->getEnd()->setTime(23, 59, 59);
if (!$this->includeUserInForms()) {
$query->setUser($this->getUser());
}
/* @var $entries Pagerfanta */
$entries = $this->getRepository()->findByQuery($query);
return $this->render($renderTemplate, [
'entries' => $entries,
'query' => $query,
]);
}
/**
* @param Timesheet $entry
* @return \Symfony\Component\Form\FormInterface
*/
abstract protected function getCreateForm(Timesheet $entry);
protected function getCreateForm(Timesheet $entry)
{
return $this->createForm(TimesheetEditForm::class, $entry, [
'action' => $this->generateUrl($this->getCreateRoute()),
'include_rate' => $this->isGranted('edit_rate', $entry),
'include_user' => $this->includeUserInForms(),
'customer' => true,
]);
}
/**
* @param Timesheet $entry
* @param int $page
* @return \Symfony\Component\Form\FormInterface
* @return FormInterface
*/
abstract protected function getEditForm(Timesheet $entry, $page);
/**
* Adds a "successful" flash message to the stack.
*
* @param string $translationKey
* @param array $parameter
*/
abstract protected function flashSuccess($translationKey, $parameter = []);
/**
* Adds a "error" flash message to the stack.
*
* @param $translationKey
* @param array $parameter
*/
abstract protected function flashError($translationKey, $parameter = []);
/**
* Shortcut to return the Doctrine Registry service.
*
* @throws \LogicException If DoctrineBundle is not available
*/
abstract protected function getDoctrine(): ManagerRegistry;
/**
* Returns a RedirectResponse to the given route with the given parameters.
*/
abstract protected function redirectToRoute(string $route, array $parameters = [], int $status = 302): RedirectResponse;
/**
* Renders a view.
*/
abstract protected function render(string $view, array $parameters = [], Response $response = null): Response;
/**
* Get a user from the Security Token Storage.
*
* @return User
* @throws \LogicException If SecurityBundle is not available
*/
abstract protected function getUser();
protected function getEditForm(Timesheet $entry, $page)
{
return $this->createForm(TimesheetEditForm::class, $entry, [
'action' => $this->generateUrl($this->getEditRoute(), [
'id' => $entry->getId(),
'page' => $page,
]),
'include_rate' => $this->isGranted('edit_rate', $entry),
'include_exported' => $this->isGranted('edit_export', $entry),
'include_user' => $this->includeUserInForms(),
'customer' => true,
]);
}
/**
* @param TimesheetQuery $query
* @return FormInterface
*/
protected function getToolbarForm(TimesheetQuery $query)
{
return $this->createForm(TimesheetToolbarForm::class, $query, [
'action' => $this->generateUrl($this->getTimesheetRoute(), [
'page' => $query->getPage(),
]),
'method' => 'GET',
'include_user' => $this->includeUserInForms(),
]);
}
protected function includeSummary(): bool
{
return (bool) $this->getUser()->getPreferenceValue('timesheet.daily_stats', false);
}
protected function includeUserInForms(): bool
{
return false;
}
protected function getTimesheetRoute(): string
{
return 'timesheet';
}
protected function getEditRoute(): string
{
return 'timesheet_edit';
}
protected function getCreateRoute(): string
{
return 'timesheet_create';
}
}

View File

@@ -9,29 +9,19 @@
namespace App\Controller;
use App\Entity\Tag;
use App\Entity\Timesheet;
use App\Form\TimesheetEditForm;
use App\Form\Toolbar\TimesheetToolbarForm;
use App\Repository\ActivityRepository;
use App\Repository\ProjectRepository;
use App\Repository\Query\TimesheetQuery;
use Doctrine\Common\Collections\ArrayCollection;
use Pagerfanta\Pagerfanta;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
/**
* Controller used to manage timesheets.
*
* @Route(path="/timesheet")
* @Security("is_granted('view_own_timesheet')")
*/
class TimesheetController extends AbstractController
class TimesheetController extends TimesheetAbstractController
{
use TimesheetControllerTrait;
/**
* @Route(path="/", defaults={"page": 1}, name="timesheet", methods={"GET"})
* @Route(path="/page/{page}", requirements={"page": "[1-9]\d*"}, name="timesheet_paginated", methods={"GET"})
@@ -43,43 +33,7 @@ class TimesheetController extends AbstractController
*/
public function indexAction($page, Request $request)
{
$query = new TimesheetQuery();
$query->setPage($page);
$form = $this->getToolbarForm($query);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/** @var TimesheetQuery $query */
$query = $form->getData();
if (null !== $query->getBegin()) {
$query->getBegin()->setTime(0, 0, 0);
}
if (null !== $query->getEnd()) {
$query->getEnd()->setTime(23, 59, 59);
}
}
$query->setUser($this->getUser());
if ($query->hasTags()) {
$query->setTags(
new ArrayCollection(
$this->getDoctrine()->getRepository(Tag::class)->findIdsByTagNameList(implode(',', $query->getTags()->toArray()))
)
);
}
/* @var $entries Pagerfanta */
$entries = $this->getRepository()->findByQuery($query);
return $this->render('timesheet/index.html.twig', [
'entries' => $entries,
'page' => $query->getPage(),
'query' => $query,
'showFilter' => $form->isSubmitted(),
'toolbarForm' => $form->createView(),
'showSummary' => $this->getUser()->getPreferenceValue('timesheet.daily_stats', false),
]);
return $this->index($page, $request, 'timesheet/index.html.twig');
}
/**
@@ -91,37 +45,34 @@ class TimesheetController extends AbstractController
*/
public function exportAction(Request $request)
{
$query = new TimesheetQuery();
$query->setResultType(TimesheetQuery::RESULT_TYPE_OBJECTS);
$form = $this->getToolbarForm($query);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/** @var TimesheetQuery $query */
$query = $form->getData();
return $this->export($request, 'timesheet/export.html.twig');
}
// by default the current month is exported, but it can be overwritten
if (null === $query->getBegin()) {
$query->setBegin($this->dateTime->createDateTime('first day of this month'));
/**
* @Route(path="/{id}/edit", name="timesheet_edit", methods={"GET", "POST"})
* @Security("is_granted('edit', entry)")
*
* @param Timesheet $entry
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function editAction(Timesheet $entry, Request $request)
{
return $this->edit($entry, $request, 'timesheet/edit.html.twig');
}
$query->getBegin()->setTime(0, 0, 0);
if (null === $query->getEnd()) {
$query->setEnd($this->dateTime->createDateTime('last day of this month'));
}
$query->getEnd()->setTime(23, 59, 59);
// user timesheet always export for the session user
$query->setUser($this->getUser());
/* @var $entries Pagerfanta */
$entries = $this->getRepository()->findByQuery($query);
return $this->render('timesheet/export.html.twig', [
'entries' => $entries,
'query' => $query,
]);
/**
* @Route(path="/create", name="timesheet_create", methods={"GET", "POST"})
* @Security("is_granted('create_own_timesheet')")
*
* @param Request $request
* @param ProjectRepository $projectRepository
* @param ActivityRepository $activityRepository
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function createAction(Request $request, ProjectRepository $projectRepository, ActivityRepository $activityRepository)
{
return $this->create($request, 'timesheet/edit.html.twig', $projectRepository, $activityRepository);
}
/**
@@ -142,76 +93,4 @@ class TimesheetController extends AbstractController
]
);
}
/**
* @Route(path="/{id}/edit", name="timesheet_edit", methods={"GET", "POST"})
* @Security("is_granted('edit', entry)")
*
* @param Timesheet $entry
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function editAction(Timesheet $entry, Request $request)
{
return $this->edit($entry, $request, 'timesheet', 'timesheet/edit.html.twig');
}
/**
* @Route(path="/create", name="timesheet_create", methods={"GET", "POST"})
* @Security("is_granted('create_own_timesheet')")
*
* @param Request $request
* @param ProjectRepository $projectRepository
* @param ActivityRepository $activityRepository
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function createAction(Request $request, ProjectRepository $projectRepository, ActivityRepository $activityRepository)
{
return $this->create($request, 'timesheet', 'timesheet/edit.html.twig', $projectRepository, $activityRepository);
}
/**
* @param Timesheet $entry
* @return \Symfony\Component\Form\FormInterface
*/
protected function getCreateForm(Timesheet $entry)
{
return $this->createForm(TimesheetEditForm::class, $entry, [
'action' => $this->generateUrl('timesheet_create', []),
'include_rate' => $this->isGranted('edit_rate', $entry),
'customer' => true,
]);
}
/**
* @param Timesheet $entry
* @param int $page
* @return \Symfony\Component\Form\FormInterface
*/
protected function getEditForm(Timesheet $entry, $page)
{
return $this->createForm(TimesheetEditForm::class, $entry, [
'action' => $this->generateUrl('timesheet_edit', [
'id' => $entry->getId(),
'page' => $page,
]),
'include_rate' => $this->isGranted('edit_rate', $entry),
'include_exported' => $this->isGranted('edit_export', $entry),
'customer' => true,
]);
}
/**
* @param TimesheetQuery $query
* @return \Symfony\Component\Form\FormInterface
*/
protected function getToolbarForm(TimesheetQuery $query)
{
return $this->createForm(TimesheetToolbarForm::class, $query, [
'action' => $this->generateUrl('timesheet', [
'page' => $query->getPage(),
]),
'method' => 'GET',
]);
}
}

View File

@@ -9,29 +9,19 @@
namespace App\Controller;
use App\Entity\Tag;
use App\Entity\Timesheet;
use App\Form\TimesheetEditForm;
use App\Form\Toolbar\TimesheetToolbarForm;
use App\Repository\ActivityRepository;
use App\Repository\ProjectRepository;
use App\Repository\Query\TimesheetQuery;
use Doctrine\Common\Collections\ArrayCollection;
use Pagerfanta\Pagerfanta;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
/**
* Controller used for manage timesheet entries in the admin part of the site.
*
* @Route(path="/team/timesheet")
* @Security("is_granted('view_other_timesheet')")
*/
class TimesheetTeamController extends AbstractController
class TimesheetTeamController extends TimesheetAbstractController
{
use TimesheetControllerTrait;
/**
* @Route(path="/", defaults={"page": 1}, name="admin_timesheet", methods={"GET"})
* @Route(path="/page/{page}", requirements={"page": "[1-9]\d*"}, name="admin_timesheet_paginated", methods={"GET"})
@@ -43,40 +33,7 @@ class TimesheetTeamController extends AbstractController
*/
public function indexAction($page, Request $request)
{
$query = new TimesheetQuery();
$query->setPage($page);
$form = $this->getToolbarForm($query);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/** @var TimesheetQuery $query */
$query = $form->getData();
if (null !== $query->getBegin()) {
$query->getBegin()->setTime(0, 0, 0);
}
if (null !== $query->getEnd()) {
$query->getEnd()->setTime(23, 59, 59);
}
}
if ($query->hasTags()) {
$query->setTags(
new ArrayCollection(
$this->getDoctrine()->getRepository(Tag::class)->findIdsByTagNameList(implode(',', $query->getTags()->toArray()))
)
);
}
/* @var $entries Pagerfanta */
$entries = $this->getRepository()->findByQuery($query);
return $this->render('timesheet-team/index.html.twig', [
'entries' => $entries,
'page' => $query->getPage(),
'query' => $query,
'showFilter' => $form->isSubmitted(),
'toolbarForm' => $form->createView(),
]);
return $this->index($page, $request, 'timesheet-team/index.html.twig');
}
/**
@@ -87,34 +44,7 @@ class TimesheetTeamController extends AbstractController
*/
public function exportAction(Request $request)
{
$query = new TimesheetQuery();
$query->setResultType(TimesheetQuery::RESULT_TYPE_OBJECTS);
$form = $this->getToolbarForm($query);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/** @var TimesheetQuery $query */
$query = $form->getData();
}
// by default the current month is exported, but it can be overwritten
if (null === $query->getBegin()) {
$query->setBegin($this->dateTime->createDateTime('first day of this month'));
}
$query->getBegin()->setTime(0, 0, 0);
if (null === $query->getEnd()) {
$query->setEnd($this->dateTime->createDateTime('last day of this month'));
}
$query->getEnd()->setTime(23, 59, 59);
/* @var $entries Pagerfanta */
$entries = $this->getRepository()->findByQuery($query);
return $this->render('timesheet-team/export.html.twig', [
'entries' => $entries,
'query' => $query,
]);
return $this->export($request, 'timesheet-team/export.html.twig');
}
/**
@@ -127,7 +57,7 @@ class TimesheetTeamController extends AbstractController
*/
public function editAction(Timesheet $entry, Request $request)
{
return $this->edit($entry, $request, 'admin_timesheet', 'timesheet-team/edit.html.twig');
return $this->edit($entry, $request, 'timesheet-team/edit.html.twig');
}
/**
@@ -141,54 +71,26 @@ class TimesheetTeamController extends AbstractController
*/
public function createAction(Request $request, ProjectRepository $projectRepository, ActivityRepository $activityRepository)
{
return $this->create($request, 'admin_timesheet', 'timesheet-team/edit.html.twig', $projectRepository, $activityRepository);
return $this->create($request, 'timesheet-team/edit.html.twig', $projectRepository, $activityRepository);
}
/**
* @param Timesheet $entry
* @return \Symfony\Component\Form\FormInterface
*/
protected function getCreateForm(Timesheet $entry)
protected function includeUserInForms(): bool
{
return $this->createForm(TimesheetEditForm::class, $entry, [
'action' => $this->generateUrl('admin_timesheet_create'),
'include_rate' => $this->isGranted('edit_rate', $entry),
'include_user' => true,
'customer' => true,
]);
return true;
}
/**
* @param Timesheet $entry
* @param int $page
* @return \Symfony\Component\Form\FormInterface
*/
protected function getEditForm(Timesheet $entry, $page)
protected function getTimesheetRoute(): string
{
return $this->createForm(TimesheetEditForm::class, $entry, [
'action' => $this->generateUrl('admin_timesheet_edit', [
'id' => $entry->getId(),
'page' => $page,
]),
'include_rate' => $this->isGranted('edit_rate', $entry),
'include_exported' => $this->isGranted('edit_export', $entry),
'include_user' => true,
'customer' => true,
]);
return 'admin_timesheet';
}
/**
* @param TimesheetQuery $query
* @return \Symfony\Component\Form\FormInterface
*/
protected function getToolbarForm(TimesheetQuery $query)
protected function getEditRoute(): string
{
return $this->createForm(TimesheetToolbarForm::class, $query, [
'action' => $this->generateUrl('admin_timesheet', [
'page' => $query->getPage(),
]),
'method' => 'GET',
'include_user' => true,
]);
return 'admin_timesheet_edit';
}
protected function getCreateRoute(): string
{
return 'admin_timesheet_create';
}
}

View File

@@ -361,7 +361,7 @@ class TimesheetEditForm extends AbstractType
'docu_chapter' => 'timesheet.html',
'method' => 'POST',
'date_format' => null,
'customer' => false,
'customer' => false, // for API usage
'attr' => [
'data-form-event' => 'kimai.timesheetUpdate',
'data-msg-success' => 'action.update.success',

View File

@@ -79,28 +79,12 @@
{% if is_granted('create_invoice') %}
<div class="row no-print">
<div class="col-xs-12">
<button type="button" id="print-invoice-button" class="btn btn-success pull-right">
<a href="{{ path('invoice_print') }}" class="btn btn-success pull-right toolbar-action">
<i class="{{ 'print'|icon }}"></i> {{ 'button.print'|trans }}
</button>
</a>
</div>
</div>
{% endif %}
{% endif %}
{% endblock %}
{% block javascripts %}
{{ parent() }}
{% if is_granted('create_invoice') %}
<script type="text/javascript">
document.addEventListener('kimai.initialized', function() {
$("body").on('click', '#print-invoice-button', function() {
var prevAction = $( "#invoice-print-form" ).attr('action');
$( "#invoice-print-form" ).attr('target', '_blank').attr('action', '{{ path('invoice_print') }}');
$( "#invoice-print-form" ).submit();
$( "#invoice-print-form" ).removeAttr('target').attr('action', prevAction);
});
});
</script>
{% endif %}
{% endblock %}

View File

@@ -208,7 +208,7 @@
{% set actions = {'filter': '#collapseTimesheet'} %}
{% if is_granted('export_own_timesheet') %}
{% set actions = actions|merge({'download': {'onclick': 'return exportTimesheet()'}}) %}
{% set actions = actions|merge({'download': {'url': path('timesheet_export'), 'class': 'toolbar-action'}}) %}
{% endif %}
{% set actions = actions|merge({'visibility': '#modal_timesheet'}) %}
{% if is_granted('create_own_timesheet') %}
@@ -264,7 +264,7 @@
{% set actions = {'filter': '#collapseTimesheetAdmin'} %}
{% if is_granted('export_own_timesheet') %}
{% set actions = actions|merge({'download': 'onclick:return exportTimesheet()'}) %}
{% set actions = actions|merge({'download': {'url': path('admin_timesheet_export'), 'class': 'toolbar-action'}}) %}
{% endif %}
{% set actions = actions|merge({'visibility': '#modal_timesheet_admin'}) %}
{% if is_granted('create_other_timesheet') %}

View File

@@ -42,7 +42,7 @@
{% for entry in entries %}
{% set timeWorked = timeWorked + entry.duration %}
<tr>
<td>{{ entry.begin|date_short }}</td>
<td class="text-nowrap">{{ entry.begin|date_short }}</td>
{% if query.user is empty %}
<td>{{ widgets.username(entry.user) }}</td>
{% endif %}
@@ -58,7 +58,7 @@
{{ 'label.customer'|trans }}: {{ entry.project.customer.name }}
</span>
</td>
<td>{{ entry.duration|duration }}</td>
<td class="text-nowrap">{{ entry.duration|duration }}</td>
</tr>
{% endfor %}
</tbody>

View File

@@ -4,13 +4,17 @@
{% import "macros/toolbar.html.twig" as toolbar %}
{% import "macros/actions.html.twig" as actions %}
{% set tableName = 'timesheet_admin' %}
{% set duration_only = is_duration_only() %}
{% set columns = {
'date': 'alwaysVisible',
} %}
{% if not duration_only %}
{% set columns = columns|merge({'starttime': 'hidden-xs', 'endtime': 'hidden-xs'}) %}
{% set columns = columns|merge({
'starttime': 'hidden-xs',
'endtime': 'hidden-xs'
}) %}
{% endif %}
{% set columns = columns|merge({
@@ -25,8 +29,6 @@
'actions': 'actions alwaysVisible',
}) %}
{% set tableName = 'timesheet_admin' %}
{% block page_title %}{{ 'admin_timesheet.title'|trans }}{% endblock %}
{% block page_subtitle %}{{ 'admin_timesheet.subtitle'|trans }}{% endblock %}
{% block page_actions %}{{ actions.timesheets_team('index') }}{% endblock %}
@@ -49,21 +51,23 @@
{% if not duration_only %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, 'starttime') }}">{{ entry.begin|time }}</td>
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, 'endtime') }}">
{% if entry.end %}
{{ entry.end|time }}
{% else %}
&dash;
{% endif %}
</td>
{% endif %}
{% if entry.end %}
{% if not duration_only %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, 'endtime') }}">{{ entry.end|time }}</td>
{% endif %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, 'duration') }}">{{ entry.duration|duration }}</td>
{% else %}
{% if not duration_only %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, 'endtime') }}">&dash;</td>
{% endif %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, 'duration') }}">
<i data-since="{{ entry.begin.format(constant('DATE_ISO8601')) }}" data-format="{{ get_format_duration() }}">{{ entry|duration }}</i>
</td>
{% endif %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, 'rate') }}">
{% if not entry.end or not is_granted('view_rate', entry) %}
&dash;
@@ -86,7 +90,7 @@
<td class="{{ tables.data_table_column_class(tableName, columns, 'description') }}">{{ entry.description|nl2br }}</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'tags') }}">{{ widgets.tag_list(entry.tags) }}</td>
<td class="actions">
{{ actions.timesheet_team(entry, 'index') }}
{{- actions.timesheet_team(entry, 'index') -}}
</td>
</tr>
{% endfor %}
@@ -95,17 +99,3 @@
{% endif %}
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script type="text/javascript">
function exportTimesheet() {
var form = $("div.toolbar form.navbar-form");
var prevAction = form.attr('action');
form.attr('target', '_blank').attr('action', '{{ path('admin_timesheet_export') }}');
form.submit();
form.removeAttr('target').attr('action', prevAction);
return false;
}
</script>
{% endblock %}

View File

@@ -37,7 +37,7 @@
{% for entry in entries %}
{% set timeWorked = timeWorked + entry.duration %}
<tr>
<td>{{ entry.begin|date_short }}</td>
<td class="text-nowrap">{{ entry.begin|date_short }}</td>
<td>
{% if entry.description is not empty %}
<div>
@@ -50,7 +50,7 @@
{{ 'label.customer'|trans }}: {{ entry.project.customer.name }}
</span>
</td>
<td>{{ entry.duration|duration }}</td>
<td class="text-nowrap">{{ entry.duration|duration }}</td>
</tr>
{% endfor %}
</tbody>

View File

@@ -11,6 +11,7 @@
{% set columns = {
'date': 'alwaysVisible',
} %}
{% if not duration_only %}
{% set columns = columns|merge({
'starttime': '',
@@ -40,6 +41,7 @@
{% endblock %}
{% block main %}
{% if entries.count == 0 %}
{{ widgets.callout('warning', 'error.no_entries_found') }}
{% else %}
@@ -64,26 +66,31 @@
{% if not duration_only %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, 'starttime') }}">{{ entry.begin|time }}</td>
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, 'endtime') }}">
{% if entry.end %}
{{ entry.end|time }}
{% else %}
&dash;
{% endif %}
</td>
{% endif %}
{% if entry.end %}
{% if not duration_only %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, 'endtime') }}">{{ entry.end|time }}</td>
{% endif %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, 'duration') }}">{{ entry.duration|duration }}</td>
{% if canSeeRate %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, 'rate') }}">{{ entry.rate|money(entry.project.customer.currency) }}</td>
{% endif %}
{% else %}
{% if not duration_only %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, 'endtime') }}">&dash;</td>
{% endif %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, 'duration') }}">
<i data-since="{{ entry.begin.format(constant('DATE_ISO8601')) }}" data-format="{{ get_format_duration() }}">{{ entry|duration }}</i>
</td>
{% if canSeeRate %}
<td class="{{ tables.data_table_column_class(tableName, columns, 'rate') }}">&dash;</td>
{% endif %}
{% if canSeeRate %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, 'rate') }}">
{% if not entry.end %}
&dash;
{% else %}
{{ entry.rate|money(entry.project.customer.currency) }}
{% endif %}
</td>
{% endif %}
<td class="{{ tables.data_table_column_class(tableName, columns, 'customer') }}">{{ widgets.label_customer(entry.project.customer) }}</td>
@@ -113,20 +120,6 @@
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script type="text/javascript">
function exportTimesheet() {
var form = $("div.toolbar form.navbar-form");
var prevAction = form.attr('action');
form.attr('target', '_blank').attr('action', '{{ path('timesheet_export') }}');
form.submit();
form.removeAttr('target').attr('action', prevAction);
return false;
}
</script>
{% endblock %}
{% macro summary(day, duration, dayRates, columns, canSeeRate, duration_only, tableName) %}
{% import "macros/datatables.html.twig" as tables %}
<tr class="summary info">

View File

@@ -10,9 +10,7 @@
namespace App\Tests\EventSubscriber;
use App\Entity\User;
use App\Event\DashboardEvent;
use App\Event\ThemeEvent;
use App\Model\DashboardSection;
use PHPUnit\Framework\TestCase;
/**