added event to extend detail pages (#3209)
This commit is contained in:
@@ -17,6 +17,7 @@ use App\Entity\ActivityRate;
|
|||||||
use App\Entity\MetaTableTypeInterface;
|
use App\Entity\MetaTableTypeInterface;
|
||||||
use App\Entity\Project;
|
use App\Entity\Project;
|
||||||
use App\Entity\Team;
|
use App\Entity\Team;
|
||||||
|
use App\Event\ActivityDetailControllerEvent;
|
||||||
use App\Event\ActivityMetaDefinitionEvent;
|
use App\Event\ActivityMetaDefinitionEvent;
|
||||||
use App\Event\ActivityMetaDisplayEvent;
|
use App\Event\ActivityMetaDisplayEvent;
|
||||||
use App\Export\Spreadsheet\EntityWithMetaFieldsExporter;
|
use App\Export\Spreadsheet\EntityWithMetaFieldsExporter;
|
||||||
@@ -140,6 +141,11 @@ final class ActivityController extends AbstractController
|
|||||||
$teams = $activity->getTeams();
|
$teams = $activity->getTeams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// additional boxes by plugins
|
||||||
|
$event = new ActivityDetailControllerEvent($activity);
|
||||||
|
$this->dispatcher->dispatch($event);
|
||||||
|
$boxes = $event->getController();
|
||||||
|
|
||||||
return $this->render('activity/details.html.twig', [
|
return $this->render('activity/details.html.twig', [
|
||||||
'activity' => $activity,
|
'activity' => $activity,
|
||||||
'stats' => $stats,
|
'stats' => $stats,
|
||||||
@@ -147,6 +153,7 @@ final class ActivityController extends AbstractController
|
|||||||
'team' => $defaultTeam,
|
'team' => $defaultTeam,
|
||||||
'teams' => $teams,
|
'teams' => $teams,
|
||||||
'now' => $now,
|
'now' => $now,
|
||||||
|
'boxes' => $boxes
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ use App\Entity\CustomerComment;
|
|||||||
use App\Entity\CustomerRate;
|
use App\Entity\CustomerRate;
|
||||||
use App\Entity\MetaTableTypeInterface;
|
use App\Entity\MetaTableTypeInterface;
|
||||||
use App\Entity\Team;
|
use App\Entity\Team;
|
||||||
|
use App\Event\CustomerDetailControllerEvent;
|
||||||
use App\Event\CustomerMetaDefinitionEvent;
|
use App\Event\CustomerMetaDefinitionEvent;
|
||||||
use App\Event\CustomerMetaDisplayEvent;
|
use App\Event\CustomerMetaDisplayEvent;
|
||||||
use App\Export\Spreadsheet\EntityWithMetaFieldsExporter;
|
use App\Export\Spreadsheet\EntityWithMetaFieldsExporter;
|
||||||
@@ -300,7 +301,6 @@ final class CustomerController extends AbstractController
|
|||||||
$attachments = [];
|
$attachments = [];
|
||||||
$comments = null;
|
$comments = null;
|
||||||
$teams = null;
|
$teams = null;
|
||||||
$projects = null;
|
|
||||||
$rates = [];
|
$rates = [];
|
||||||
$now = $this->getDateTimeFactory()->createDateTime();
|
$now = $this->getDateTimeFactory()->createDateTime();
|
||||||
|
|
||||||
@@ -331,6 +331,11 @@ final class CustomerController extends AbstractController
|
|||||||
$teams = $customer->getTeams();
|
$teams = $customer->getTeams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// additional boxes by plugins
|
||||||
|
$event = new CustomerDetailControllerEvent($customer);
|
||||||
|
$this->dispatcher->dispatch($event);
|
||||||
|
$boxes = $event->getController();
|
||||||
|
|
||||||
return $this->render('customer/details.html.twig', [
|
return $this->render('customer/details.html.twig', [
|
||||||
'customer' => $customer,
|
'customer' => $customer,
|
||||||
'comments' => $comments,
|
'comments' => $comments,
|
||||||
@@ -342,6 +347,7 @@ final class CustomerController extends AbstractController
|
|||||||
'customer_now' => new \DateTime('now', $timezone),
|
'customer_now' => new \DateTime('now', $timezone),
|
||||||
'rates' => $rates,
|
'rates' => $rates,
|
||||||
'now' => $now,
|
'now' => $now,
|
||||||
|
'boxes' => $boxes
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ use App\Entity\ProjectComment;
|
|||||||
use App\Entity\ProjectRate;
|
use App\Entity\ProjectRate;
|
||||||
use App\Entity\Rate;
|
use App\Entity\Rate;
|
||||||
use App\Entity\Team;
|
use App\Entity\Team;
|
||||||
|
use App\Event\ProjectDetailControllerEvent;
|
||||||
use App\Event\ProjectMetaDefinitionEvent;
|
use App\Event\ProjectMetaDefinitionEvent;
|
||||||
use App\Event\ProjectMetaDisplayEvent;
|
use App\Event\ProjectMetaDisplayEvent;
|
||||||
use App\Export\Spreadsheet\EntityWithMetaFieldsExporter;
|
use App\Export\Spreadsheet\EntityWithMetaFieldsExporter;
|
||||||
@@ -348,6 +349,11 @@ final class ProjectController extends AbstractController
|
|||||||
$teams = $project->getTeams();
|
$teams = $project->getTeams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// additional boxes by plugins
|
||||||
|
$event = new ProjectDetailControllerEvent($project);
|
||||||
|
$this->dispatcher->dispatch($event);
|
||||||
|
$boxes = $event->getController();
|
||||||
|
|
||||||
return $this->render('project/details.html.twig', [
|
return $this->render('project/details.html.twig', [
|
||||||
'project' => $project,
|
'project' => $project,
|
||||||
'comments' => $comments,
|
'comments' => $comments,
|
||||||
@@ -358,6 +364,7 @@ final class ProjectController extends AbstractController
|
|||||||
'teams' => $teams,
|
'teams' => $teams,
|
||||||
'rates' => $rates,
|
'rates' => $rates,
|
||||||
'now' => $now,
|
'now' => $now,
|
||||||
|
'boxes' => $boxes
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
30
src/Event/ActivityDetailControllerEvent.php
Normal file
30
src/Event/ActivityDetailControllerEvent.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\Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggered for activity detail pages, to add additional content boxes.
|
||||||
|
*
|
||||||
|
* @see https://symfony.com/doc/5.4/templates.html#embedding-controllers
|
||||||
|
*/
|
||||||
|
final class ActivityDetailControllerEvent extends AbstractActivityEvent
|
||||||
|
{
|
||||||
|
private $controller = [];
|
||||||
|
|
||||||
|
public function addController(string $controller): void
|
||||||
|
{
|
||||||
|
$this->controller[] = $controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getController(): array
|
||||||
|
{
|
||||||
|
return $this->controller;
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/Event/CustomerDetailControllerEvent.php
Normal file
30
src/Event/CustomerDetailControllerEvent.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\Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggered for customer detail pages, to add additional content boxes.
|
||||||
|
*
|
||||||
|
* @see https://symfony.com/doc/5.4/templates.html#embedding-controllers
|
||||||
|
*/
|
||||||
|
final class CustomerDetailControllerEvent extends AbstractCustomerEvent
|
||||||
|
{
|
||||||
|
private $controller = [];
|
||||||
|
|
||||||
|
public function addController(string $controller): void
|
||||||
|
{
|
||||||
|
$this->controller[] = $controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getController(): array
|
||||||
|
{
|
||||||
|
return $this->controller;
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/Event/ProjectDetailControllerEvent.php
Normal file
30
src/Event/ProjectDetailControllerEvent.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\Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggered for project detail pages, to add additional content boxes.
|
||||||
|
*
|
||||||
|
* @see https://symfony.com/doc/5.4/templates.html#embedding-controllers
|
||||||
|
*/
|
||||||
|
final class ProjectDetailControllerEvent extends AbstractProjectEvent
|
||||||
|
{
|
||||||
|
private $controller = [];
|
||||||
|
|
||||||
|
public function addController(string $controller): void
|
||||||
|
{
|
||||||
|
$this->controller[] = $controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getController(): array
|
||||||
|
{
|
||||||
|
return $this->controller;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -93,6 +93,10 @@
|
|||||||
{{ include('embeds/budgets.html.twig', {'entity': activity, 'stats': stats, 'currency': currency}) }}
|
{{ include('embeds/budgets.html.twig', {'entity': activity, 'stats': stats, 'currency': currency}) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% for controller in boxes %}
|
||||||
|
{{ render(controller(controller, {'activity': activity, 'page': 1})) }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
{% if can_edit %}
|
{% if can_edit %}
|
||||||
{{ include('embeds/rates-table.html.twig', {'id': 'activity_rates_box', 'entity': activity, 'create_url': path('admin_activity_rate_add', {'id': activity.id}), 'delete_route': 'delete_activity_rate', 'currency': currency}) }}
|
{{ include('embeds/rates-table.html.twig', {'id': 'activity_rates_box', 'entity': activity, 'create_url': path('admin_activity_rate_add', {'id': activity.id}), 'delete_route': 'delete_activity_rate', 'currency': currency}) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -132,6 +132,10 @@
|
|||||||
{{ include('embeds/budgets.html.twig', {'entity': customer, 'stats': stats, 'currency': customer.currency}) }}
|
{{ include('embeds/budgets.html.twig', {'entity': customer, 'stats': stats, 'currency': customer.currency}) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% for controller in boxes %}
|
||||||
|
{{ render(controller(controller, {'customer': customer, 'page': 1})) }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
{% if can_edit %}
|
{% if can_edit %}
|
||||||
{{ include('embeds/rates-table.html.twig', {'id': 'customer_rates_box', 'entity': customer, 'create_url': path('admin_customer_rate_add', {'id': customer.id}), 'delete_route': 'delete_customer_rate', 'currency': customer.currency}) }}
|
{{ include('embeds/rates-table.html.twig', {'id': 'customer_rates_box', 'entity': customer, 'create_url': path('admin_customer_rate_add', {'id': customer.id}), 'delete_route': 'delete_customer_rate', 'currency': customer.currency}) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -134,6 +134,10 @@
|
|||||||
{{ include('embeds/budgets.html.twig', {'entity': project, 'stats': stats, 'currency': project.customer.currency}) }}
|
{{ include('embeds/budgets.html.twig', {'entity': project, 'stats': stats, 'currency': project.customer.currency}) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% for controller in boxes %}
|
||||||
|
{{ render(controller(controller, {'project': project, 'page': 1})) }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
{% if can_edit %}
|
{% if can_edit %}
|
||||||
{{ include('embeds/rates-table.html.twig', {'id': 'project_rates_box', 'entity': project, 'create_url': path('admin_project_rate_add', {'id': project.id}), 'delete_route': 'delete_project_rate', 'currency': project.customer.currency}) }}
|
{{ include('embeds/rates-table.html.twig', {'id': 'project_rates_box', 'entity': project, 'create_url': path('admin_project_rate_add', {'id': project.id}), 'delete_route': 'delete_project_rate', 'currency': project.customer.currency}) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
34
tests/Event/ActivityDetailControllerEventTest.php
Normal file
34
tests/Event/ActivityDetailControllerEventTest.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?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\Activity;
|
||||||
|
use App\Event\AbstractActivityEvent;
|
||||||
|
use App\Event\ActivityDetailControllerEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \App\Event\AbstractActivityEvent
|
||||||
|
* @covers \App\Event\ActivityDetailControllerEvent
|
||||||
|
*/
|
||||||
|
class ActivityDetailControllerEventTest extends AbstractActivityEventTest
|
||||||
|
{
|
||||||
|
protected function createActivityEvent(Activity $activity): AbstractActivityEvent
|
||||||
|
{
|
||||||
|
return new ActivityDetailControllerEvent($activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testController(): void
|
||||||
|
{
|
||||||
|
/** @var ActivityDetailControllerEvent $event */
|
||||||
|
$event = $this->createActivityEvent(new Activity());
|
||||||
|
$event->addController('Foo\\Bar::helloWorld');
|
||||||
|
$this->assertEquals(['Foo\\Bar::helloWorld'], $event->getController());
|
||||||
|
}
|
||||||
|
}
|
||||||
34
tests/Event/CustomerDetailControllerEventTest.php
Normal file
34
tests/Event/CustomerDetailControllerEventTest.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?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\Customer;
|
||||||
|
use App\Event\AbstractCustomerEvent;
|
||||||
|
use App\Event\CustomerDetailControllerEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \App\Event\AbstractCustomerEvent
|
||||||
|
* @covers \App\Event\CustomerDetailControllerEvent
|
||||||
|
*/
|
||||||
|
class CustomerDetailControllerEventTest extends AbstractCustomerEventTest
|
||||||
|
{
|
||||||
|
protected function createCustomerEvent(Customer $customer): AbstractCustomerEvent
|
||||||
|
{
|
||||||
|
return new CustomerDetailControllerEvent($customer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testController(): void
|
||||||
|
{
|
||||||
|
/** @var CustomerDetailControllerEvent $event */
|
||||||
|
$event = $this->createCustomerEvent(new Customer());
|
||||||
|
$event->addController('Foo\\Bar::helloWorld');
|
||||||
|
$this->assertEquals(['Foo\\Bar::helloWorld'], $event->getController());
|
||||||
|
}
|
||||||
|
}
|
||||||
34
tests/Event/ProjectDetailControllerEventTest.php
Normal file
34
tests/Event/ProjectDetailControllerEventTest.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?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\Project;
|
||||||
|
use App\Event\AbstractProjectEvent;
|
||||||
|
use App\Event\ProjectDetailControllerEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \App\Event\AbstractProjectEvent
|
||||||
|
* @covers \App\Event\ProjectDetailControllerEvent
|
||||||
|
*/
|
||||||
|
class ProjectDetailControllerEventTest extends AbstractProjectEventTest
|
||||||
|
{
|
||||||
|
protected function createProjectEvent(Project $project): AbstractProjectEvent
|
||||||
|
{
|
||||||
|
return new ProjectDetailControllerEvent($project);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testController(): void
|
||||||
|
{
|
||||||
|
/** @var ProjectDetailControllerEvent $event */
|
||||||
|
$event = $this->createProjectEvent(new Project());
|
||||||
|
$event->addController('Foo\\Bar::helloWorld');
|
||||||
|
$this->assertEquals(['Foo\\Bar::helloWorld'], $event->getController());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user