Display meta-fields in datatables (#1116)
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
span.label-color,
|
||||
span.label-meta,
|
||||
span.label-activity,
|
||||
span.label-project,
|
||||
span.label-customer {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -8,7 +8,7 @@
|
||||
"build/app.3295d6f6.js"
|
||||
],
|
||||
"css": [
|
||||
"build/app.af6cd671.css"
|
||||
"build/app.58c329bf.css"
|
||||
]
|
||||
},
|
||||
"chart": {
|
||||
@@ -36,7 +36,7 @@
|
||||
"build/0.2372f97a.js": "sha384-+My37x5S4cen1I4LYgCVg4Qaa+y8vmPzhpDNLPEoEuH5uBtdwYx6ACOxm23nW0UP",
|
||||
"build/1.eec3372c.js": "sha384-7UVWcP6Hefp2k/CrtGSITKXx4dSZqtvpAiU8WX7dClETkzMewrUjoCRtVXQ5j3KI",
|
||||
"build/app.3295d6f6.js": "sha384-hwTdghEQ1R6XmRqdhx3b1TlOjCZ693mjt6aSL9sHJM6AtQr6hAaoOKlChDHlw9Mc",
|
||||
"build/app.af6cd671.css": "sha384-N8TrohuaS6twRAMAhyy+5o3qV69cT6KGgsvKiLmHMCmRIV3zssFoM14+pO92w+JL",
|
||||
"build/app.58c329bf.css": "sha384-I3CvNLDh32q0zo8ah/FB8Y6qQK+ygagaN1ZczISNHX1pW7jcBS76/W7EsrYQmsUX",
|
||||
"build/2.ad3e2792.js": "sha384-1aYWOOt09EZyaAlTHQzsuBKU1b+iDuMEen4m8lrRIm7awHvYkP82CWAowcKZ+XuW",
|
||||
"build/chart.a0ca6955.js": "sha384-I57c9DtU3AOG2kzKqIZkIu0hi1aGYHRZ5QG4LKC9+9slzJnAMttPGXoL2cQG3m6y",
|
||||
"build/calendar.8464f183.js": "sha384-27JQ0m1u6lO4g3EYXKKIaPlGnbHKOzhpA11X/k2QM0ytL+RWmBilcjR7d56vleXn",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"build/0.2372f97a.js": "build/0.2372f97a.js",
|
||||
"build/1.eec3372c.js": "build/1.eec3372c.js",
|
||||
"build/2.ad3e2792.js": "build/2.ad3e2792.js",
|
||||
"build/app.css": "build/app.af6cd671.css",
|
||||
"build/app.css": "build/app.58c329bf.css",
|
||||
"build/app.js": "build/app.3295d6f6.js",
|
||||
"build/calendar.css": "build/calendar.8bb56227.css",
|
||||
"build/calendar.js": "build/calendar.8464f183.js",
|
||||
|
||||
@@ -177,7 +177,7 @@ class ActivityController extends BaseApiController
|
||||
$activity = new Activity();
|
||||
|
||||
$event = new ActivityMetaDefinitionEvent($activity);
|
||||
$this->dispatcher->dispatch($event, ActivityMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$form = $this->createForm(ActivityApiEditForm::class, $activity);
|
||||
|
||||
@@ -242,7 +242,7 @@ class ActivityController extends BaseApiController
|
||||
}
|
||||
|
||||
$event = new ActivityMetaDefinitionEvent($activity);
|
||||
$this->dispatcher->dispatch($event, ActivityMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$form = $this->createForm(ActivityApiEditForm::class, $activity);
|
||||
|
||||
@@ -301,7 +301,7 @@ class ActivityController extends BaseApiController
|
||||
}
|
||||
|
||||
$event = new ActivityMetaDefinitionEvent($activity);
|
||||
$this->dispatcher->dispatch($event, ActivityMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$name = $paramFetcher->get('name');
|
||||
$value = $paramFetcher->get('value');
|
||||
|
||||
@@ -156,7 +156,7 @@ class CustomerController extends BaseApiController
|
||||
$customer = new Customer();
|
||||
|
||||
$event = new CustomerMetaDefinitionEvent($customer);
|
||||
$this->dispatcher->dispatch($event, CustomerMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$form = $this->createForm(CustomerApiEditForm::class, $customer);
|
||||
|
||||
@@ -221,7 +221,7 @@ class CustomerController extends BaseApiController
|
||||
}
|
||||
|
||||
$event = new CustomerMetaDefinitionEvent($customer);
|
||||
$this->dispatcher->dispatch($event, CustomerMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$form = $this->createForm(CustomerApiEditForm::class, $customer);
|
||||
|
||||
@@ -280,7 +280,7 @@ class CustomerController extends BaseApiController
|
||||
}
|
||||
|
||||
$event = new CustomerMetaDefinitionEvent($customer);
|
||||
$this->dispatcher->dispatch($event, CustomerMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$name = $paramFetcher->get('name');
|
||||
$value = $paramFetcher->get('value');
|
||||
|
||||
@@ -162,7 +162,7 @@ class ProjectController extends BaseApiController
|
||||
$project = new Project();
|
||||
|
||||
$event = new ProjectMetaDefinitionEvent($project);
|
||||
$this->dispatcher->dispatch($event, ProjectMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$form = $this->createForm(ProjectApiEditForm::class, $project);
|
||||
|
||||
@@ -227,7 +227,7 @@ class ProjectController extends BaseApiController
|
||||
}
|
||||
|
||||
$event = new ProjectMetaDefinitionEvent($project);
|
||||
$this->dispatcher->dispatch($event, ProjectMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$form = $this->createForm(ProjectApiEditForm::class, $project);
|
||||
|
||||
@@ -286,7 +286,7 @@ class ProjectController extends BaseApiController
|
||||
}
|
||||
|
||||
$event = new ProjectMetaDefinitionEvent($project);
|
||||
$this->dispatcher->dispatch($event, ProjectMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$name = $paramFetcher->get('name');
|
||||
$value = $paramFetcher->get('value');
|
||||
|
||||
@@ -291,7 +291,7 @@ class TimesheetController extends BaseApiController
|
||||
$timesheet->setBegin($this->dateTime->createDateTime());
|
||||
|
||||
$event = new TimesheetMetaDefinitionEvent($timesheet);
|
||||
$this->dispatcher->dispatch($event, TimesheetMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$mode = $this->getTrackingMode();
|
||||
|
||||
@@ -372,7 +372,7 @@ class TimesheetController extends BaseApiController
|
||||
}
|
||||
|
||||
$event = new TimesheetMetaDefinitionEvent($timesheet);
|
||||
$this->dispatcher->dispatch($event, TimesheetMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$mode = $this->getTrackingMode();
|
||||
|
||||
@@ -732,7 +732,7 @@ class TimesheetController extends BaseApiController
|
||||
}
|
||||
|
||||
$event = new TimesheetMetaDefinitionEvent($timesheet);
|
||||
$this->dispatcher->dispatch($event, TimesheetMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$name = $paramFetcher->get('name');
|
||||
$value = $paramFetcher->get('value');
|
||||
|
||||
@@ -11,8 +11,10 @@ namespace App\Controller;
|
||||
|
||||
use App\Configuration\FormConfiguration;
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Entity\Project;
|
||||
use App\Event\ActivityMetaDefinitionEvent;
|
||||
use App\Event\ActivityMetaDisplayEvent;
|
||||
use App\Form\ActivityEditForm;
|
||||
use App\Form\Toolbar\ActivityToolbarForm;
|
||||
use App\Form\Type\ActivityType;
|
||||
@@ -92,9 +94,22 @@ class ActivityController extends AbstractController
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
'toolbarForm' => $form->createView(),
|
||||
'metaColumns' => $this->findMetaColumns($query),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ActivityQuery $query
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
protected function findMetaColumns(ActivityQuery $query): array
|
||||
{
|
||||
$event = new ActivityMetaDisplayEvent($query, ActivityMetaDisplayEvent::ACTIVITY);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
return $event->getFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/create", name="admin_activity_create", methods={"GET", "POST"})
|
||||
* @Route(path="/create/{project}", name="admin_activity_create_with_project", methods={"GET", "POST"})
|
||||
@@ -123,9 +138,13 @@ class ActivityController extends AbstractController
|
||||
*/
|
||||
public function budgetAction(Activity $activity)
|
||||
{
|
||||
$stats = $this->getRepository()->getActivityStatistics($activity);
|
||||
|
||||
// TODO sent event with stats
|
||||
|
||||
return $this->render('activity/budget.html.twig', [
|
||||
'activity' => $activity,
|
||||
'stats' => $this->getRepository()->getActivityStatistics($activity)
|
||||
'stats' => $stats,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -207,7 +226,7 @@ class ActivityController extends AbstractController
|
||||
protected function renderActivityForm(Activity $activity, Request $request)
|
||||
{
|
||||
$event = new ActivityMetaDefinitionEvent($activity);
|
||||
$this->dispatcher->dispatch($event, ActivityMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$editForm = $this->createEditForm($activity);
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
@@ -11,7 +11,9 @@ namespace App\Controller;
|
||||
|
||||
use App\Configuration\FormConfiguration;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Event\CustomerMetaDefinitionEvent;
|
||||
use App\Event\CustomerMetaDisplayEvent;
|
||||
use App\Form\CustomerEditForm;
|
||||
use App\Form\CustomerTeamPermissionForm;
|
||||
use App\Form\Toolbar\CustomerToolbarForm;
|
||||
@@ -49,10 +51,6 @@ class CustomerController extends AbstractController
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* @param CustomerRepository $repository
|
||||
* @param FormConfiguration $configuration
|
||||
*/
|
||||
public function __construct(CustomerRepository $repository, FormConfiguration $configuration, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
@@ -93,9 +91,22 @@ class CustomerController extends AbstractController
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
'toolbarForm' => $form->createView(),
|
||||
'metaColumns' => $this->findMetaColumns($query),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CustomerQuery $query
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
protected function findMetaColumns(CustomerQuery $query): array
|
||||
{
|
||||
$event = new CustomerMetaDisplayEvent($query, CustomerMetaDisplayEvent::CUSTOMER);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
return $event->getFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/create", name="admin_customer_create", methods={"GET", "POST"})
|
||||
* @Security("is_granted('create_customer')")
|
||||
@@ -151,9 +162,13 @@ class CustomerController extends AbstractController
|
||||
*/
|
||||
public function budgetAction(Customer $customer)
|
||||
{
|
||||
$stats = $this->getRepository()->getCustomerStatistics($customer);
|
||||
|
||||
// TODO sent event with stats
|
||||
|
||||
return $this->render('customer/budget.html.twig', [
|
||||
'customer' => $customer,
|
||||
'stats' => $this->getRepository()->getCustomerStatistics($customer)
|
||||
'stats' => $stats,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -224,7 +239,7 @@ class CustomerController extends AbstractController
|
||||
protected function renderCustomerForm(Customer $customer, Request $request)
|
||||
{
|
||||
$event = new CustomerMetaDefinitionEvent($customer);
|
||||
$this->dispatcher->dispatch($event, CustomerMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$editForm = $this->createEditForm($customer);
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ class ExportController extends AbstractController
|
||||
$query->getBegin()->setTime(0, 0, 0);
|
||||
$query->getEnd()->setTime(23, 59, 59);
|
||||
|
||||
return $this->timesheetRepository->getTimesheetsForQuery($query);
|
||||
return $this->timesheetRepository->getTimesheetsForQuery($query, true);
|
||||
}
|
||||
|
||||
protected function getToolbarForm(ExportQuery $query, string $method): FormInterface
|
||||
|
||||
@@ -11,8 +11,10 @@ namespace App\Controller;
|
||||
|
||||
use App\Configuration\FormConfiguration;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Entity\Project;
|
||||
use App\Event\ProjectMetaDefinitionEvent;
|
||||
use App\Event\ProjectMetaDisplayEvent;
|
||||
use App\Form\ProjectEditForm;
|
||||
use App\Form\ProjectTeamPermissionForm;
|
||||
use App\Form\Toolbar\ProjectToolbarForm;
|
||||
@@ -89,9 +91,22 @@ class ProjectController extends AbstractController
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
'toolbarForm' => $form->createView(),
|
||||
'metaColumns' => $this->findMetaColumns($query),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ProjectQuery $query
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
protected function findMetaColumns(ProjectQuery $query): array
|
||||
{
|
||||
$event = new ProjectMetaDisplayEvent($query, ProjectMetaDisplayEvent::PROJECT);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
return $event->getFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/permissions", name="admin_project_permissions", methods={"GET", "POST"})
|
||||
* @Security("is_granted('permissions', project)")
|
||||
@@ -144,9 +159,13 @@ class ProjectController extends AbstractController
|
||||
*/
|
||||
public function budgetAction(Project $project)
|
||||
{
|
||||
$stats = $this->getRepository()->getProjectStatistics($project);
|
||||
|
||||
// TODO sent event with stats
|
||||
|
||||
return $this->render('project/budget.html.twig', [
|
||||
'project' => $project,
|
||||
'stats' => $this->getRepository()->getProjectStatistics($project)
|
||||
'stats' => $stats
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -218,7 +237,7 @@ class ProjectController extends AbstractController
|
||||
protected function renderProjectForm(Project $project, Request $request)
|
||||
{
|
||||
$event = new ProjectMetaDefinitionEvent($project);
|
||||
$this->dispatcher->dispatch($event, ProjectMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$editForm = $this->createEditForm($project);
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Configuration\TimesheetConfiguration;
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Entity\Tag;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Event\TimesheetMetaDefinitionEvent;
|
||||
use App\Event\TimesheetMetaDisplayEvent;
|
||||
use App\Form\TimesheetEditForm;
|
||||
use App\Form\Toolbar\TimesheetToolbarForm;
|
||||
use App\Repository\ActivityRepository;
|
||||
@@ -81,7 +83,7 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
return $this->repository;
|
||||
}
|
||||
|
||||
protected function index($page, Request $request, string $renderTemplate)
|
||||
protected function index($page, Request $request, string $renderTemplate, string $location): Response
|
||||
{
|
||||
$query = new TimesheetQuery();
|
||||
$query->setPage($page);
|
||||
@@ -122,20 +124,28 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
'query' => $query,
|
||||
'toolbarForm' => $form->createView(),
|
||||
'showSummary' => $this->includeSummary(),
|
||||
'showStartEndTime' => $this->canSeeStartEndTime()
|
||||
'showStartEndTime' => $this->canSeeStartEndTime(),
|
||||
'metaColumns' => $this->findMetaColumns($query, $location),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Timesheet $entry
|
||||
* @param Request $request
|
||||
* @param string $renderTemplate
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
* @param TimesheetQuery $query
|
||||
* @param string $location
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
protected function edit(Timesheet $entry, Request $request, string $renderTemplate)
|
||||
protected function findMetaColumns(TimesheetQuery $query, string $location): array
|
||||
{
|
||||
$event = new TimesheetMetaDisplayEvent($query, $location);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
return $event->getFields();
|
||||
}
|
||||
|
||||
protected function edit(Timesheet $entry, Request $request, string $renderTemplate): Response
|
||||
{
|
||||
$event = new TimesheetMetaDefinitionEvent($entry);
|
||||
$this->dispatcher->dispatch($event, TimesheetMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$editForm = $this->getEditForm($entry, $request->get('page'));
|
||||
$editForm->handleRequest($request);
|
||||
@@ -157,14 +167,7 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param string $renderTemplate
|
||||
* @param ProjectRepository $projectRepository
|
||||
* @param ActivityRepository $activityRepository
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
protected function create(Request $request, string $renderTemplate, ProjectRepository $projectRepository, ActivityRepository $activityRepository, TagRepository $tagRepository)
|
||||
protected function create(Request $request, string $renderTemplate, ProjectRepository $projectRepository, ActivityRepository $activityRepository, TagRepository $tagRepository): Response
|
||||
{
|
||||
$entry = new Timesheet();
|
||||
$entry->setUser($this->getUser());
|
||||
@@ -183,7 +186,7 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
if ($request->query->get('tags')) {
|
||||
$tagNames = explode(',', $request->query->get('tags'));
|
||||
foreach ($tagNames as $tagName) {
|
||||
$tag = $tagRepository->findOneByName($tagName);
|
||||
$tag = $tagRepository->findTagByName($tagName);
|
||||
if (!$tag) {
|
||||
$tag = new Tag();
|
||||
$tag->setName($tagName);
|
||||
@@ -193,7 +196,7 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
}
|
||||
|
||||
$event = new TimesheetMetaDefinitionEvent($entry);
|
||||
$this->dispatcher->dispatch($event, TimesheetMetaDefinitionEvent::class);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$mode = $this->getTrackingMode();
|
||||
$mode->create($entry, $request);
|
||||
@@ -224,12 +227,7 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param string $renderTemplate
|
||||
* @return Response
|
||||
*/
|
||||
protected function export(Request $request, string $renderTemplate)
|
||||
protected function export(Request $request, string $renderTemplate, string $location): Response
|
||||
{
|
||||
$query = new TimesheetQuery();
|
||||
|
||||
@@ -257,6 +255,7 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
return $this->render($renderTemplate, [
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
'metaColumns' => $this->findMetaColumns($query, $location),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Event\TimesheetMetaDisplayEvent;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Repository\TagRepository;
|
||||
@@ -34,7 +35,7 @@ class TimesheetController extends TimesheetAbstractController
|
||||
*/
|
||||
public function indexAction($page, Request $request)
|
||||
{
|
||||
return $this->index($page, $request, 'timesheet/index.html.twig');
|
||||
return $this->index($page, $request, 'timesheet/index.html.twig', TimesheetMetaDisplayEvent::TIMESHEET);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,7 +47,7 @@ class TimesheetController extends TimesheetAbstractController
|
||||
*/
|
||||
public function exportAction(Request $request)
|
||||
{
|
||||
return $this->export($request, 'timesheet/export.html.twig');
|
||||
return $this->export($request, 'timesheet/export.html.twig', TimesheetMetaDisplayEvent::TIMESHEET_EXPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Event\TimesheetMetaDisplayEvent;
|
||||
use App\Form\TimesheetAdminEditForm;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
@@ -36,7 +37,7 @@ class TimesheetTeamController extends TimesheetAbstractController
|
||||
*/
|
||||
public function indexAction($page, Request $request)
|
||||
{
|
||||
return $this->index($page, $request, 'timesheet-team/index.html.twig');
|
||||
return $this->index($page, $request, 'timesheet-team/index.html.twig', TimesheetMetaDisplayEvent::TEAM_TIMESHEET);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,7 +48,7 @@ class TimesheetTeamController extends TimesheetAbstractController
|
||||
*/
|
||||
public function exportAction(Request $request)
|
||||
{
|
||||
return $this->export($request, 'timesheet-team/export.html.twig');
|
||||
return $this->export($request, 'timesheet-team/export.html.twig', TimesheetMetaDisplayEvent::TEAM_TIMESHEET_EXPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Event\UserPreferenceDisplayEvent;
|
||||
use App\Form\Toolbar\UserToolbarForm;
|
||||
use App\Form\UserCreateType;
|
||||
use App\Repository\Query\UserQuery;
|
||||
@@ -18,6 +19,7 @@ use App\Repository\UserRepository;
|
||||
use App\Security\RolePermissionManager;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||
@@ -38,11 +40,16 @@ class UserController extends AbstractController
|
||||
* @var UserRepository
|
||||
*/
|
||||
protected $repository;
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
public function __construct(UserPasswordEncoderInterface $encoder, UserRepository $repository)
|
||||
public function __construct(UserPasswordEncoderInterface $encoder, UserRepository $repository, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$this->encoder = $encoder;
|
||||
$this->repository = $repository;
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,10 +85,14 @@ class UserController extends AbstractController
|
||||
/* @var $entries Pagerfanta */
|
||||
$entries = $this->getRepository()->findByQuery($query);
|
||||
|
||||
$event = new UserPreferenceDisplayEvent(UserPreferenceDisplayEvent::USERS);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
return $this->render('user/index.html.twig', [
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
'toolbarForm' => $form->createView(),
|
||||
'preferences' => $event->getPreferences(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ class Activity implements EntityWithMetaFields
|
||||
public function getMetaField(string $name): ?MetaTableTypeInterface
|
||||
{
|
||||
foreach ($this->meta as $field) {
|
||||
if ($field->getName() === $name) {
|
||||
if (strtolower($field->getName()) === strtolower($name)) {
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,7 +411,7 @@ class Customer implements EntityWithMetaFields
|
||||
public function getMetaField(string $name): ?MetaTableTypeInterface
|
||||
{
|
||||
foreach ($this->meta as $field) {
|
||||
if ($field->getName() === $name) {
|
||||
if (strtolower($field->getName()) === strtolower($name)) {
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,4 +148,19 @@ interface MetaTableTypeInterface
|
||||
* @return MetaTableTypeInterface
|
||||
*/
|
||||
public function setLabel(string $label): MetaTableTypeInterface;
|
||||
|
||||
/**
|
||||
* Set an array of options for the FormType.
|
||||
*
|
||||
* @param array $options
|
||||
* @return MetaTableTypeInterface
|
||||
*/
|
||||
public function setOptions(array $options): MetaTableTypeInterface;
|
||||
|
||||
/**
|
||||
* Returns an array with options for the FormType.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions(): array;
|
||||
}
|
||||
|
||||
@@ -70,6 +70,12 @@ trait MetaTableTypeTrait
|
||||
*/
|
||||
private $constraints = [];
|
||||
|
||||
/**
|
||||
* An array of options for the form element
|
||||
* @var array
|
||||
*/
|
||||
private $options = [];
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
if (null === $this->name) {
|
||||
@@ -183,7 +189,10 @@ trait MetaTableTypeTrait
|
||||
->setType($meta->getType())
|
||||
->setConstraints($meta->getConstraints())
|
||||
->setIsRequired($meta->isRequired())
|
||||
->setIsVisible($meta->isVisible());
|
||||
->setIsVisible($meta->isVisible())
|
||||
->setLabel($meta->getLabel())
|
||||
->setOptions($meta->getOptions())
|
||||
;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -203,4 +212,16 @@ trait MetaTableTypeTrait
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setOptions(array $options): MetaTableTypeInterface
|
||||
{
|
||||
$this->options = $options;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOptions(): array
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ class Project implements EntityWithMetaFields
|
||||
public function getMetaField(string $name): ?MetaTableTypeInterface
|
||||
{
|
||||
foreach ($this->meta as $field) {
|
||||
if ($field->getName() === $name) {
|
||||
if (strtolower($field->getName()) === strtolower($name)) {
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -463,7 +463,7 @@ class Timesheet implements EntityWithMetaFields, InvoiceItemInterface
|
||||
public function getMetaField(string $name): ?MetaTableTypeInterface
|
||||
{
|
||||
foreach ($this->meta as $field) {
|
||||
if ($field->getName() === $name) {
|
||||
if (strtolower($field->getName()) === strtolower($name)) {
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Form\Type\YesNoType;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
@@ -96,18 +97,11 @@ class UserPreference
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getUser(): User
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @return UserPreference
|
||||
*/
|
||||
public function setUser(User $user): UserPreference
|
||||
{
|
||||
$this->user = $user;
|
||||
@@ -115,18 +109,11 @@ class UserPreference
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return UserPreference
|
||||
*/
|
||||
public function setName(string $name): UserPreference
|
||||
{
|
||||
$this->name = $name;
|
||||
@@ -140,6 +127,7 @@ class UserPreference
|
||||
public function getValue()
|
||||
{
|
||||
switch ($this->type) {
|
||||
case YesNoType::class:
|
||||
case CheckboxType::class:
|
||||
return (bool) $this->value;
|
||||
case IntegerType::class:
|
||||
@@ -169,34 +157,24 @@ class UserPreference
|
||||
* @param string $type
|
||||
* @return UserPreference
|
||||
*/
|
||||
public function setType(string $type)
|
||||
public function setType(string $type): UserPreference
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
public function getType(): ?string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $enabled
|
||||
* @return UserPreference
|
||||
*/
|
||||
public function setEnabled(bool $enabled)
|
||||
public function setEnabled(bool $enabled): UserPreference
|
||||
{
|
||||
$this->enabled = $enabled;
|
||||
|
||||
@@ -259,4 +237,13 @@ class UserPreference
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
public function getLabel(): ?string
|
||||
{
|
||||
if (isset($this->options['label'])) {
|
||||
return $this->options['label'];
|
||||
}
|
||||
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ final class ActivityMetaDefinitionEvent extends Event
|
||||
/**
|
||||
* @var Activity
|
||||
*/
|
||||
protected $entity;
|
||||
private $entity;
|
||||
|
||||
public function __construct(Activity $entity)
|
||||
{
|
||||
|
||||
76
src/Event/ActivityMetaDisplayEvent.php
Normal file
76
src/Event/ActivityMetaDisplayEvent.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace App\Event;
|
||||
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Repository\Query\ActivityQuery;
|
||||
use App\Repository\Query\BaseQuery;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Dynamically find possible meta fields for a activity query.
|
||||
*/
|
||||
final class ActivityMetaDisplayEvent extends Event implements MetaDisplayEventInterface
|
||||
{
|
||||
public const EXPORT = 'export';
|
||||
public const ACTIVITY = 'activity';
|
||||
|
||||
/**
|
||||
* @var ActivityQuery
|
||||
*/
|
||||
private $query;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $location;
|
||||
/**
|
||||
* @var MetaTableTypeInterface[]
|
||||
*/
|
||||
private $fields = [];
|
||||
|
||||
public function __construct(ActivityQuery $query, string $location)
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->location = $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, use the query settings.
|
||||
*
|
||||
* @return ActivityQuery
|
||||
*/
|
||||
public function getQuery(): BaseQuery
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, check the current location.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocation(): string
|
||||
{
|
||||
return $this->location;
|
||||
}
|
||||
|
||||
public function addField(MetaTableTypeInterface $meta)
|
||||
{
|
||||
$this->fields[] = $meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
public function getFields(): array
|
||||
{
|
||||
return $this->fields;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ final class CustomerMetaDefinitionEvent extends Event
|
||||
/**
|
||||
* @var Customer
|
||||
*/
|
||||
protected $entity;
|
||||
private $entity;
|
||||
|
||||
public function __construct(Customer $entity)
|
||||
{
|
||||
|
||||
76
src/Event/CustomerMetaDisplayEvent.php
Normal file
76
src/Event/CustomerMetaDisplayEvent.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace App\Event;
|
||||
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Repository\Query\BaseQuery;
|
||||
use App\Repository\Query\CustomerQuery;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Dynamically find possible meta fields for a customer query.
|
||||
*/
|
||||
final class CustomerMetaDisplayEvent extends Event implements MetaDisplayEventInterface
|
||||
{
|
||||
public const EXPORT = 'export';
|
||||
public const CUSTOMER = 'customer';
|
||||
|
||||
/**
|
||||
* @var CustomerQuery
|
||||
*/
|
||||
private $query;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $location;
|
||||
/**
|
||||
* @var MetaTableTypeInterface[]
|
||||
*/
|
||||
private $fields = [];
|
||||
|
||||
public function __construct(CustomerQuery $query, string $location)
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->location = $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, use the query settings.
|
||||
*
|
||||
* @return CustomerQuery
|
||||
*/
|
||||
public function getQuery(): BaseQuery
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, check the current location.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocation(): string
|
||||
{
|
||||
return $this->location;
|
||||
}
|
||||
|
||||
public function addField(MetaTableTypeInterface $meta)
|
||||
{
|
||||
$this->fields[] = $meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
public function getFields(): array
|
||||
{
|
||||
return $this->fields;
|
||||
}
|
||||
}
|
||||
42
src/Event/MetaDisplayEventInterface.php
Normal file
42
src/Event/MetaDisplayEventInterface.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace App\Event;
|
||||
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Repository\Query\BaseQuery;
|
||||
|
||||
interface MetaDisplayEventInterface
|
||||
{
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, use the query settings.
|
||||
*
|
||||
* @return BaseQuery
|
||||
*/
|
||||
public function getQuery(): BaseQuery;
|
||||
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, check the current location.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocation(): string;
|
||||
|
||||
/**
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
public function getFields(): array;
|
||||
|
||||
/**
|
||||
* Adds a field that should be displayed.
|
||||
*
|
||||
* @param MetaTableTypeInterface $meta
|
||||
*/
|
||||
public function addField(MetaTableTypeInterface $meta);
|
||||
}
|
||||
@@ -20,7 +20,7 @@ final class ProjectMetaDefinitionEvent extends Event
|
||||
/**
|
||||
* @var Project
|
||||
*/
|
||||
protected $entity;
|
||||
private $entity;
|
||||
|
||||
public function __construct(Project $entity)
|
||||
{
|
||||
|
||||
76
src/Event/ProjectMetaDisplayEvent.php
Normal file
76
src/Event/ProjectMetaDisplayEvent.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace App\Event;
|
||||
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Repository\Query\BaseQuery;
|
||||
use App\Repository\Query\ProjectQuery;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Dynamically find possible meta fields for a project query.
|
||||
*/
|
||||
final class ProjectMetaDisplayEvent extends Event implements MetaDisplayEventInterface
|
||||
{
|
||||
public const EXPORT = 'export';
|
||||
public const PROJECT = 'project';
|
||||
|
||||
/**
|
||||
* @var ProjectQuery
|
||||
*/
|
||||
private $query;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $location;
|
||||
/**
|
||||
* @var MetaTableTypeInterface[]
|
||||
*/
|
||||
private $fields = [];
|
||||
|
||||
public function __construct(ProjectQuery $query, string $location)
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->location = $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, use the query settings.
|
||||
*
|
||||
* @return ProjectQuery
|
||||
*/
|
||||
public function getQuery(): BaseQuery
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, check the current location.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocation(): string
|
||||
{
|
||||
return $this->location;
|
||||
}
|
||||
|
||||
public function addField(MetaTableTypeInterface $meta)
|
||||
{
|
||||
$this->fields[] = $meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
public function getFields(): array
|
||||
{
|
||||
return $this->fields;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ final class TimesheetMetaDefinitionEvent extends Event
|
||||
/**
|
||||
* @var Timesheet
|
||||
*/
|
||||
protected $entity;
|
||||
private $entity;
|
||||
|
||||
public function __construct(Timesheet $entity)
|
||||
{
|
||||
|
||||
79
src/Event/TimesheetMetaDisplayEvent.php
Normal file
79
src/Event/TimesheetMetaDisplayEvent.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace App\Event;
|
||||
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Repository\Query\BaseQuery;
|
||||
use App\Repository\Query\TimesheetQuery;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Dynamically find possible meta fields for a timesheet query.
|
||||
*/
|
||||
final class TimesheetMetaDisplayEvent extends Event implements MetaDisplayEventInterface
|
||||
{
|
||||
public const EXPORT = 'export';
|
||||
public const TIMESHEET = 'timesheet';
|
||||
public const TEAM_TIMESHEET = 'team-timesheet';
|
||||
public const TIMESHEET_EXPORT = 'timesheet-export';
|
||||
public const TEAM_TIMESHEET_EXPORT = 'team-timesheet-export';
|
||||
|
||||
/**
|
||||
* @var TimesheetQuery
|
||||
*/
|
||||
private $query;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $location;
|
||||
/**
|
||||
* @var MetaTableTypeInterface[]
|
||||
*/
|
||||
private $fields = [];
|
||||
|
||||
public function __construct(TimesheetQuery $query, string $location)
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->location = $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, use the query settings.
|
||||
*
|
||||
* @return TimesheetQuery
|
||||
*/
|
||||
public function getQuery(): BaseQuery
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to filter where your meta-field will be displayed, check the current location.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocation(): string
|
||||
{
|
||||
return $this->location;
|
||||
}
|
||||
|
||||
public function addField(MetaTableTypeInterface $meta)
|
||||
{
|
||||
$this->fields[] = $meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
public function getFields(): array
|
||||
{
|
||||
return $this->fields;
|
||||
}
|
||||
}
|
||||
59
src/Event/UserPreferenceDisplayEvent.php
Normal file
59
src/Event/UserPreferenceDisplayEvent.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace App\Event;
|
||||
|
||||
use App\Entity\UserPreference;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Dynamically find possible user preferences to display.
|
||||
*/
|
||||
final class UserPreferenceDisplayEvent extends Event
|
||||
{
|
||||
public const EXPORT = 'export';
|
||||
public const USERS = 'users';
|
||||
|
||||
/**
|
||||
* @var UserPreference[]
|
||||
*/
|
||||
protected $preferences = [];
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $location;
|
||||
|
||||
public function __construct(string $location)
|
||||
{
|
||||
$this->location = $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UserPreference[]
|
||||
*/
|
||||
public function getPreferences(): array
|
||||
{
|
||||
return $this->preferences;
|
||||
}
|
||||
|
||||
public function addPreference(UserPreference $preference)
|
||||
{
|
||||
$this->preferences[] = $preference;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to filter where the preference will be displayed, check the current location.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocation(): string
|
||||
{
|
||||
return $this->location;
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ final class UserPreferenceEvent extends Event
|
||||
public function addUserPreference(UserPreference $preference)
|
||||
{
|
||||
foreach ($this->preferences as $pref) {
|
||||
if ($pref->getName() == $preference->getName()) {
|
||||
if (strtolower($pref->getName()) === strtolower($preference->getName())) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Cannot add preference, one with the name "' . $preference->getName() . '" is already existing'
|
||||
);
|
||||
|
||||
@@ -9,7 +9,14 @@
|
||||
|
||||
namespace App\Export\Renderer;
|
||||
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Event\ActivityMetaDisplayEvent;
|
||||
use App\Event\CustomerMetaDisplayEvent;
|
||||
use App\Event\MetaDisplayEventInterface;
|
||||
use App\Event\ProjectMetaDisplayEvent;
|
||||
use App\Event\TimesheetMetaDisplayEvent;
|
||||
use App\Event\UserPreferenceDisplayEvent;
|
||||
use App\Repository\Query\TimesheetQuery;
|
||||
use App\Twig\DateExtensions;
|
||||
use DateTime;
|
||||
@@ -18,6 +25,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
@@ -40,11 +48,16 @@ abstract class AbstractSpreadsheetRenderer
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
public function __construct(TranslatorInterface $translator, DateExtensions $dateExtension)
|
||||
public function __construct(TranslatorInterface $translator, DateExtensions $dateExtension, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
$this->dateExtension = $dateExtension;
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
protected function setFormattedDateTime(Worksheet $sheet, $column, $row, ?DateTime $date)
|
||||
@@ -109,6 +122,17 @@ abstract class AbstractSpreadsheetRenderer
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MetaDisplayEventInterface $event
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
protected function findMetaColumns(MetaDisplayEventInterface $event): array
|
||||
{
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
return $event->getFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Timesheet[] $timesheets
|
||||
* @param TimesheetQuery $query
|
||||
@@ -117,14 +141,14 @@ abstract class AbstractSpreadsheetRenderer
|
||||
*/
|
||||
protected function fromArrayToSpreadsheet(array $timesheets, TimesheetQuery $query): Spreadsheet
|
||||
{
|
||||
$publicMetaFields = [];
|
||||
foreach ($timesheets as $timesheet) {
|
||||
foreach ($timesheet->getVisibleMetaFields() as $metaField) {
|
||||
$publicMetaFields[] = $metaField->getName();
|
||||
}
|
||||
}
|
||||
$timesheetMetaFields = $this->findMetaColumns(new TimesheetMetaDisplayEvent($query, TimesheetMetaDisplayEvent::EXPORT));
|
||||
$customerMetaFields = $this->findMetaColumns(new CustomerMetaDisplayEvent($query, CustomerMetaDisplayEvent::EXPORT));
|
||||
$projectMetaFields = $this->findMetaColumns(new ProjectMetaDisplayEvent($query, ProjectMetaDisplayEvent::EXPORT));
|
||||
$activityMetaFields = $this->findMetaColumns(new ActivityMetaDisplayEvent($query, ActivityMetaDisplayEvent::EXPORT));
|
||||
|
||||
$publicMetaFields = array_unique($publicMetaFields);
|
||||
$event = new UserPreferenceDisplayEvent(UserPreferenceDisplayEvent::EXPORT);
|
||||
$this->dispatcher->dispatch($event);
|
||||
$userPreferences = $event->getPreferences();
|
||||
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
@@ -146,8 +170,20 @@ abstract class AbstractSpreadsheetRenderer
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans('label.tags'));
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans('label.hourlyRate'));
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans('label.fixedRate'));
|
||||
foreach ($publicMetaFields as $metaFieldName) {
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans($metaFieldName));
|
||||
foreach ($timesheetMetaFields as $metaField) {
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans($metaField->getLabel()));
|
||||
}
|
||||
foreach ($customerMetaFields as $metaField) {
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans($metaField->getLabel()));
|
||||
}
|
||||
foreach ($projectMetaFields as $metaField) {
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans($metaField->getLabel()));
|
||||
}
|
||||
foreach ($activityMetaFields as $metaField) {
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans($metaField->getLabel()));
|
||||
}
|
||||
foreach ($userPreferences as $preference) {
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans($preference->getLabel()));
|
||||
}
|
||||
|
||||
$entryHeaderRow = $recordsHeaderRow + 1;
|
||||
@@ -205,10 +241,42 @@ abstract class AbstractSpreadsheetRenderer
|
||||
$this->setRate($sheet, $entryHeaderColumn, $entryHeaderRow, $timesheet->getFixedRate(), $customerCurrency);
|
||||
$entryHeaderColumn++;
|
||||
|
||||
foreach ($publicMetaFields as $metaFieldName) {
|
||||
$metaField = $timesheet->getMetaField($metaFieldName);
|
||||
foreach ($timesheetMetaFields as $metaField) {
|
||||
$metaField = $timesheet->getMetaField($metaField->getName());
|
||||
$metaFieldValue = '';
|
||||
if (null !== $metaField && $metaField->isVisible()) {
|
||||
if (null !== $metaField) {
|
||||
$metaFieldValue = $metaField->getValue();
|
||||
}
|
||||
$sheet->setCellValueByColumnAndRow($entryHeaderColumn++, $entryHeaderRow, $metaFieldValue);
|
||||
}
|
||||
foreach ($customerMetaFields as $metaField) {
|
||||
$metaField = $timesheet->getProject()->getCustomer()->getMetaField($metaField->getName());
|
||||
$metaFieldValue = '';
|
||||
if (null !== $metaField) {
|
||||
$metaFieldValue = $metaField->getValue();
|
||||
}
|
||||
$sheet->setCellValueByColumnAndRow($entryHeaderColumn++, $entryHeaderRow, $metaFieldValue);
|
||||
}
|
||||
foreach ($projectMetaFields as $metaField) {
|
||||
$metaField = $timesheet->getProject()->getMetaField($metaField->getName());
|
||||
$metaFieldValue = '';
|
||||
if (null !== $metaField) {
|
||||
$metaFieldValue = $metaField->getValue();
|
||||
}
|
||||
$sheet->setCellValueByColumnAndRow($entryHeaderColumn++, $entryHeaderRow, $metaFieldValue);
|
||||
}
|
||||
foreach ($activityMetaFields as $metaField) {
|
||||
$metaField = $timesheet->getActivity()->getMetaField($metaField->getName());
|
||||
$metaFieldValue = '';
|
||||
if (null !== $metaField) {
|
||||
$metaFieldValue = $metaField->getValue();
|
||||
}
|
||||
$sheet->setCellValueByColumnAndRow($entryHeaderColumn++, $entryHeaderRow, $metaFieldValue);
|
||||
}
|
||||
foreach ($userPreferences as $preference) {
|
||||
$metaField = $timesheet->getUser()->getPreference($preference->getName());
|
||||
$metaFieldValue = '';
|
||||
if (null !== $metaField) {
|
||||
$metaFieldValue = $metaField->getValue();
|
||||
}
|
||||
$sheet->setCellValueByColumnAndRow($entryHeaderColumn++, $entryHeaderRow, $metaFieldValue);
|
||||
|
||||
@@ -9,9 +9,17 @@
|
||||
|
||||
namespace App\Export\Renderer;
|
||||
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Event\ActivityMetaDisplayEvent;
|
||||
use App\Event\CustomerMetaDisplayEvent;
|
||||
use App\Event\MetaDisplayEventInterface;
|
||||
use App\Event\ProjectMetaDisplayEvent;
|
||||
use App\Event\TimesheetMetaDisplayEvent;
|
||||
use App\Event\UserPreferenceDisplayEvent;
|
||||
use App\Export\RendererInterface;
|
||||
use App\Repository\Query\TimesheetQuery;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Twig\Environment;
|
||||
|
||||
@@ -23,10 +31,26 @@ final class HtmlRenderer implements RendererInterface
|
||||
* @var Environment
|
||||
*/
|
||||
protected $twig;
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
public function __construct(Environment $twig)
|
||||
public function __construct(Environment $twig, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$this->twig = $twig;
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MetaDisplayEventInterface $event
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
protected function findMetaColumns(MetaDisplayEventInterface $event): array
|
||||
{
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
return $event->getFields();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,18 +63,24 @@ final class HtmlRenderer implements RendererInterface
|
||||
*/
|
||||
public function render(array $timesheets, TimesheetQuery $query): Response
|
||||
{
|
||||
$publicMetaFields = [];
|
||||
foreach ($timesheets as $timesheet) {
|
||||
foreach ($timesheet->getVisibleMetaFields() as $metaField) {
|
||||
$publicMetaFields[] = $metaField->getName();
|
||||
}
|
||||
}
|
||||
$timesheetMetaFields = $this->findMetaColumns(new TimesheetMetaDisplayEvent($query, TimesheetMetaDisplayEvent::EXPORT));
|
||||
$customerMetaFields = $this->findMetaColumns(new CustomerMetaDisplayEvent($query, CustomerMetaDisplayEvent::EXPORT));
|
||||
$projectMetaFields = $this->findMetaColumns(new ProjectMetaDisplayEvent($query, ProjectMetaDisplayEvent::EXPORT));
|
||||
$activityMetaFields = $this->findMetaColumns(new ActivityMetaDisplayEvent($query, ActivityMetaDisplayEvent::EXPORT));
|
||||
|
||||
$event = new UserPreferenceDisplayEvent(UserPreferenceDisplayEvent::EXPORT);
|
||||
$this->dispatcher->dispatch($event);
|
||||
$userPreferences = $event->getPreferences();
|
||||
|
||||
$content = $this->twig->render('export/renderer/default.html.twig', [
|
||||
'entries' => $timesheets,
|
||||
'query' => $query,
|
||||
'metaFields' => array_unique($publicMetaFields),
|
||||
'summaries' => $this->calculateSummary($timesheets),
|
||||
'timesheetMetaFields' => $timesheetMetaFields,
|
||||
'customerMetaFields' => $customerMetaFields,
|
||||
'projectMetaFields' => $projectMetaFields,
|
||||
'activityMetaFields' => $activityMetaFields,
|
||||
'userPreferences' => $userPreferences,
|
||||
]);
|
||||
|
||||
$response = new Response();
|
||||
|
||||
@@ -42,11 +42,11 @@ class EntityMetaDefinitionType extends AbstractType
|
||||
return;
|
||||
}
|
||||
|
||||
$event->getForm()->add('value', $definition->getType(), [
|
||||
$event->getForm()->add('value', $definition->getType(), array_merge([
|
||||
'label' => $definition->getLabel(),
|
||||
'constraints' => $definition->getConstraints(),
|
||||
'required' => $definition->isRequired(),
|
||||
]);
|
||||
], $definition->getOptions()));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
namespace App\Repository\Loader;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Timesheet;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
@@ -19,10 +21,15 @@ final class TimesheetIdLoader implements LoaderInterface
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
private $entityManager;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $fullyHydrated = false;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
public function __construct(EntityManagerInterface $entityManager, bool $hydrateFullTree = false)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->fullyHydrated = $hydrateFullTree;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,23 +44,45 @@ final class TimesheetIdLoader implements LoaderInterface
|
||||
$em = $this->entityManager;
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$projects = $qb->select('PARTIAL t.{id}', 'project')
|
||||
$timesheets = $qb->select('PARTIAL t.{id}', 'project')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.project', 'project')
|
||||
->andWhere($qb->expr()->in('t.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
if (!empty($projects)) {
|
||||
$projectIds = array_map(function (Timesheet $timesheet) {
|
||||
return $timesheet->getProject()->getId();
|
||||
$projectIds = array_map(function (Timesheet $timesheet) {
|
||||
return $timesheet->getProject()->getId();
|
||||
}, $timesheets);
|
||||
|
||||
if ($this->fullyHydrated) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL p.{id}', 'meta')
|
||||
->from(Project::class, 'p')
|
||||
->leftJoin('p.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('p.id', $projectIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$projects = $qb->select('PARTIAL p.{id}', 'customer')
|
||||
->from(Project::class, 'p')
|
||||
->leftJoin('p.customer', 'customer')
|
||||
->andWhere($qb->expr()->in('p.id', $projectIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
if ($this->fullyHydrated) {
|
||||
$customerIds = array_map(function (Project $project) {
|
||||
return $project->getCustomer()->getId();
|
||||
}, $projects);
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL p.{id}', 'customer')
|
||||
->from(Project::class, 'p')
|
||||
->leftJoin('p.customer', 'customer')
|
||||
->andWhere($qb->expr()->in('p.id', $projectIds))
|
||||
$qb->select('PARTIAL c.{id}', 'meta')
|
||||
->from(Customer::class, 'c')
|
||||
->leftJoin('c.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('c.id', $customerIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
@@ -66,6 +95,20 @@ final class TimesheetIdLoader implements LoaderInterface
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
if ($this->fullyHydrated) {
|
||||
$activityIds = array_map(function (Timesheet $timesheet) {
|
||||
return $timesheet->getActivity()->getId();
|
||||
}, $timesheets);
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL a.{id}', 'meta')
|
||||
->from(Activity::class, 'a')
|
||||
->leftJoin('a.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('a.id', $activityIds))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL t.{id}', 'user')
|
||||
->from(Timesheet::class, 't')
|
||||
|
||||
@@ -19,9 +19,9 @@ final class TimesheetLoader implements LoaderInterface
|
||||
*/
|
||||
private $loader;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
public function __construct(EntityManagerInterface $entityManager, bool $hydrateFullTree = false)
|
||||
{
|
||||
$this->loader = new TimesheetIdLoader($entityManager);
|
||||
$this->loader = new TimesheetIdLoader($entityManager, $hydrateFullTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,6 +42,11 @@ class TagRepository extends EntityRepository
|
||||
$entityManager->flush();
|
||||
}
|
||||
|
||||
public function findTagByName(string $tagName): ?Tag
|
||||
{
|
||||
return $this->findOneBy(['name' => $tagName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find ids of the given tagNames separated by comma
|
||||
* @param string $tagNames
|
||||
|
||||
@@ -432,12 +432,7 @@ class TimesheetRepository extends EntityRepository
|
||||
$qb->setParameter('user', $user);
|
||||
}
|
||||
|
||||
$results = $qb->getQuery()->getResult();
|
||||
|
||||
$loader = new TimesheetLoader($qb->getEntityManager());
|
||||
$loader->loadResults($results);
|
||||
|
||||
return $results;
|
||||
return $this->getHydratedResultsByQuery($qb, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -530,16 +525,33 @@ class TimesheetRepository extends EntityRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* When switching $fullyHydrated to true, the call gets even more expensive.
|
||||
* You normally don't need this, unless you want to access deeply nested attributes for many entries!
|
||||
*
|
||||
* @param TimesheetQuery $query
|
||||
* @param bool $fullyHydrated
|
||||
* @return Timesheet[]
|
||||
*/
|
||||
public function getTimesheetsForQuery(TimesheetQuery $query): iterable
|
||||
public function getTimesheetsForQuery(TimesheetQuery $query, bool $fullyHydrated = false): iterable
|
||||
{
|
||||
// this is using the paginator internally, as it will load all joined entities into the working unit
|
||||
// do not "optimize" to use the query directly, as it would results in hundreds of additional lazy queries
|
||||
$paginator = $this->getPaginatorForQuery($query);
|
||||
$qb = $this->getQueryBuilderForQuery($query);
|
||||
|
||||
return $paginator->getAll();
|
||||
return $this->getHydratedResultsByQuery($qb, $fullyHydrated);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param QueryBuilder $qb
|
||||
* @param bool $fullyHydrated
|
||||
* @return Timesheet[]
|
||||
*/
|
||||
protected function getHydratedResultsByQuery(QueryBuilder $qb, bool $fullyHydrated = false): iterable
|
||||
{
|
||||
$results = $qb->getQuery()->getResult();
|
||||
|
||||
$loader = new TimesheetLoader($qb->getEntityManager(), $fullyHydrated);
|
||||
$loader->loadResults($results);
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
private function getQueryBuilderForQuery(TimesheetQuery $query): QueryBuilder
|
||||
@@ -738,12 +750,7 @@ class TimesheetRepository extends EntityRepository
|
||||
->orderBy('t.end', 'DESC')
|
||||
;
|
||||
|
||||
$results = $qb->getQuery()->getResult();
|
||||
|
||||
$loader = new TimesheetLoader($qb->getEntityManager());
|
||||
$loader->loadResults($results);
|
||||
|
||||
return $results;
|
||||
return $this->getHydratedResultsByQuery($qb, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -80,41 +80,53 @@ class DateExtensions extends AbstractExtension
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $date
|
||||
* @param DateTime|string $date
|
||||
* @return string
|
||||
*/
|
||||
public function dateShort(DateTime $date)
|
||||
public function dateShort($date)
|
||||
{
|
||||
if (null === $this->dateFormat) {
|
||||
$this->dateFormat = $this->localeSettings->getDateFormat();
|
||||
}
|
||||
|
||||
if (!$date instanceof DateTime) {
|
||||
$date = new DateTime($date);
|
||||
}
|
||||
|
||||
return date_format($date, $this->dateFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $date
|
||||
* @param DateTime|string $date
|
||||
* @return string
|
||||
*/
|
||||
public function dateTime(DateTime $date)
|
||||
public function dateTime($date)
|
||||
{
|
||||
if (null === $this->dateTimeFormat) {
|
||||
$this->dateTimeFormat = $this->localeSettings->getDateTimeFormat();
|
||||
}
|
||||
|
||||
if (!$date instanceof DateTime) {
|
||||
$date = new DateTime($date);
|
||||
}
|
||||
|
||||
return date_format($date, $this->dateTimeFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $date
|
||||
* @param DateTime|string $date
|
||||
* @return string
|
||||
*/
|
||||
public function dateTimeFull(DateTime $date)
|
||||
public function dateTimeFull($date)
|
||||
{
|
||||
if (null === $this->dateTimeTypeFormat) {
|
||||
$this->dateTimeTypeFormat = $this->localeSettings->getDateTimeTypeFormat();
|
||||
}
|
||||
|
||||
if (!$date instanceof DateTime) {
|
||||
$date = new DateTime($date);
|
||||
}
|
||||
|
||||
$formatter = new \IntlDateFormatter(
|
||||
$this->localeSettings->getLocale(),
|
||||
\IntlDateFormatter::MEDIUM,
|
||||
@@ -128,25 +140,33 @@ class DateExtensions extends AbstractExtension
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $date
|
||||
* @param DateTime|string $date
|
||||
* @param string $format
|
||||
* @return false|string
|
||||
*/
|
||||
public function dateFormat(DateTime $date, string $format)
|
||||
public function dateFormat($date, string $format)
|
||||
{
|
||||
if (!$date instanceof DateTime) {
|
||||
$date = new DateTime($date);
|
||||
}
|
||||
|
||||
return date_format($date, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $date
|
||||
* @param DateTime|string $date
|
||||
* @return string
|
||||
*/
|
||||
public function time(DateTime $date)
|
||||
public function time($date)
|
||||
{
|
||||
if (null === $this->timeFormat) {
|
||||
$this->timeFormat = $this->localeSettings->getTimeFormat();
|
||||
}
|
||||
|
||||
if (!$date instanceof DateTime) {
|
||||
$date = new DateTime($date);
|
||||
}
|
||||
|
||||
return date_format($date, $this->timeFormat);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ use App\Utils\LocaleSettings;
|
||||
use NumberFormatter;
|
||||
use Symfony\Component\Intl\Countries;
|
||||
use Symfony\Component\Intl\Currencies;
|
||||
use Symfony\Component\Intl\Languages;
|
||||
use Symfony\Component\Intl\Locales;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
@@ -67,6 +68,7 @@ class Extensions extends AbstractExtension
|
||||
new TwigFilter('money', [$this, 'money']),
|
||||
new TwigFilter('currency', [$this, 'currency']),
|
||||
new TwigFilter('country', [$this, 'country']),
|
||||
new TwigFilter('language', [$this, 'language']),
|
||||
new TwigFilter('docu_link', [$this, 'documentationLink']),
|
||||
];
|
||||
}
|
||||
@@ -162,6 +164,15 @@ class Extensions extends AbstractExtension
|
||||
return Currencies::getSymbol($currency);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $language
|
||||
* @return string
|
||||
*/
|
||||
public function language($language)
|
||||
{
|
||||
return Languages::getName($language, $this->locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $country
|
||||
* @return string
|
||||
|
||||
@@ -9,9 +9,16 @@
|
||||
'customer': 'hidden-xs',
|
||||
'project': 'hidden-xs',
|
||||
'comment': 'hidden-xs',
|
||||
} %}
|
||||
{% for field in metaColumns %}
|
||||
{% set columns = columns|merge({
|
||||
(field.name): {'title': field.label, 'class': 'hidden-xs hidden-sm', 'orderBy': false}
|
||||
}) %}
|
||||
{% endfor %}
|
||||
{% set columns = columns|merge({
|
||||
'visible': {'class': '', 'orderBy': false},
|
||||
'actions': 'actions alwaysVisible',
|
||||
} %}
|
||||
}) %}
|
||||
|
||||
{% set tableName = 'activity_admin' %}
|
||||
|
||||
@@ -46,6 +53,11 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'comment') }}">{{ entry.comment|comment2html }}</td>
|
||||
{% for field in metaColumns %}
|
||||
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, field.name) }}">
|
||||
{{ tables.datatable_meta_column(entry, field) }}
|
||||
</td>
|
||||
{% endfor %}
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'visible') }}">{{ widgets.label_visible(entry.visible) }}</td>
|
||||
<td class="actions">
|
||||
{{ actions.activity(entry, 'index') }}
|
||||
|
||||
@@ -9,10 +9,17 @@
|
||||
'comment': 'hidden-xs',
|
||||
'country': 'hidden-xs hidden-sm',
|
||||
'number': 'hidden-xs',
|
||||
} %}
|
||||
{% for field in metaColumns %}
|
||||
{% set columns = columns|merge({
|
||||
(field.name): {'title': field.label, 'class': 'hidden-xs hidden-sm', 'orderBy': false}
|
||||
}) %}
|
||||
{% endfor %}
|
||||
{% set columns = columns|merge({
|
||||
'team': {'class': '', 'orderBy': false},
|
||||
'visible': {'class': 'hidden-xs', 'orderBy': false},
|
||||
'actions': 'actions alwaysVisible',
|
||||
} %}
|
||||
}) %}
|
||||
|
||||
{% set tableName = 'customer_admin' %}
|
||||
|
||||
@@ -37,6 +44,11 @@
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'comment') }}">{{ entry.comment|comment2html }}</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'country') }}">{{ entry.country|country }}</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'number') }}">{{ entry.number }}</td>
|
||||
{% for field in metaColumns %}
|
||||
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, field.name) }}">
|
||||
{{ tables.datatable_meta_column(entry, field) }}
|
||||
</td>
|
||||
{% endfor %}
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'team') }}">
|
||||
{% if entry.teams|length > 0 %}
|
||||
{{ widgets.badge_counter(entry.teams|length) }}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{% import "macros/widgets.html.twig" as widgets %}
|
||||
{% import "macros/datatables.html.twig" as tables %}
|
||||
{% extends 'export/layout.html.twig' %}
|
||||
|
||||
{% set columnTitles = {} %}
|
||||
@@ -13,9 +14,25 @@
|
||||
'tags': false,
|
||||
} %}
|
||||
|
||||
{% for id, metaField in metaFields %}
|
||||
{% set columns = columns|merge({ (metaField): true}) %}
|
||||
{% set columnTitles = columnTitles|merge({ (metaField): (metaField)}) %}
|
||||
{% for id, field in timesheetMetaFields %}
|
||||
{% set columns = columns|merge({ ('t_' ~ field.name): true}) %}
|
||||
{% set columnTitles = columnTitles|merge({ ('t_' ~ field.name): (field.label)}) %}
|
||||
{% endfor %}
|
||||
{% for id, field in customerMetaFields %}
|
||||
{% set columns = columns|merge({ ('c_' ~ field.name): true}) %}
|
||||
{% set columnTitles = columnTitles|merge({ ('c_' ~ field.name): (field.label)}) %}
|
||||
{% endfor %}
|
||||
{% for id, field in projectMetaFields %}
|
||||
{% set columns = columns|merge({ ('p_' ~ field.name): true}) %}
|
||||
{% set columnTitles = columnTitles|merge({ ('p_' ~ field.name): (field.label)}) %}
|
||||
{% endfor %}
|
||||
{% for id, field in activityMetaFields %}
|
||||
{% set columns = columns|merge({ ('a_' ~ field.name): true}) %}
|
||||
{% set columnTitles = columnTitles|merge({ ('a_' ~ field.name): (field.label)}) %}
|
||||
{% endfor %}
|
||||
{% for id, field in userPreferences %}
|
||||
{% set columns = columns|merge({ ('u_' ~ field.name): true}) %}
|
||||
{% set columnTitles = columnTitles|merge({ ('u_' ~ field.name): (field.label)}) %}
|
||||
{% endfor %}
|
||||
|
||||
{% set columns = columns|merge({
|
||||
@@ -293,11 +310,31 @@
|
||||
{{ entry.tagsAsArray|join(', ') }}
|
||||
{% endif %}
|
||||
</td>
|
||||
{% for id, metaFieldName in metaFields %}
|
||||
<td class="column-{{ metaFieldName }} text-nowrap" {% if not columns[metaFieldName] %}style="display: none"{% endif %}>
|
||||
{% set metaField = entry.metaField(metaFieldName) %}
|
||||
{% if not metaField is null and metaField.visible %}
|
||||
{{ metaField.value }}
|
||||
{% for id, field in timesheetMetaFields %}
|
||||
<td class="column-{{ 't_' ~ field.name }} text-nowrap" {% if not columns['t_' ~ field.name] %}style="display: none"{% endif %}>
|
||||
{{ tables.datatable_meta_column(entry, field) }}
|
||||
</td>
|
||||
{% endfor %}
|
||||
{% for id, field in customerMetaFields %}
|
||||
<td class="column-{{ 'c_' ~ field.name }} text-nowrap" {% if not columns['c_' ~ field.name] %}style="display: none"{% endif %}>
|
||||
{{ tables.datatable_meta_column(entry.project.customer, field) }}
|
||||
</td>
|
||||
{% endfor %}
|
||||
{% for id, field in projectMetaFields %}
|
||||
<td class="column-{{ 'p_' ~ field.name }} text-nowrap" {% if not columns['p_' ~ field.name] %}style="display: none"{% endif %}>
|
||||
{{ tables.datatable_meta_column(entry.project, field) }}
|
||||
</td>
|
||||
{% endfor %}
|
||||
{% for id, field in activityMetaFields %}
|
||||
<td class="column-{{ 'a_' ~ field.name }} text-nowrap" {% if not columns['a_' ~ field.name] %}style="display: none"{% endif %}>
|
||||
{{ tables.datatable_meta_column(entry.activity, field) }}
|
||||
</td>
|
||||
{% endfor %}
|
||||
{% for id, field in userPreferences %}
|
||||
<td class="column-{{ 'u_' ~ field.name }} text-nowrap" {% if not columns['u_' ~ field.name] %}style="display: none"{% endif %}>
|
||||
{% set metaField = entry.user.preference(field.name) %}
|
||||
{% if not metaField is null and metaField.value is not null and metaField.value is not empty %}
|
||||
{{ widgets.form_type_value(field.type, metaField.value, entry.user) }}
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endfor %}
|
||||
|
||||
@@ -9,11 +9,18 @@
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form name="{{ name }}_visibility">
|
||||
{% for title, class in columns %}
|
||||
{% if 'alwaysVisible' not in class %}
|
||||
{%- for title, headerOptions in columns -%}
|
||||
{% if not headerOptions is iterable %}
|
||||
{% set headerOptions = {'class': headerOptions} %}
|
||||
{% endif %}
|
||||
{% set headerTitle = ('label.' ~ title)|trans %}
|
||||
{% if headerOptions.title is defined %}
|
||||
{% set headerTitle = headerOptions.title %}
|
||||
{% endif %}
|
||||
{% if 'alwaysVisible' not in headerOptions.class %}
|
||||
<div class="form-group">
|
||||
<input type="checkbox" id="column_{{ title }}" name="{{ title }}"{% if is_visible_column(name, title) %} checked="checked"{% endif %}>
|
||||
<label class="control-label" for="column_{{ title }}">{{ ('label.' ~ title)|trans }}</label>
|
||||
<label class="control-label" for="column_{{ title }}">{{ headerTitle }}</label>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
@@ -66,7 +73,9 @@
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% set headerTitle = '' %}
|
||||
{% if title is not empty and title != 'actions' %}
|
||||
{% if headerOptions.title is defined %}
|
||||
{% set headerTitle = headerOptions.title %}
|
||||
{% elseif title is not empty and title != 'actions' %}
|
||||
{% set headerTitle = (translationPrefix ~ title)|trans({}, translationDomain) %}
|
||||
{% endif %}
|
||||
<th data-field="{{ title }}" {% if not headerOptions.orderBy is same as(false) %}data-order="{{ headerOptions.orderBy }}" {% endif %}class="{{ headerClass }}">{{ headerTitle }}</th>
|
||||
@@ -168,3 +177,12 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro datatable_meta_column(entry, field) %}
|
||||
{% import "macros/widgets.html.twig" as widgets %}
|
||||
{% set metaField = entry.metaField(field.name) %}
|
||||
{% if not metaField is null and metaField.value is not null and metaField.value is not empty %}
|
||||
{% set metaField = metaField.merge(field) %}
|
||||
{{ widgets.form_type_value(metaField.type, metaField.value, entry) }}
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
@@ -102,6 +102,12 @@
|
||||
</span>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro color_dot(color, tooltip) %}
|
||||
<span class="label-color" data-toggle="tooltip" data-placement="top" title="{{ tooltip }}">
|
||||
<span class="dot" style="background-color:{{ color }}"></span>
|
||||
</span>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro badge_counter(count, url) %}
|
||||
{% if url %}
|
||||
<a href="{{ url }}"><span class="badge bg-blue">{{ count }}</span></a>
|
||||
@@ -294,3 +300,40 @@
|
||||
{{ macro.badge(tag.name , 'green') }}
|
||||
{% endfor %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro form_type_value(type, value, entity) %}
|
||||
{% import _self as widgets %}
|
||||
{% if '\\ColorPickerType' in type %}
|
||||
{{ widgets.color_dot(value, value) }}
|
||||
{% elseif '\\DurationType' in type %}
|
||||
{{ value|duration }}
|
||||
{% elseif '\\YesNoType' in type or '\\CheckBoxType' in type %}
|
||||
{{ widgets.label_boolean(value) }}
|
||||
{% elseif '\\DatePickerType' in type %}
|
||||
{{ value|date_short }}
|
||||
{% elseif '\\DateTimePickerType' in type %}
|
||||
{{ value|date_full }}
|
||||
{% elseif '\\CountryType' in type %}
|
||||
{{ value|country }}
|
||||
{% elseif '\\CurrencyType' in type %}
|
||||
{{ value|currency }}
|
||||
{% elseif '\\LanguageType' in type %}
|
||||
{{ value|language }}
|
||||
{% elseif '\\MoneyType' in type %}
|
||||
{% if entity is null %}
|
||||
{{ value }}
|
||||
{% elseif class_name(entity) == 'App\\Entity\\Timesheet' %}
|
||||
{{ value|money(entity.project.customer.currency) }}
|
||||
{% elseif class_name(entity) == 'App\\Entity\\Customer' %}
|
||||
{{ value|money(entity.currency) }}
|
||||
{% elseif class_name(entity) == 'App\\Entity\\Project' %}
|
||||
{{ value|money(entity.customer.currency) }}
|
||||
{% elseif class_name(entity) == 'App\\Entity\\Activity' and entity.project is not null %}
|
||||
{{ value|money(entity.project.customer.currency) }}
|
||||
{% else %}
|
||||
{{ value }}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{{ value }}
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
@@ -9,10 +9,17 @@
|
||||
'customer': 'hidden-xs',
|
||||
'comment': 'hidden-xs hidden-sm',
|
||||
'orderNumber': 'hidden-xs hidden-sm',
|
||||
} %}
|
||||
{% for field in metaColumns %}
|
||||
{% set columns = columns|merge({
|
||||
(field.name): {'title': field.label, 'class': 'hidden-xs hidden-sm', 'orderBy': false}
|
||||
}) %}
|
||||
{% endfor %}
|
||||
{% set columns = columns|merge({
|
||||
'team': {'class': '', 'orderBy': false},
|
||||
'visible': {'class': '', 'orderBy': false},
|
||||
'actions': 'actions alwaysVisible',
|
||||
} %}
|
||||
}) %}
|
||||
|
||||
{% set tableName = 'project_admin' %}
|
||||
|
||||
@@ -39,6 +46,11 @@
|
||||
</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'comment') }}">{{ entry.comment|comment2html }}</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'orderNumber') }}">{{ entry.orderNumber }}</td>
|
||||
{% for field in metaColumns %}
|
||||
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, field.name) }}">
|
||||
{{ tables.datatable_meta_column(entry, field) }}
|
||||
</td>
|
||||
{% endfor %}
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'team') }}">
|
||||
{% if entry.teams|length > 0 %}
|
||||
{{ widgets.badge_counter(entry.teams|length) }}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{% import "macros/widgets.html.twig" as widgets %}
|
||||
{% import "macros/datatables.html.twig" as tables %}
|
||||
{% extends 'invoice/layout.html.twig' %}
|
||||
|
||||
{% block invoice %}
|
||||
@@ -34,6 +35,9 @@
|
||||
<th>{{ 'label.username'|trans }}</th>
|
||||
{% endif %}
|
||||
<th>{{ 'label.description'|trans }}</th>
|
||||
{% for field in metaColumns %}
|
||||
<th>{{ field.label|trans }}</th>
|
||||
{% endfor %}
|
||||
<th>{{ 'label.hours'|trans }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -58,6 +62,9 @@
|
||||
{{ 'label.customer'|trans }}: {{ entry.project.customer.name }}
|
||||
</span>
|
||||
</td>
|
||||
{% for field in metaColumns %}
|
||||
<td>{{ tables.datatable_meta_column(entry, field) }}</td>
|
||||
{% endfor %}
|
||||
<td class="text-nowrap">{{ entry.duration|duration }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
@@ -65,6 +72,12 @@
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th></th>
|
||||
{% if query.user is empty %}
|
||||
<th></th>
|
||||
{% endif %}
|
||||
{% for field in metaColumns %}
|
||||
<th></th>
|
||||
{% endfor %}
|
||||
<th>{{ 'invoice.total_working_time'|trans }}</th>
|
||||
<th>{{ timeWorked|duration }}</th>
|
||||
</tr>
|
||||
|
||||
@@ -25,6 +25,13 @@
|
||||
'description': 'hidden-xs hidden-sm',
|
||||
'username': {'class': 'hidden-xs', 'orderBy': false},
|
||||
'tags': {'class': 'hidden-xs hidden-sm', 'orderBy': false},
|
||||
}) %}
|
||||
{% for field in metaColumns %}
|
||||
{% set columns = columns|merge({
|
||||
(field.name): {'title': field.label, 'class': 'hidden-xs hidden-sm', 'orderBy': false}
|
||||
}) %}
|
||||
{% endfor %}
|
||||
{% set columns = columns|merge({
|
||||
'actions': 'actions alwaysVisible',
|
||||
}) %}
|
||||
|
||||
@@ -87,6 +94,11 @@
|
||||
{{ widgets.label_user(entry.user) }}
|
||||
</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'tags') }}">{{ widgets.tag_list(entry.tags) }}</td>
|
||||
{% for field in metaColumns %}
|
||||
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, field.name) }}">
|
||||
{{ tables.datatable_meta_column(entry, field) }}
|
||||
</td>
|
||||
{% endfor %}
|
||||
<td class="actions">
|
||||
{{- actions.timesheet_team(entry, 'index') -}}
|
||||
</td>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{% import "macros/widgets.html.twig" as widgets %}
|
||||
{% import "macros/datatables.html.twig" as tables %}
|
||||
{% extends 'invoice/layout.html.twig' %}
|
||||
|
||||
{% block invoice %}
|
||||
@@ -29,6 +30,9 @@
|
||||
<tr>
|
||||
<th>{{ 'label.date'|trans }}</th>
|
||||
<th>{{ 'label.description'|trans }}</th>
|
||||
{% for field in metaColumns %}
|
||||
<th>{{ field.label|trans }}</th>
|
||||
{% endfor %}
|
||||
<th>{{ 'label.hours'|trans }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -50,6 +54,9 @@
|
||||
{{ 'label.customer'|trans }}: {{ entry.project.customer.name }}
|
||||
</span>
|
||||
</td>
|
||||
{% for field in metaColumns %}
|
||||
<td>{{ tables.datatable_meta_column(entry, field) }}</td>
|
||||
{% endfor %}
|
||||
<td class="text-nowrap">{{ entry.duration|duration }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
@@ -57,6 +64,9 @@
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th></th>
|
||||
{% for field in metaColumns %}
|
||||
<th></th>
|
||||
{% endfor %}
|
||||
<th>{{ 'invoice.total_working_time'|trans }}</th>
|
||||
<th>{{ timeWorked|duration }}</th>
|
||||
</tr>
|
||||
|
||||
@@ -27,6 +27,13 @@
|
||||
'activity': 'hidden-xs hidden-sm',
|
||||
'description': 'hidden-xs hidden-sm',
|
||||
'tags': {'class': 'hidden-xs hidden-sm', 'orderBy': false},
|
||||
}) %}
|
||||
{% for field in metaColumns %}
|
||||
{% set columns = columns|merge({
|
||||
(field.name): {'title': field.label, 'class': 'hidden-xs hidden-sm', 'orderBy': false}
|
||||
}) %}
|
||||
{% endfor %}
|
||||
{% set columns = columns|merge({
|
||||
'actions': 'actions alwaysVisible',
|
||||
}) %}
|
||||
|
||||
@@ -54,7 +61,7 @@
|
||||
{% set day = entry.begin|date_short %}
|
||||
{% endif %}
|
||||
{%- if showSummary and day is not same as(entry.begin|date_short) -%}
|
||||
{{ timesheet.summary(day, dayDuration, dayRate, columns, canSeeRate, showStartEndTime, tableName) }}
|
||||
{{ timesheet.summary(day, dayDuration, dayRate, columns, canSeeRate, showStartEndTime, tableName, metaColumns) }}
|
||||
{% set day = entry.begin|date_short %}
|
||||
{% set dayDuration = 0 %}
|
||||
{% set dayRate = {} %}
|
||||
@@ -96,6 +103,11 @@
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'activity') }}">{{ widgets.label_activity(entry.activity) }}</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'description') }} timesheet-description">{{ entry.description|escape|desc2html }}</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'tags') }}">{{ widgets.tag_list(entry.tags) }}</td>
|
||||
{% for field in metaColumns %}
|
||||
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, field.name) }}">
|
||||
{{ tables.datatable_meta_column(entry, field) }}
|
||||
</td>
|
||||
{% endfor %}
|
||||
<td class="actions">
|
||||
{{- actions.timesheet(entry, 'index') -}}
|
||||
</td>
|
||||
@@ -110,7 +122,7 @@
|
||||
{% endfor %}
|
||||
|
||||
{% if showSummary %}
|
||||
{{ timesheet.summary(day, dayDuration, dayRate, columns, canSeeRate, showStartEndTime, tableName) }}
|
||||
{{ timesheet.summary(day, dayDuration, dayRate, columns, canSeeRate, showStartEndTime, tableName, metaColumns) }}
|
||||
{% endif %}
|
||||
|
||||
{{ tables.data_table_footer(entries, 'timesheet_paginated') }}
|
||||
@@ -118,7 +130,7 @@
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% macro summary(day, duration, dayRates, columns, canSeeRate, showStartEndTime, tableName) %}
|
||||
{% macro summary(day, duration, dayRates, columns, canSeeRate, showStartEndTime, tableName, metaColumns) %}
|
||||
{% import "macros/datatables.html.twig" as tables %}
|
||||
<tr class="summary info">
|
||||
<td class="text-nowrap">{{ day }}</td>
|
||||
@@ -142,6 +154,9 @@
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'activity') }}"></td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'description') }}"></td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'tags') }}"></td>
|
||||
{% for field in metaColumns %}
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, field.name) }}"></td>
|
||||
{% endfor %}
|
||||
<td class="actions"></td>
|
||||
</tr>
|
||||
{% endmacro %}
|
||||
|
||||
@@ -9,10 +9,17 @@
|
||||
'username': 'hidden-xs',
|
||||
'email': 'hidden-xs hidden-sm',
|
||||
'title': 'hidden-xs',
|
||||
} %}
|
||||
{% for pref in preferences %}
|
||||
{% set columns = columns|merge({
|
||||
(pref.name): {'title': pref.label, 'class': 'hidden-xs hidden-sm', 'orderBy': false}
|
||||
}) %}
|
||||
{% endfor %}
|
||||
{% set columns = columns|merge({
|
||||
'roles': {'class': 'hidden-xs', 'orderBy': false},
|
||||
'active': {'class': '', 'orderBy': false},
|
||||
'actions': 'actions alwaysVisible',
|
||||
} %}
|
||||
}) %}
|
||||
|
||||
{% set tableName = 'user_admin' %}
|
||||
|
||||
@@ -37,6 +44,14 @@
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'username') }}">{{ entry.username }}</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'email') }}">{{ entry.email }}</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'title') }}">{{ entry.title }}</td>
|
||||
{% for pref in preferences %}
|
||||
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, pref.name) }}">
|
||||
{% set metaField = entry.preference(pref.name) %}
|
||||
{% if not metaField is null and metaField.value is not null and metaField.value is not empty %}
|
||||
{{ widgets.form_type_value(pref.type, metaField.value, entry) }}
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endfor %}
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'roles') }}">
|
||||
{% for role in entry.roles %}
|
||||
{% if role != 'ROLE_USER' %}
|
||||
|
||||
@@ -84,13 +84,13 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
|
||||
{
|
||||
$data = ['message' => 'Authentication required, missing headers: X-AUTH-USER, X-AUTH-TOKEN'];
|
||||
|
||||
$this->assertEquals(
|
||||
self::assertEquals(
|
||||
$data,
|
||||
json_decode($response->getContent(), true),
|
||||
sprintf('The secure URL %s is not protected.', $url)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
self::assertEquals(
|
||||
Response::HTTP_FORBIDDEN,
|
||||
$response->getStatusCode(),
|
||||
sprintf('The secure URL %s has the wrong status code %s.', $url, $response->getStatusCode())
|
||||
@@ -107,7 +107,7 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
|
||||
$client = $this->getClientForAuthenticatedUser($role);
|
||||
$client->request($method, $this->createUrl($url));
|
||||
|
||||
$this->assertFalse(
|
||||
self::assertFalse(
|
||||
$client->getResponse()->isSuccessful(),
|
||||
sprintf('The secure URL %s is not protected for role %s', $url, $role)
|
||||
);
|
||||
@@ -117,9 +117,9 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
|
||||
'message' => 'Access denied.'
|
||||
];
|
||||
|
||||
$this->assertEquals(403, $client->getResponse()->getStatusCode());
|
||||
self::assertEquals(403, $client->getResponse()->getStatusCode());
|
||||
|
||||
$this->assertEquals(
|
||||
self::assertEquals(
|
||||
$expected,
|
||||
json_decode($client->getResponse()->getContent(), true)
|
||||
);
|
||||
@@ -142,9 +142,9 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
|
||||
'message' => 'Not found'
|
||||
];
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
self::assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
|
||||
$this->assertEquals(
|
||||
self::assertEquals(
|
||||
$expected,
|
||||
json_decode($client->getResponse()->getContent(), true)
|
||||
);
|
||||
@@ -164,11 +164,11 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
|
||||
|
||||
$this->request($client, $url, 'PATCH', [], json_encode($data));
|
||||
$response = $client->getResponse();
|
||||
$this->assertFalse($response->isSuccessful());
|
||||
self::assertFalse($response->isSuccessful());
|
||||
|
||||
$this->assertEquals($expectedErrors['code'], $client->getResponse()->getStatusCode());
|
||||
self::assertEquals($expectedErrors['code'], $client->getResponse()->getStatusCode());
|
||||
|
||||
$this->assertEquals(
|
||||
self::assertEquals(
|
||||
$expectedErrors,
|
||||
json_decode($client->getResponse()->getContent(), true)
|
||||
);
|
||||
@@ -180,16 +180,16 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
|
||||
|
||||
$this->request($client, $url, 'DELETE', [], json_encode($data));
|
||||
$response = $client->getResponse();
|
||||
$this->assertFalse($response->isSuccessful());
|
||||
self::assertFalse($response->isSuccessful());
|
||||
|
||||
$expected = [
|
||||
'code' => 404,
|
||||
'message' => 'Not found'
|
||||
];
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
self::assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
|
||||
$this->assertEquals(
|
||||
self::assertEquals(
|
||||
$expected,
|
||||
json_decode($client->getResponse()->getContent(), true)
|
||||
);
|
||||
@@ -197,9 +197,9 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
|
||||
|
||||
protected function assertApiException(Response $response, string $message)
|
||||
{
|
||||
$this->assertFalse($response->isSuccessful());
|
||||
$this->assertEquals(500, $response->getStatusCode());
|
||||
$this->assertEquals(['code' => 500, 'message' => $message], json_decode($response->getContent(), true));
|
||||
self::assertFalse($response->isSuccessful());
|
||||
self::assertEquals(500, $response->getStatusCode());
|
||||
self::assertEquals(['code' => 500, 'message' => $message], json_decode($response->getContent(), true));
|
||||
}
|
||||
|
||||
protected function assertApiAccessDenied(Client $client, string $url, string $message)
|
||||
@@ -210,28 +210,35 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
|
||||
|
||||
protected function assertApiResponseAccessDenied(Response $response, string $message)
|
||||
{
|
||||
$this->assertFalse($response->isSuccessful());
|
||||
$this->assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode());
|
||||
self::assertFalse($response->isSuccessful());
|
||||
self::assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode());
|
||||
$expected = ['code' => Response::HTTP_FORBIDDEN, 'message' => $message];
|
||||
$this->assertEquals($expected, json_decode($response->getContent(), true));
|
||||
self::assertEquals($expected, json_decode($response->getContent(), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
* @param string[] $failedFields
|
||||
* @param bool $extraFields
|
||||
*/
|
||||
protected function assertApiCallValidationError(Response $response, array $failedFields)
|
||||
protected function assertApiCallValidationError(Response $response, array $failedFields, bool $extraFields = false)
|
||||
{
|
||||
$this->assertFalse($response->isSuccessful());
|
||||
self::assertFalse($response->isSuccessful());
|
||||
$result = json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertArrayHasKey('errors', $result);
|
||||
$this->assertArrayHasKey('children', $result['errors']);
|
||||
self::assertArrayHasKey('errors', $result);
|
||||
|
||||
if ($extraFields) {
|
||||
self::assertArrayHasKey('errors', $result['errors']);
|
||||
self::assertEquals($result['errors']['errors'][0], 'This form should not contain extra fields.');
|
||||
}
|
||||
|
||||
self::assertArrayHasKey('children', $result['errors']);
|
||||
$data = $result['errors']['children'];
|
||||
|
||||
foreach ($failedFields as $fieldName) {
|
||||
$this->assertArrayHasKey($fieldName, $data);
|
||||
$this->assertArrayHasKey('errors', $data[$fieldName]);
|
||||
self::assertArrayHasKey($fieldName, $data);
|
||||
self::assertArrayHasKey('errors', $data[$fieldName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,6 +164,20 @@ class ActivityControllerTest extends APIControllerBaseTest
|
||||
$this->assertEquals('User cannot create activities', $json['message']);
|
||||
}
|
||||
|
||||
public function testPostActionWithInvalidData()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$data = [
|
||||
'name' => 'foo',
|
||||
'project' => 100,
|
||||
'unexpected' => 'foo-bar',
|
||||
'visible' => true
|
||||
];
|
||||
$this->request($client, '/api/activities', 'POST', [], json_encode($data));
|
||||
$response = $client->getResponse();
|
||||
$this->assertApiCallValidationError($response, ['project'], true);
|
||||
}
|
||||
|
||||
public function testPatchAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
|
||||
@@ -101,6 +101,22 @@ class CustomerControllerTest extends APIControllerBaseTest
|
||||
$this->assertEquals('User cannot create customers', $json['message']);
|
||||
}
|
||||
|
||||
public function testPostActionWithInvalidData()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$data = [
|
||||
'name' => 'foo',
|
||||
'visible' => true,
|
||||
'country' => 'XYZ',
|
||||
'currency' => '---',
|
||||
'timezone' => 'foo/bar',
|
||||
'unexpected' => 'field',
|
||||
];
|
||||
$this->request($client, '/api/customers', 'POST', [], json_encode($data));
|
||||
$response = $client->getResponse();
|
||||
$this->assertApiCallValidationError($response, ['country', 'currency', 'timezone'], true);
|
||||
}
|
||||
|
||||
public function testPatchAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
|
||||
@@ -156,6 +156,20 @@ class ProjectControllerTest extends APIControllerBaseTest
|
||||
$this->assertEquals('User cannot create projects', $json['message']);
|
||||
}
|
||||
|
||||
public function testPostActionWithInvalidData()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$data = [
|
||||
'name' => 'foo',
|
||||
'customer' => 100,
|
||||
'xxxxx' => 'whoami',
|
||||
'visible' => true
|
||||
];
|
||||
$this->request($client, '/api/projects', 'POST', [], json_encode($data));
|
||||
$response = $client->getResponse();
|
||||
$this->assertApiCallValidationError($response, ['customer'], true);
|
||||
}
|
||||
|
||||
public function testPatchAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
|
||||
@@ -33,6 +33,8 @@ abstract class AbstractMetaEntityTest extends TestCase
|
||||
self::assertNull($sut->getEntity());
|
||||
self::assertIsArray($sut->getConstraints());
|
||||
self::assertEmpty($sut->getConstraints());
|
||||
self::assertIsArray($sut->getOptions());
|
||||
self::assertEmpty($sut->getOptions());
|
||||
self::assertFalse($sut->isVisible());
|
||||
self::assertFalse($sut->isRequired());
|
||||
}
|
||||
@@ -71,6 +73,9 @@ abstract class AbstractMetaEntityTest extends TestCase
|
||||
self::assertInstanceOf(MetaTableTypeInterface::class, $sut->setConstraints([new Length(['min' => 2])]));
|
||||
self::assertCount(1, $sut->getConstraints());
|
||||
|
||||
self::assertInstanceOf(MetaTableTypeInterface::class, $sut->setOptions(['foo' => 'bar']));
|
||||
self::assertCount(1, $sut->getOptions());
|
||||
|
||||
$entity = $this->getEntity();
|
||||
self::assertInstanceOf(MetaTableTypeInterface::class, $sut->setEntity($entity));
|
||||
self::assertSame($entity, $sut->getEntity());
|
||||
@@ -87,24 +92,29 @@ abstract class AbstractMetaEntityTest extends TestCase
|
||||
->setType('blub')
|
||||
->setEntity($entity1)
|
||||
->setConstraints([new NotNull()])
|
||||
->setOptions(['foo' => 'bar', 'bar' => 'foo'])
|
||||
;
|
||||
self::assertEquals('foo', $meta1->getName());
|
||||
self::assertEquals('bar', $meta1->getValue());
|
||||
self::assertEquals('blub', $meta1->getType());
|
||||
self::assertEquals('foo', $meta1->getLabel());
|
||||
self::assertFalse($meta1->isRequired());
|
||||
self::assertFalse($meta1->isVisible());
|
||||
self::assertSame($entity1, $meta1->getEntity());
|
||||
self::assertCount(1, $meta1->getConstraints());
|
||||
self::assertCount(2, $meta1->getOptions());
|
||||
|
||||
$meta2 = $this->getMetaEntity();
|
||||
$meta2
|
||||
->setName('foo2')
|
||||
->setLabel('TRALALA')
|
||||
->setValue('bar2')
|
||||
->setType('blub2')
|
||||
->setEntity($entity2)
|
||||
->setIsRequired(true)
|
||||
->setisVisible(true)
|
||||
->setConstraints([new NotBlank(), new Length(['min' => 1])])
|
||||
->setOptions(['foo1' => 'bar1'])
|
||||
;
|
||||
|
||||
self::assertInstanceOf(MetaTableTypeInterface::class, $meta1->merge($meta2));
|
||||
@@ -112,9 +122,12 @@ abstract class AbstractMetaEntityTest extends TestCase
|
||||
self::assertEquals('foo', $meta1->getName());
|
||||
self::assertEquals('bar', $meta1->getValue());
|
||||
self::assertEquals('blub2', $meta1->getType());
|
||||
self::assertEquals('TRALALA', $meta1->getLabel());
|
||||
self::assertTrue($meta1->isRequired());
|
||||
self::assertTrue($meta1->isVisible());
|
||||
self::assertSame($entity1, $meta1->getEntity());
|
||||
self::assertCount(2, $meta1->getConstraints());
|
||||
self::assertCount(1, $meta1->getOptions());
|
||||
self::assertEquals(['foo1' => 'bar1'], $meta1->getOptions());
|
||||
}
|
||||
}
|
||||
|
||||
39
tests/Event/ActivityMetaDisplayEventTest.php
Normal file
39
tests/Event/ActivityMetaDisplayEventTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Event;
|
||||
|
||||
use App\Entity\ActivityMeta;
|
||||
use App\Event\ActivityMetaDisplayEvent;
|
||||
use App\Event\MetaDisplayEventInterface;
|
||||
use App\Repository\Query\ActivityQuery;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Event\ActivityMetaDisplayEvent
|
||||
*/
|
||||
class ActivityMetaDisplayEventTest extends TestCase
|
||||
{
|
||||
public function testGetterAndSetter()
|
||||
{
|
||||
$query = new ActivityQuery();
|
||||
$sut = new ActivityMetaDisplayEvent($query, ActivityMetaDisplayEvent::EXPORT);
|
||||
|
||||
self::assertInstanceOf(MetaDisplayEventInterface::class, $sut);
|
||||
self::assertSame($sut->getQuery(), $query);
|
||||
self::assertIsArray($sut->getFields());
|
||||
self::assertEmpty($sut->getFields());
|
||||
self::assertEquals('export', $sut->getLocation());
|
||||
|
||||
$sut->addField(new ActivityMeta());
|
||||
$sut->addField(new ActivityMeta());
|
||||
|
||||
self::assertCount(2, $sut->getFields());
|
||||
}
|
||||
}
|
||||
39
tests/Event/CustomerMetaDisplayEventTest.php
Normal file
39
tests/Event/CustomerMetaDisplayEventTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Event;
|
||||
|
||||
use App\Entity\CustomerMeta;
|
||||
use App\Event\CustomerMetaDisplayEvent;
|
||||
use App\Event\MetaDisplayEventInterface;
|
||||
use App\Repository\Query\CustomerQuery;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Event\CustomerMetaDisplayEvent
|
||||
*/
|
||||
class CustomerMetaDisplayEventTest extends TestCase
|
||||
{
|
||||
public function testGetterAndSetter()
|
||||
{
|
||||
$query = new CustomerQuery();
|
||||
$sut = new CustomerMetaDisplayEvent($query, CustomerMetaDisplayEvent::EXPORT);
|
||||
|
||||
self::assertInstanceOf(MetaDisplayEventInterface::class, $sut);
|
||||
self::assertSame($sut->getQuery(), $query);
|
||||
self::assertIsArray($sut->getFields());
|
||||
self::assertEmpty($sut->getFields());
|
||||
self::assertEquals('export', $sut->getLocation());
|
||||
|
||||
$sut->addField(new CustomerMeta());
|
||||
$sut->addField(new CustomerMeta());
|
||||
|
||||
self::assertCount(2, $sut->getFields());
|
||||
}
|
||||
}
|
||||
39
tests/Event/ProjectMetaQueryDisplayTest.php
Normal file
39
tests/Event/ProjectMetaQueryDisplayTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Event;
|
||||
|
||||
use App\Entity\ProjectMeta;
|
||||
use App\Event\MetaDisplayEventInterface;
|
||||
use App\Event\ProjectMetaDisplayEvent;
|
||||
use App\Repository\Query\ProjectQuery;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Event\ProjectMetaDisplayEvent
|
||||
*/
|
||||
class ProjectMetaQueryDisplayTest extends TestCase
|
||||
{
|
||||
public function testGetterAndSetter()
|
||||
{
|
||||
$query = new ProjectQuery();
|
||||
$sut = new ProjectMetaDisplayEvent($query, ProjectMetaDisplayEvent::EXPORT);
|
||||
|
||||
self::assertInstanceOf(MetaDisplayEventInterface::class, $sut);
|
||||
self::assertSame($sut->getQuery(), $query);
|
||||
self::assertIsArray($sut->getFields());
|
||||
self::assertEmpty($sut->getFields());
|
||||
self::assertEquals('export', $sut->getLocation());
|
||||
|
||||
$sut->addField(new ProjectMeta());
|
||||
$sut->addField(new ProjectMeta());
|
||||
|
||||
self::assertCount(2, $sut->getFields());
|
||||
}
|
||||
}
|
||||
39
tests/Event/TimesheetMetaDisplayEventTest.php
Normal file
39
tests/Event/TimesheetMetaDisplayEventTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Event;
|
||||
|
||||
use App\Entity\TimesheetMeta;
|
||||
use App\Event\MetaDisplayEventInterface;
|
||||
use App\Event\TimesheetMetaDisplayEvent;
|
||||
use App\Repository\Query\TimesheetQuery;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Event\TimesheetMetaDisplayEvent
|
||||
*/
|
||||
class TimesheetMetaDisplayEventTest extends TestCase
|
||||
{
|
||||
public function testGetterAndSetter()
|
||||
{
|
||||
$query = new TimesheetQuery();
|
||||
$sut = new TimesheetMetaDisplayEvent($query, TimesheetMetaDisplayEvent::EXPORT);
|
||||
|
||||
self::assertInstanceOf(MetaDisplayEventInterface::class, $sut);
|
||||
self::assertSame($sut->getQuery(), $query);
|
||||
self::assertIsArray($sut->getFields());
|
||||
self::assertEmpty($sut->getFields());
|
||||
self::assertEquals('export', $sut->getLocation());
|
||||
|
||||
$sut->addField(new TimesheetMeta());
|
||||
$sut->addField(new TimesheetMeta());
|
||||
|
||||
self::assertCount(2, $sut->getFields());
|
||||
}
|
||||
}
|
||||
@@ -11,17 +11,28 @@ namespace App\Tests\Export\Renderer;
|
||||
|
||||
use App\Configuration\LanguageFormattings;
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\ActivityMeta;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\CustomerMeta;
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\ProjectMeta;
|
||||
use App\Entity\Tag;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\TimesheetMeta;
|
||||
use App\Entity\User;
|
||||
use App\Event\ActivityMetaDisplayEvent;
|
||||
use App\Event\CustomerMetaDisplayEvent;
|
||||
use App\Event\ProjectMetaDisplayEvent;
|
||||
use App\Event\TimesheetMetaDisplayEvent;
|
||||
use App\Export\RendererInterface;
|
||||
use App\Repository\Query\TimesheetQuery;
|
||||
use App\Twig\DateExtensions;
|
||||
use App\Utils\LocaleSettings;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
@@ -52,7 +63,10 @@ abstract class AbstractRendererTest extends KernelTestCase
|
||||
$translator = $this->getMockBuilder(TranslatorInterface::class)->getMock();
|
||||
$dateExtension = new DateExtensions($localeSettings);
|
||||
|
||||
return new $classname($translator, $dateExtension);
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->addSubscriber(new MetaFieldColumnSubscriber());
|
||||
|
||||
return new $classname($translator, $dateExtension, $dispatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,14 +77,18 @@ abstract class AbstractRendererTest extends KernelTestCase
|
||||
{
|
||||
$customer = new Customer();
|
||||
$customer->setName('Customer Name');
|
||||
$customer->setMetaField((new CustomerMeta())->setName('customer-foo')->setValue('customer-bar')->setIsVisible(true));
|
||||
|
||||
$project = new Project();
|
||||
$project->setName('project name');
|
||||
$project->setCustomer($customer);
|
||||
$project->setMetaField((new ProjectMeta())->setName('project-bar')->setValue('project-bar')->setIsVisible(true));
|
||||
$project->setMetaField((new ProjectMeta())->setName('project-foo2')->setValue('project-foo2')->setIsVisible(true));
|
||||
|
||||
$activity = new Activity();
|
||||
$activity->setName('activity description');
|
||||
$activity->setProject($project);
|
||||
$activity->setMetaField((new ActivityMeta())->setName('activity-foo')->setValue('activity-bar')->setIsVisible(true));
|
||||
|
||||
$userMethods = ['getId', 'getPreferenceValue', 'getUsername'];
|
||||
$user1 = $this->getMockBuilder(User::class)->setMethods($userMethods)->disableOriginalConstructor()->getMock();
|
||||
@@ -153,3 +171,47 @@ abstract class AbstractRendererTest extends KernelTestCase
|
||||
return $renderer->render($entries, $query);
|
||||
}
|
||||
}
|
||||
|
||||
class MetaFieldColumnSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
TimesheetMetaDisplayEvent::class => ['loadTimesheetField', 200],
|
||||
CustomerMetaDisplayEvent::class => ['loadCustomerField', 200],
|
||||
ProjectMetaDisplayEvent::class => ['loadProjectField', 200],
|
||||
ActivityMetaDisplayEvent::class => ['loadActivityField', 200],
|
||||
];
|
||||
}
|
||||
|
||||
public function loadTimesheetField(TimesheetMetaDisplayEvent $event)
|
||||
{
|
||||
$event->addField($this->prepareEntity(new TimesheetMeta(), 'foo'));
|
||||
$event->addField($this->prepareEntity(new TimesheetMeta(), 'foo2'));
|
||||
}
|
||||
|
||||
public function loadCustomerField(CustomerMetaDisplayEvent $event)
|
||||
{
|
||||
$event->addField($this->prepareEntity(new CustomerMeta(), 'customer-foo'));
|
||||
}
|
||||
|
||||
public function loadProjectField(ProjectMetaDisplayEvent $event)
|
||||
{
|
||||
$event->addField($this->prepareEntity(new ProjectMeta(), 'project-foo'));
|
||||
$event->addField($this->prepareEntity(new ProjectMeta(), 'project-foo2')->setIsVisible(false));
|
||||
}
|
||||
|
||||
public function loadActivityField(ActivityMetaDisplayEvent $event)
|
||||
{
|
||||
$event->addField($this->prepareEntity(new ActivityMeta(), 'activity-foo'));
|
||||
}
|
||||
|
||||
private function prepareEntity(MetaTableTypeInterface $meta, string $name)
|
||||
{
|
||||
return $meta
|
||||
->setLabel('Working place')
|
||||
->setName($name)
|
||||
->setType(TextType::class)
|
||||
->setIsVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,12 +92,15 @@ class CsvRendererTest extends AbstractRendererTest
|
||||
13 => ' EUR 84.00 ',
|
||||
14 => 'meta-bar',
|
||||
15 => 'meta-bar2',
|
||||
16 => 'customer-bar',
|
||||
17 => '',
|
||||
18 => 'project-foo2',
|
||||
19 => 'activity-bar',
|
||||
];
|
||||
|
||||
self::assertEquals(7, count($all));
|
||||
self::assertEquals($expected, $all[5]);
|
||||
self::assertEquals(count($expected), count($all[0]));
|
||||
self::assertEquals('foo', $all[4][11]);
|
||||
|
||||
self::assertEquals($expected, $all[5]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace App\Tests\Export\Renderer;
|
||||
|
||||
use App\Export\Renderer\HtmlRenderer;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Twig\Environment;
|
||||
|
||||
@@ -23,7 +24,8 @@ class HtmlRendererTest extends AbstractRendererTest
|
||||
public function testConfiguration()
|
||||
{
|
||||
$sut = new HtmlRenderer(
|
||||
$this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock()
|
||||
$this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock(),
|
||||
new EventDispatcher()
|
||||
);
|
||||
|
||||
$this->assertEquals('html', $sut->getId());
|
||||
@@ -41,7 +43,7 @@ class HtmlRendererTest extends AbstractRendererTest
|
||||
$request->setLocale('en');
|
||||
$stack->push($request);
|
||||
|
||||
$sut = new HtmlRenderer($twig);
|
||||
$sut = new HtmlRenderer($twig, new EventDispatcher());
|
||||
|
||||
$response = $this->render($sut);
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace App\Tests\Export;
|
||||
use App\Export\Renderer\HtmlRenderer;
|
||||
use App\Export\ServiceExport;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
@@ -36,7 +37,8 @@ class ServiceExportTest extends TestCase
|
||||
$sut = new ServiceExport([]);
|
||||
|
||||
$sut->addRenderer(new HtmlRenderer(
|
||||
$this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock()
|
||||
$this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock(),
|
||||
new EventDispatcher()
|
||||
));
|
||||
|
||||
$this->assertEquals(1, count($sut->getRenderer()));
|
||||
@@ -45,7 +47,8 @@ class ServiceExportTest extends TestCase
|
||||
public function testAddViaConstruct()
|
||||
{
|
||||
$renderer = [new HtmlRenderer(
|
||||
$this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock()
|
||||
$this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock(),
|
||||
new EventDispatcher()
|
||||
)];
|
||||
$sut = new ServiceExport($renderer);
|
||||
|
||||
|
||||
29
tests/Repository/Loader/DefaultLoaderTest.php
Normal file
29
tests/Repository/Loader/DefaultLoaderTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Repository\Loader;
|
||||
|
||||
use App\Repository\Loader\DefaultLoader;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Repository\Loader\DefaultLoader
|
||||
*/
|
||||
class DefaultLoaderTest extends TestCase
|
||||
{
|
||||
public function testLoadResults()
|
||||
{
|
||||
$sut = new DefaultLoader();
|
||||
|
||||
$input = [];
|
||||
$sut->loadResults($input);
|
||||
|
||||
self::assertEquals([], $input);
|
||||
}
|
||||
}
|
||||
30
tests/Repository/Paginator/QueryBuilderPaginatorTest.php
Normal file
30
tests/Repository/Paginator/QueryBuilderPaginatorTest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Repository\Paginator;
|
||||
|
||||
use App\Repository\Paginator\QueryBuilderPaginator;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Repository\Paginator\QueryBuilderPaginator
|
||||
*/
|
||||
class QueryBuilderPaginatorTest extends TestCase
|
||||
{
|
||||
public function testPaginator()
|
||||
{
|
||||
$em = $this->getMockBuilder(EntityManager::class)->disableOriginalConstructor()->getMock();
|
||||
$qb = new QueryBuilder($em);
|
||||
$sut = new QueryBuilderPaginator($qb, 10);
|
||||
|
||||
self::assertEquals(10, $sut->getNbResults());
|
||||
}
|
||||
}
|
||||
@@ -69,11 +69,11 @@ class DateExtensionsTest extends TestCase
|
||||
|
||||
/**
|
||||
* @param string $locale
|
||||
* @param \DateTime $date
|
||||
* @param \DateTime|string $date
|
||||
* @param string $result
|
||||
* @dataProvider getDateShortData
|
||||
*/
|
||||
public function testDateShort($locale, \DateTime $date, $result)
|
||||
public function testDateShort($locale, $date, $result)
|
||||
{
|
||||
$sut = $this->getSut($locale, [
|
||||
'de' => ['date' => 'd.m.Y'],
|
||||
@@ -90,16 +90,17 @@ class DateExtensionsTest extends TestCase
|
||||
['en', new \DateTime('2016-06-23'), '2016-06-23'],
|
||||
['de', new \DateTime('1980-12-14'), '14.12.1980'],
|
||||
['ru', new \DateTime('1980-12-14'), '14.12.1980'],
|
||||
['ru', '1980-12-14', '14.12.1980'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $locale
|
||||
* @param \DateTime $date
|
||||
* @param \DateTime|string $date
|
||||
* @param string $result
|
||||
* @dataProvider getDateTimeData
|
||||
*/
|
||||
public function testDateTime($locale, \DateTime $date, $result)
|
||||
public function testDateTime($locale, $date, $result)
|
||||
{
|
||||
$sut = $this->getSut($locale, [
|
||||
'de' => ['date_time' => 'd.m.Y H:i:s'],
|
||||
@@ -113,6 +114,7 @@ class DateExtensionsTest extends TestCase
|
||||
return [
|
||||
['en', new \DateTime('7 January 2010'), '2010-01-07 12:01 AM'],
|
||||
['de', (new \DateTime('1980-12-14'))->setTime(13, 27, 55), '14.12.1980 13:27:55'],
|
||||
['de', '1980-12-14 13:27:55', '14.12.1980 13:27:55'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -141,6 +143,7 @@ class DateExtensionsTest extends TestCase
|
||||
$date = new \DateTime('7 January 2010 17:43:21', new \DateTimeZone('Europe/Berlin'));
|
||||
$sut = $this->getSut('en', []);
|
||||
$this->assertEquals('2010-01-07T17:43:21+01:00', $sut->dateFormat($date, 'c'));
|
||||
$this->assertStringStartsWith('2010-01-07T17:43:21', $sut->dateFormat('7 January 2010 17:43:21', 'c'));
|
||||
}
|
||||
|
||||
public function testTime()
|
||||
@@ -150,6 +153,7 @@ class DateExtensionsTest extends TestCase
|
||||
|
||||
$sut = $this->getSut('en', ['en' => ['time' => 'H:i']]);
|
||||
$this->assertEquals('17:53', $sut->time($time));
|
||||
$this->assertEquals('17:53', $sut->time('2016-06-23 17:53'));
|
||||
}
|
||||
|
||||
public function testHour24()
|
||||
@@ -176,5 +180,6 @@ class DateExtensionsTest extends TestCase
|
||||
$dateTime->setTime(12, 29, 47);
|
||||
|
||||
$this->assertEquals('2019-08-17 12:29:47', $sut->dateTimeFull($dateTime));
|
||||
$this->assertEquals('2019-08-17 12:29:47', $sut->dateTimeFull('2019-08-17 12:29:47'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class ExtensionsTest extends TestCase
|
||||
|
||||
public function testGetFilters()
|
||||
{
|
||||
$filters = ['duration', 'duration_decimal', 'money', 'currency', 'country', 'docu_link'];
|
||||
$filters = ['duration', 'duration_decimal', 'money', 'currency', 'country', 'language', 'docu_link'];
|
||||
$sut = $this->getSut($this->localeDe);
|
||||
$twigFilters = $sut->getFilters();
|
||||
$this->assertCount(count($filters), $twigFilters);
|
||||
@@ -117,6 +117,20 @@ class ExtensionsTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testLanguage()
|
||||
{
|
||||
$languages = [
|
||||
'de' => 'German',
|
||||
'ru' => 'Russian',
|
||||
'es' => 'Spanish',
|
||||
];
|
||||
|
||||
$sut = $this->getSut($this->localeEn);
|
||||
foreach ($languages as $locale => $name) {
|
||||
$this->assertEquals($name, $sut->language($locale));
|
||||
}
|
||||
}
|
||||
|
||||
public function testMoneyNull()
|
||||
{
|
||||
$sut = $this->getSut($this->localeEn, 'en');
|
||||
|
||||
Reference in New Issue
Block a user