added event to extend detail pages (#3209)

This commit is contained in:
Kevin Papst
2022-03-19 23:54:40 +01:00
committed by GitHub
parent a8ac6b2eda
commit 4b069edd33
12 changed files with 225 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ use App\Entity\ActivityRate;
use App\Entity\MetaTableTypeInterface;
use App\Entity\Project;
use App\Entity\Team;
use App\Event\ActivityDetailControllerEvent;
use App\Event\ActivityMetaDefinitionEvent;
use App\Event\ActivityMetaDisplayEvent;
use App\Export\Spreadsheet\EntityWithMetaFieldsExporter;
@@ -140,6 +141,11 @@ final class ActivityController extends AbstractController
$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', [
'activity' => $activity,
'stats' => $stats,
@@ -147,6 +153,7 @@ final class ActivityController extends AbstractController
'team' => $defaultTeam,
'teams' => $teams,
'now' => $now,
'boxes' => $boxes
]);
}

View File

@@ -16,6 +16,7 @@ use App\Entity\CustomerComment;
use App\Entity\CustomerRate;
use App\Entity\MetaTableTypeInterface;
use App\Entity\Team;
use App\Event\CustomerDetailControllerEvent;
use App\Event\CustomerMetaDefinitionEvent;
use App\Event\CustomerMetaDisplayEvent;
use App\Export\Spreadsheet\EntityWithMetaFieldsExporter;
@@ -300,7 +301,6 @@ final class CustomerController extends AbstractController
$attachments = [];
$comments = null;
$teams = null;
$projects = null;
$rates = [];
$now = $this->getDateTimeFactory()->createDateTime();
@@ -331,6 +331,11 @@ final class CustomerController extends AbstractController
$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', [
'customer' => $customer,
'comments' => $comments,
@@ -342,6 +347,7 @@ final class CustomerController extends AbstractController
'customer_now' => new \DateTime('now', $timezone),
'rates' => $rates,
'now' => $now,
'boxes' => $boxes
]);
}

View File

@@ -17,6 +17,7 @@ use App\Entity\ProjectComment;
use App\Entity\ProjectRate;
use App\Entity\Rate;
use App\Entity\Team;
use App\Event\ProjectDetailControllerEvent;
use App\Event\ProjectMetaDefinitionEvent;
use App\Event\ProjectMetaDisplayEvent;
use App\Export\Spreadsheet\EntityWithMetaFieldsExporter;
@@ -348,6 +349,11 @@ final class ProjectController extends AbstractController
$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', [
'project' => $project,
'comments' => $comments,
@@ -358,6 +364,7 @@ final class ProjectController extends AbstractController
'teams' => $teams,
'rates' => $rates,
'now' => $now,
'boxes' => $boxes
]);
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View File

@@ -93,6 +93,10 @@
{{ include('embeds/budgets.html.twig', {'entity': activity, 'stats': stats, 'currency': currency}) }}
{% endif %}
{% for controller in boxes %}
{{ render(controller(controller, {'activity': activity, 'page': 1})) }}
{% endfor %}
{% 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}) }}
{% endif %}

View File

@@ -132,6 +132,10 @@
{{ include('embeds/budgets.html.twig', {'entity': customer, 'stats': stats, 'currency': customer.currency}) }}
{% endif %}
{% for controller in boxes %}
{{ render(controller(controller, {'customer': customer, 'page': 1})) }}
{% endfor %}
{% 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}) }}
{% endif %}

View File

@@ -134,6 +134,10 @@
{{ include('embeds/budgets.html.twig', {'entity': project, 'stats': stats, 'currency': project.customer.currency}) }}
{% endif %}
{% for controller in boxes %}
{{ render(controller(controller, {'project': project, 'page': 1})) }}
{% endfor %}
{% 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}) }}
{% endif %}

View 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());
}
}

View 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());
}
}

View 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());
}
}