support different formats in user timesheet exports (#1222)

This commit is contained in:
Kevin Papst
2019-11-08 16:10:38 +01:00
committed by GitHub
parent 0705c26513
commit fa1c79e15c
75 changed files with 1872 additions and 951 deletions

View File

@@ -17,6 +17,7 @@ use App\Form\UserPasswordType;
use App\Form\UserPreferencesForm;
use App\Form\UserRolesType;
use App\Form\UserTeamsType;
use App\Repository\TeamRepository;
use App\Repository\TimesheetRepository;
use App\Voter\UserVoter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
@@ -38,21 +39,21 @@ class ProfileController extends AbstractController
/**
* @var EventDispatcherInterface
*/
protected $dispatcher;
private $dispatcher;
/**
* @var UserPasswordEncoderInterface
*/
protected $encoder;
private $encoder;
/**
* @param UserPasswordEncoderInterface $encoder
* @param EventDispatcherInterface $dispatcher
* @var TeamRepository
*/
public function __construct(UserPasswordEncoderInterface $encoder, EventDispatcherInterface $dispatcher)
private $teams;
public function __construct(UserPasswordEncoderInterface $encoder, EventDispatcherInterface $dispatcher, TeamRepository $teams)
{
$this->encoder = $encoder;
$this->dispatcher = $dispatcher;
$this->teams = $teams;
}
/**
@@ -283,7 +284,7 @@ class ProfileController extends AbstractController
$apiTokenForm = $apiTokenForm ?: $this->createApiTokenForm($user);
$forms['api-token'] = $apiTokenForm->createView();
}
if ($this->isGranted(UserVoter::TEAMS, $user)) {
if ($this->isGranted(UserVoter::TEAMS, $user) && $this->teams->count([]) > 0) {
$teamsForm = $teamsForm ?: $this->createTeamsForm($user);
$forms['teams'] = $teamsForm->createView();
}

View File

@@ -15,6 +15,7 @@ use App\Entity\Tag;
use App\Entity\Timesheet;
use App\Event\TimesheetMetaDefinitionEvent;
use App\Event\TimesheetMetaDisplayEvent;
use App\Export\ServiceExport;
use App\Form\TimesheetEditForm;
use App\Form\Toolbar\TimesheetToolbarForm;
use App\Repository\ActivityRepository;
@@ -53,19 +54,25 @@ abstract class TimesheetAbstractController extends AbstractController
* @var EventDispatcherInterface
*/
protected $dispatcher;
/**
* @var ServiceExport
*/
protected $exportService;
public function __construct(
UserDateTimeFactory $dateTime,
TimesheetConfiguration $configuration,
TimesheetRepository $repository,
TrackingModeService $service,
EventDispatcherInterface $dispatcher
EventDispatcherInterface $dispatcher,
ServiceExport $exportService
) {
$this->dateTime = $dateTime;
$this->configuration = $configuration;
$this->repository = $repository;
$this->trackingModeService = $service;
$this->dispatcher = $dispatcher;
$this->exportService = $exportService;
}
protected function getTrackingMode(): TrackingModeInterface
@@ -227,7 +234,7 @@ abstract class TimesheetAbstractController extends AbstractController
]);
}
protected function export(Request $request, string $renderTemplate, string $location): Response
protected function export(Request $request, string $exporterId): Response
{
$query = new TimesheetQuery();
@@ -252,11 +259,13 @@ abstract class TimesheetAbstractController extends AbstractController
$entries = $this->getRepository()->getTimesheetsForQuery($query);
return $this->render($renderTemplate, [
'entries' => $entries,
'query' => $query,
'metaColumns' => $this->findMetaColumns($query, $location),
]);
$exporter = $this->exportService->getTimesheetExporterById($exporterId);
if (null === $exporter) {
throw $this->createNotFoundException('Invalid timesheet exporter given');
}
return $exporter->render($entries, $query);
}
protected function prepareQuery(TimesheetQuery $query)

View File

@@ -16,6 +16,7 @@ use App\Repository\ProjectRepository;
use App\Repository\TagRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
@@ -31,7 +32,7 @@ class TimesheetController extends TimesheetAbstractController
*
* @param int $page
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
* @return Response
*/
public function indexAction($page, Request $request)
{
@@ -39,15 +40,16 @@ class TimesheetController extends TimesheetAbstractController
}
/**
* @Route(path="/export", name="timesheet_export", methods={"GET"})
* @Route(path="/export/{exporter}", name="timesheet_export", methods={"GET"})
* @Security("is_granted('export_own_timesheet')")
*
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
* @param string $exporter
* @return Response
*/
public function exportAction(Request $request)
public function exportAction(Request $request, string $exporter)
{
return $this->export($request, 'timesheet/export.html.twig', TimesheetMetaDisplayEvent::TIMESHEET_EXPORT);
return $this->export($request, $exporter);
}
/**
@@ -80,7 +82,7 @@ class TimesheetController extends TimesheetAbstractController
/**
* Used for the initial page rendering.
*
* @return \Symfony\Component\HttpFoundation\Response
* @return Response
*/
public function activeEntriesAction()
{

View File

@@ -18,6 +18,7 @@ use App\Repository\Query\TimesheetQuery;
use App\Repository\TagRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
@@ -33,7 +34,7 @@ class TimesheetTeamController extends TimesheetAbstractController
*
* @param int $page
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
* @return Response
*/
public function indexAction($page, Request $request)
{
@@ -41,14 +42,15 @@ class TimesheetTeamController extends TimesheetAbstractController
}
/**
* @Route(path="/export", name="admin_timesheet_export", methods={"GET"})
* @Route(path="/export/{exporter}", name="admin_timesheet_export", methods={"GET"})
*
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
* @param string $exporter
* @return Response
*/
public function exportAction(Request $request)
public function exportAction(Request $request, string $exporter)
{
return $this->export($request, 'timesheet-team/export.html.twig', TimesheetMetaDisplayEvent::TEAM_TIMESHEET_EXPORT);
return $this->export($request, $exporter);
}
/**