feat(04-01): add getUserProjects service, widget data, and Twig data attributes
This commit is contained in:
parent
c8a5f0da08
commit
3df754ea62
3 changed files with 32 additions and 2 deletions
|
|
@ -6,6 +6,8 @@
|
||||||
<link rel="stylesheet" href="{{ asset('bundles/kimaiheatmap/heatmap.css') }}">
|
<link rel="stylesheet" href="{{ asset('bundles/kimaiheatmap/heatmap.css') }}">
|
||||||
<div id="heatmap-container"
|
<div id="heatmap-container"
|
||||||
data-url="{{ path('heatmap_data') }}"
|
data-url="{{ path('heatmap_data') }}"
|
||||||
|
data-projects="{{ data.projects|json_encode }}"
|
||||||
|
data-timesheet-url="{{ path('timesheet') }}"
|
||||||
style="min-height: 150px; overflow-x: auto;">
|
style="min-height: 150px; overflow-x: auto;">
|
||||||
</div>
|
</div>
|
||||||
<script src="{{ asset('bundles/kimaiheatmap/heatmap.js') }}"></script>
|
<script src="{{ asset('bundles/kimaiheatmap/heatmap.js') }}"></script>
|
||||||
|
|
|
||||||
|
|
@ -47,4 +47,23 @@ class HeatmapService
|
||||||
];
|
];
|
||||||
}, $results);
|
}, $results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, array{id: int, name: string}>
|
||||||
|
*/
|
||||||
|
public function getUserProjects(User $user): array
|
||||||
|
{
|
||||||
|
$qb = $this->repository->createQueryBuilder('t');
|
||||||
|
$qb->select('DISTINCT IDENTITY(t.project) as projectId, p.name')
|
||||||
|
->join('t.project', 'p')
|
||||||
|
->andWhere($qb->expr()->eq('t.user', ':user'))
|
||||||
|
->andWhere($qb->expr()->isNotNull('t.end'))
|
||||||
|
->setParameter('user', $user)
|
||||||
|
->orderBy('p.name', 'ASC');
|
||||||
|
|
||||||
|
return array_map(fn(array $row) => [
|
||||||
|
'id' => (int) $row['projectId'],
|
||||||
|
'name' => $row['name'],
|
||||||
|
], $qb->getQuery()->getResult());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,14 @@ namespace KimaiPlugin\KimaiHeatmapBundle\Widget;
|
||||||
|
|
||||||
use App\Widget\Type\AbstractWidget;
|
use App\Widget\Type\AbstractWidget;
|
||||||
use App\Widget\WidgetInterface;
|
use App\Widget\WidgetInterface;
|
||||||
|
use KimaiPlugin\KimaiHeatmapBundle\Service\HeatmapService;
|
||||||
|
|
||||||
final class HeatmapWidget extends AbstractWidget
|
class HeatmapWidget extends AbstractWidget
|
||||||
{
|
{
|
||||||
|
public function __construct(private readonly HeatmapService $service)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public function getId(): string
|
public function getId(): string
|
||||||
{
|
{
|
||||||
return 'HeatmapWidget';
|
return 'HeatmapWidget';
|
||||||
|
|
@ -34,7 +39,11 @@ final class HeatmapWidget extends AbstractWidget
|
||||||
|
|
||||||
public function getData(array $options = []): mixed
|
public function getData(array $options = []): mixed
|
||||||
{
|
{
|
||||||
return null;
|
$user = $this->getUser();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'projects' => $this->service->getUserProjects($user),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTemplateName(): string
|
public function getTemplateName(): string
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue