added start and stop entries
enhanced administration of activities/projects/customers added navbar for active records and recent activities added edit timesheet entry form added translation packages for errors and flashmessages upgraded composer packages
This commit is contained in:
54
src/TimesheetBundle/Controller/ActivityController.php
Normal file
54
src/TimesheetBundle/Controller/ActivityController.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai package.
|
||||
*
|
||||
* (c) Kevin Papst <kevin@kevinpapst.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace TimesheetBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use TimesheetBundle\Entity\Activity;
|
||||
use TimesheetBundle\Repository\ActivityRepository;
|
||||
|
||||
/**
|
||||
* Controller used to manage activity contents in the public part of the site.
|
||||
*
|
||||
* @Route("/activity")
|
||||
* @Security("has_role('ROLE_USER')")
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class ActivityController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @return ActivityRepository
|
||||
*/
|
||||
protected function getRepository()
|
||||
{
|
||||
return $this->getDoctrine()->getRepository(Activity::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* The flyout to render recent activities and quick-start new recordings.
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function recentActivitiesAction()
|
||||
{
|
||||
$user = $this->getUser();
|
||||
$activeEntries = $this->getRepository()->getRecentActivities($user, new \DateTime('-30 days')); // TODO make days configurable
|
||||
|
||||
return $this->render(
|
||||
'TimesheetBundle:Navbar:recent-activities.html.twig',
|
||||
['activities' => $activeEntries]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,11 @@
|
||||
|
||||
namespace TimesheetBundle\Controller\Admin;
|
||||
|
||||
use AppBundle\Controller\AbstractController;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use TimesheetBundle\Entity\Activity;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
@@ -30,7 +31,7 @@ use TimesheetBundle\Repository\ActivityRepository;
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class ActivityController extends Controller
|
||||
class ActivityController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route("/", defaults={"page": 1}, name="admin_activity")
|
||||
@@ -50,9 +51,8 @@ class ActivityController extends Controller
|
||||
* @Route("/{id}/edit", name="admin_activity_edit")
|
||||
* @Method({"GET", "POST"})
|
||||
*/
|
||||
public function editAction($id, Request $request)
|
||||
public function editAction(Activity $activity, Request $request)
|
||||
{
|
||||
$activity = $this->getById($id);
|
||||
$editForm = $this->createEditForm($activity);
|
||||
|
||||
$editForm->handleRequest($request);
|
||||
@@ -62,7 +62,7 @@ class ActivityController extends Controller
|
||||
$entityManager->persist($activity);
|
||||
$entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'action.updated_successfully');
|
||||
$this->flashSuccess('action.updated_successfully');
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'admin_activity', ['id' => $activity->getId()]
|
||||
@@ -78,21 +78,6 @@ class ActivityController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return null|Activity
|
||||
*/
|
||||
protected function getById($id)
|
||||
{
|
||||
/* @var $repo ActivityRepository */
|
||||
$repo = $this->getDoctrine()->getRepository(Activity::class);
|
||||
$activity = $repo->getById($id);
|
||||
if (null === $activity) {
|
||||
throw new NotFoundHttpException('Activity "'.$id.'" does not exist');
|
||||
}
|
||||
return $activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Activity $activity
|
||||
* @return \Symfony\Component\Form\Form
|
||||
|
||||
@@ -11,10 +11,11 @@
|
||||
|
||||
namespace TimesheetBundle\Controller\Admin;
|
||||
|
||||
use AppBundle\Controller\AbstractController;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use TimesheetBundle\Entity\Customer;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
@@ -30,7 +31,7 @@ use TimesheetBundle\Repository\CustomerRepository;
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class CustomerController extends Controller
|
||||
class CustomerController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route("/", defaults={"page": 1}, name="admin_customer")
|
||||
@@ -49,50 +50,38 @@ class CustomerController extends Controller
|
||||
/**
|
||||
* @Route("/{id}/edit", name="admin_customer_edit")
|
||||
* @Method({"GET", "POST"})
|
||||
*
|
||||
* @param Customer $customer
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function editAction($id, Request $request)
|
||||
public function editAction(Customer $customer, Request $request)
|
||||
{
|
||||
$entity = $this->getById($id);
|
||||
$editForm = $this->createEditForm($entity);
|
||||
$editForm = $this->createEditForm($customer);
|
||||
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->persist($entity);
|
||||
$entityManager->persist($customer);
|
||||
$entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'action.updated_successfully');
|
||||
$this->flashSuccess('action.updated_successfully');
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'admin_customer', ['id' => $entity->getId()]
|
||||
'admin_customer', ['id' => $customer->getId()]
|
||||
);
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'TimesheetBundle:admin:customer_edit.html.twig',
|
||||
[
|
||||
'customer' => $entity,
|
||||
'customer' => $customer,
|
||||
'form' => $editForm->createView()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return null|Customer
|
||||
*/
|
||||
protected function getById($id)
|
||||
{
|
||||
/* @var $repo CustomerRepository */
|
||||
$repo = $this->getDoctrine()->getRepository(Customer::class);
|
||||
$activity = $repo->getById($id);
|
||||
if (null === $activity) {
|
||||
throw new NotFoundHttpException('Customer "'.$id.'" does not exist');
|
||||
}
|
||||
return $activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Customer $customer
|
||||
* @return \Symfony\Component\Form\Form
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
|
||||
namespace TimesheetBundle\Controller\Admin;
|
||||
|
||||
use AppBundle\Controller\AbstractController;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use TimesheetBundle\Entity\Project;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
@@ -30,7 +30,7 @@ use TimesheetBundle\Repository\ProjectRepository;
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class ProjectController extends Controller
|
||||
class ProjectController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route("/", defaults={"page": 1}, name="admin_project")
|
||||
@@ -53,13 +53,12 @@ class ProjectController extends Controller
|
||||
* @Route("/{id}/edit", name="admin_project_edit")
|
||||
* @Method({"GET", "POST"})
|
||||
*
|
||||
* @param $id
|
||||
* @param Project $project
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function editAction($id, Request $request)
|
||||
public function editAction(Project $project, Request $request)
|
||||
{
|
||||
$project = $this->getById($id);
|
||||
$editForm = $this->createEditForm($project);
|
||||
|
||||
$editForm->handleRequest($request);
|
||||
@@ -69,7 +68,7 @@ class ProjectController extends Controller
|
||||
$entityManager->persist($project);
|
||||
$entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'action.updated_successfully');
|
||||
$this->flashSuccess('action.updated_successfully');
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'admin_project', ['id' => $project->getId()]
|
||||
@@ -85,24 +84,9 @@ class ProjectController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return null|Project
|
||||
*/
|
||||
protected function getById($id)
|
||||
{
|
||||
/* @var $repo ProjectRepository */
|
||||
$repo = $this->getDoctrine()->getRepository(Project::class);
|
||||
$activity = $repo->getById($id);
|
||||
if (null === $activity) {
|
||||
throw new NotFoundHttpException('Project "'.$id.'" does not exist');
|
||||
}
|
||||
return $activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Project $project
|
||||
* @return \Symfony\Component\Form\Form
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
private function createEditForm(Project $project)
|
||||
{
|
||||
@@ -112,7 +96,7 @@ class ProjectController extends Controller
|
||||
[
|
||||
'action' => $this->generateUrl('admin_project_edit', ['id' => $project->getId()]),
|
||||
'method' => 'POST',
|
||||
'currency' => $project->getCurrency()
|
||||
'currency' => $project->getCustomer()->getCurrency()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,12 +11,17 @@
|
||||
|
||||
namespace TimesheetBundle\Controller;
|
||||
|
||||
use AppBundle\Controller\AbstractController;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use TimesheetBundle\Entity\Activity;
|
||||
use TimesheetBundle\Entity\Timesheet;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use TimesheetBundle\Form\TimesheetEditForm;
|
||||
use TimesheetBundle\Repository\TimesheetRepository;
|
||||
|
||||
/**
|
||||
* Controller used to manage timesheet contents in the public part of the site.
|
||||
@@ -26,8 +31,16 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class TimesheetController extends Controller
|
||||
class TimesheetController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @return TimesheetRepository
|
||||
*/
|
||||
protected function getRepository()
|
||||
{
|
||||
return $this->getDoctrine()->getRepository(Timesheet::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/", defaults={"page": 1}, name="timesheet")
|
||||
* @Route("/page/{page}", requirements={"page": "[1-9]\d*"}, name="timesheet_paginated")
|
||||
@@ -38,20 +51,144 @@ class TimesheetController extends Controller
|
||||
{
|
||||
$user = $this->getUser();
|
||||
/* @var $entries Pagerfanta */
|
||||
$entries = $this->getDoctrine()->getRepository(Timesheet::class)->findLatest($user, $page);
|
||||
$entries = $this->getRepository()->findLatest($user, $page);
|
||||
|
||||
return $this->render('TimesheetBundle:timesheet:index.html.twig', ['entries' => $entries]);
|
||||
return $this->render('TimesheetBundle:timesheet:index.html.twig', [
|
||||
'entries' => $entries,
|
||||
'page' => $page
|
||||
]);
|
||||
}
|
||||
|
||||
public function statusEntryAction()
|
||||
/**
|
||||
* The "main button and flyout" for displaying (and stopping) active entries.
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function activeEntriesAction()
|
||||
{
|
||||
$user = $this->getUser();
|
||||
$activeEntry = $this->getDoctrine()->getRepository(Timesheet::class)->getActiveEntry($user);
|
||||
$activeEntries = $this->getRepository()->getActiveEntries($user);
|
||||
|
||||
$activeEntry = null;
|
||||
return $this->render(
|
||||
'TimesheetBundle:Sidebar:navbar-panel.html.twig',
|
||||
['entry' => $activeEntry]
|
||||
'TimesheetBundle:Navbar:active-entries.html.twig',
|
||||
['entries' => $activeEntries]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The route to stop a running entry.
|
||||
*
|
||||
* @Route("/{id}/stop", name="timesheet_stop")
|
||||
* @Method({"GET"})
|
||||
*
|
||||
* @param Timesheet $entry
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function stopAction(Timesheet $entry, Request $request)
|
||||
{
|
||||
$user = $this->getUser();
|
||||
|
||||
// make sure only ADMIN can stop other users entries
|
||||
if ($user->getId() !== $entry->getUser()->getId()) {
|
||||
$this->denyUnlessGranted('ROLE_ADMIN', null, 'timesheet.access.denied', ['%user%' => $user->getId(), '%entry%' => $entry->getId()]);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->getRepository()->stopRecording($entry);
|
||||
$this->flashSuccess('timesheet.stop.success');
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('timesheet.stop.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('timesheet');
|
||||
}
|
||||
|
||||
/**
|
||||
* The route to stop a running entry.
|
||||
*
|
||||
* @Route("/start/{id}", name="timesheet_start", requirements={"id" = "\d+"})
|
||||
* @Method({"GET", "POST"})
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function startAction(Activity $activity, Request $request)
|
||||
{
|
||||
$user = $this->getUser();
|
||||
|
||||
try {
|
||||
$this->getRepository()->startRecording($user, $activity);
|
||||
$this->flashSuccess('timesheet.start.success');
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('timesheet.start.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('timesheet');
|
||||
}
|
||||
|
||||
/**
|
||||
* The route to edit an existing entry or to create a complete new entry.
|
||||
*
|
||||
* @Route("/{id}/edit", name="timesheet_edit")
|
||||
* @Method({"GET", "POST"})
|
||||
*
|
||||
* @param Timesheet $entry
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function editAction(Timesheet $entry, Request $request)
|
||||
{
|
||||
$user = $this->getUser();
|
||||
|
||||
// make sure only ADMIN can edit other users entries
|
||||
if ($user->getId() !== $entry->getUser()->getId()) {
|
||||
$this->denyUnlessGranted('ROLE_ADMIN', null, 'timesheet.access.denied', ['%user%' => $user->getId(), '%entry%' => $entry->getId()]);
|
||||
}
|
||||
|
||||
$editForm = $this->createEditForm($entry, $request->get('page'));
|
||||
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->persist($entry);
|
||||
$entityManager->flush();
|
||||
|
||||
$this->flashSuccess('action.updated_successfully');
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'timesheet_paginated', ['page' => $request->get('page')]
|
||||
);
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'TimesheetBundle:timesheet:edit.html.twig',
|
||||
[
|
||||
'entry' => $entry,
|
||||
'form' => $editForm->createView(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Timesheet $entry
|
||||
* @param string $page
|
||||
* @return \Symfony\Component\Form\Form
|
||||
*/
|
||||
private function createEditForm(Timesheet $entry, $page)
|
||||
{
|
||||
return $this->createForm(
|
||||
TimesheetEditForm::class,
|
||||
$entry,
|
||||
[
|
||||
'action' => $this->generateUrl('timesheet_edit', [
|
||||
'id' => $entry->getId(),
|
||||
'page' => $page
|
||||
]),
|
||||
'method' => 'POST',
|
||||
'currency' => $entry->getActivity()->getProject()->getCustomer()->getCurrency(),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user