Display meta-fields in datatables (#1116)
This commit is contained in:
@@ -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(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user