fix: correctly assign items to timeline

This commit is contained in:
Björn Fromme
2025-03-25 15:47:08 +01:00
parent ecc059cefc
commit da18856cc2
4 changed files with 63 additions and 50 deletions
@@ -36,7 +36,7 @@ class TimelineFilterController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$this->filterHandler->handleRequest($form); $this->filterHandler->handleRequest($form);
$returnUrl = $this->getReturnUrl($request, 'app_administrative_assignment_timeline'); $returnUrl = $this->getReturnUrl($request, 'app_administrative_timeline');
return new HxRedirectResponse($returnUrl); return new HxRedirectResponse($returnUrl);
} }
@@ -51,7 +51,7 @@ class TimelineFilterController extends AbstractController
public function reset(Request $request): Response public function reset(Request $request): Response
{ {
$this->filterHandler->resetFilterSettings(); $this->filterHandler->resetFilterSettings();
$returnUrl = $this->getReturnUrl($request, 'app_administrative_assignment_timeline'); $returnUrl = $this->getReturnUrl($request, 'app_administrative_timeline');
return $this->redirect($returnUrl); return $this->redirect($returnUrl);
} }
+14
View File
@@ -10,6 +10,7 @@ class TimelineItem
public const TYPE_ASSIGNMENT = 'assignment'; public const TYPE_ASSIGNMENT = 'assignment';
public const TYPE_DISPOSITION = 'disposition'; public const TYPE_DISPOSITION = 'disposition';
private ?int $dispositionId = null;
private ?\DateTimeImmutable $dateFrom = null; private ?\DateTimeImmutable $dateFrom = null;
private ?\DateTimeImmutable $dateTo = null; private ?\DateTimeImmutable $dateTo = null;
private ?string $status = null; private ?string $status = null;
@@ -44,6 +45,7 @@ class TimelineItem
$dateTo = $assignment->getDestination()->getDateTo(); $dateTo = $assignment->getDestination()->getDateTo();
return (new static($assignment->getId(), static::TYPE_DISPOSITION)) return (new static($assignment->getId(), static::TYPE_DISPOSITION))
->setDispositionId($disposition->getId())
->setDateFrom($dateFrom) ->setDateFrom($dateFrom)
->setDateTo($dateTo) ->setDateTo($dateTo)
->setJobProfile($assignment->getJobProfile()->getName()) ->setJobProfile($assignment->getJobProfile()->getName())
@@ -64,6 +66,18 @@ class TimelineItem
return $this->type; return $this->type;
} }
public function getDispositionId(): ?int
{
return $this->dispositionId;
}
public function setDispositionId(?int $dispositionId): static
{
$this->dispositionId = $dispositionId;
return $this;
}
public function getDateFrom(): ?\DateTimeImmutable public function getDateFrom(): ?\DateTimeImmutable
{ {
return $this->dateFrom; return $this->dateFrom;
+9 -18
View File
@@ -41,33 +41,24 @@ class TimelineService
private function addItem(array &$rows, TimelineItem $item): void private function addItem(array &$rows, TimelineItem $item): void
{ {
$itemAdded = false; $rowIndex = 0;
foreach ($rows as $index => $row) { foreach ($rows as $index => $row) {
$addToRow = true; $fitsRow = true;
foreach ($row as $entry) { foreach ($row as $entry) {
/** @var TimelineItem $entry */ /** @var TimelineItem $entry */
if ( if ($entry->getDateTo() >= $item->getDateFrom() && $entry->getDateFrom() <= $item->getDateTo()) {
$item->getDateFrom() >= $entry->getDateFrom() && $item->getDateFrom() <= $entry->getDateTo() $fitsRow = false;
|| $item->getDateTo() >= $entry->getDateFrom() && $item->getDateTo() <= $entry->getDateTo()
) {
$addToRow = false;
} }
} }
$rowIndex = $index;
if (true === $addToRow) {
$rows[$index][$item->getKey()] = $item;
$itemAdded = true;
break;
}
} }
if (false === $itemAdded) { if (false === $fitsRow) {
$rows[] = [ ++$rowIndex;
$item->getKey() => $item,
];
} }
$rows[$rowIndex][$item->getKey()] = $item;
} }
public function getActiveWindow(): CarbonPeriod public function getActiveWindow(): CarbonPeriod
@@ -2,35 +2,27 @@
{% block title %}Zeitleiste{% endblock %} {% block title %}Zeitleiste{% endblock %}
{% macro cell(row, day) %} {% macro cell(item, colspan) %}
{% if colspan is defined and colspan > 1 %} <td class="{{ html_classes('border border-gray-700', {
{% set colspan = colspan - 1 %} 'bg-gray-100': item.type == 'assignment',
{% elseif row[day|date('Ymd')] is defined %} 'bg-blue-500 text-gray-50': item.type == 'disposition' and item.status != 'confirmed',
{% set item = row[day|date('Ymd')] %} 'bg-green-500 text-gray-50': item.type == 'disposition' and (item.status == 'confirmed' or item.status == 'ended' or item.status == 'completed'),
{% set colspan = item.numberOfDays %} }) }}" colspan="{{ colspan }}">
<td class="{{ html_classes('border border-gray-700', { {% if item.type == 'disposition' %}
'bg-gray-100': item.type == 'assignment', <button type="button"
'bg-blue-500 text-gray-50': item.type == 'disposition' and item.status != 'confirmed', class="flex items-center space-x-2"
'bg-green-500 text-gray-50': item.type == 'disposition' and item.status == 'confirmed', title="Teamer:inneninfo {{ item.teamerName }}"
}) }}" colspan="{{ colspan }}"> hx-get="{{ path('app_administrative_teamer_info', { 'uuid': item.teamerUuid }) }}"
{% if item.type == 'disposition' %} hx-target="body"
<button type="button" hx-swap="beforeend">
class="flex items-center space-x-2"
title="Teamer:inneninfo {{ item.teamerName }}"
hx-get="{{ path('app_administrative_teamer_info', { 'uuid': item.teamerUuid }) }}"
hx-target="body"
hx-swap="beforeend">
<span class="text-xs font-semibold">{{ item.jobProfile }}</span>
<span class="text-xs">{{ item.teamerName | raw }}</span>
{{ icon('info', 'w-4 h-4') }}
</button>
{% else %}
<span class="text-xs font-semibold">{{ item.jobProfile }}</span> <span class="text-xs font-semibold">{{ item.jobProfile }}</span>
{% endif %} <span class="text-xs">{{ item.teamerName | raw }}</span>
</td> {{ icon('info', 'w-4 h-4') }}
{% else %} </button>
<td class="border border-gray-700"></td> {% else %}
{% endif %} <span class="text-xs font-semibold">{{ item.jobProfile }}</span>
{% endif %}
</td>
{% endmacro %} {% endmacro %}
{% block content %} {% block content %}
@@ -75,13 +67,29 @@
{{ hotelCode }} {{ hotelCode }}
</td> </td>
{% for day in filterDto.period %} {% for day in filterDto.period %}
{{ _self.cell(rows[0], day) }} {% if colspan is defined and colspan > 1 %}
{% set colspan = colspan - 1 %}
{% elseif rows[0][day|date('Ymd')] is defined %}
{% set item = rows[0][day|date('Ymd')] %}
{% set colspan = item.numberOfDays %}
{{ _self.cell(item, colspan) }}
{% else %}
<td class="border border-gray-700"></td>
{% endif %}
{% endfor %} {% endfor %}
</tr> </tr>
{% for row in rows[1:] %} {% for row in rows[1:] %}
<tr> <tr>
{% for day in filterDto.period %} {% for day in filterDto.period %}
{{ _self.cell(row, day) }} {% if colspan is defined and colspan > 1 %}
{% set colspan = colspan - 1 %}
{% elseif row[day|date('Ymd')] is defined %}
{% set item = row[day|date('Ymd')] %}
{% set colspan = item.numberOfDays %}
{{ _self.cell(item, colspan) }}
{% else %}
<td class="border border-gray-700"></td>
{% endif %}
{% endfor %} {% endfor %}
</tr> </tr>
{% endfor %} {% endfor %}