Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeline: Visualize future rotations #309

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 40 additions & 28 deletions library/Notifications/Widget/TimeGrid/BaseGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DateInterval;
use DateTime;
use Generator;
use Icinga\Module\Notifications\Widget\Timeline\FutureEntry;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\Html\HtmlElement;
Expand Down Expand Up @@ -425,46 +426,57 @@ final protected function yieldFixedEntries(Traversable $entries): Generator
$lastRow = $rowStart;
}

$actualStart = Util::roundToNearestThirtyMinute($entry->getStart());
if ($actualStart < $gridStartsAt) {
$colStart = 0;
} else {
$colStart = Util::diffHours($gridStartsAt, $actualStart) * 2;
}

$actualEnd = Util::roundToNearestThirtyMinute($entry->getEnd());
if ($actualEnd > $gridEndsAt) {
if ($entry instanceof FutureEntry) {
$colStart = ($this->getNoOfVisuallyConnectedHours() / 24 + 1) * - 1;
$colEnd = $gridBorderAt;
} else {
$colEnd = Util::diffHours($gridStartsAt, $actualEnd) * 2;
}
$actualStart = Util::roundToNearestThirtyMinute($entry->getStart());
if ($actualStart < $gridStartsAt) {
$colStart = 0;
} else {
$colStart = Util::diffHours($gridStartsAt, $actualStart) * 2;
}

$actualEnd = Util::roundToNearestThirtyMinute($entry->getEnd());
if ($actualEnd > $gridEndsAt) {
$colEnd = $gridBorderAt;
} else {
$colEnd = Util::diffHours($gridStartsAt, $actualEnd) * 2;
}

if ($colStart > $gridBorderAt || $colEnd === $colStart) {
throw new LogicException(sprintf(
'Invalid entry (%d) position: %s to %s. Grid dimension: %s to %s',
$entry->getId(),
$actualStart->format('Y-m-d H:i:s'),
$actualEnd->format('Y-m-d H:i:s'),
$gridStartsAt->format('Y-m-d'),
$gridEndsAt->format('Y-m-d')
));
if ($colStart > $gridBorderAt || $colEnd === $colStart) {
throw new LogicException(sprintf(
'Invalid entry (%d) position: %s to %s. Grid dimension: %s to %s',
$entry->getId(),
$actualStart->format('Y-m-d H:i:s'),
$actualEnd->format('Y-m-d H:i:s'),
$gridStartsAt->format('Y-m-d'),
$gridEndsAt->format('Y-m-d')
));
}

$colStart++;
}

$gridArea = $this->getGridArea(
$rowStart,
$rowStart + 1,
$colStart + 1,
$colStart,
$colEnd + 1
);

$fromPrevGrid = $gridStartsAt > $entry->getStart();
$toNextGrid = $gridEndsAt < $entry->getEnd();
if ($fromPrevGrid && $toNextGrid) {
$entry->setContinuationType(Entry::ACROSS_GRID);
} elseif ($fromPrevGrid) {
$entry->setContinuationType(Entry::FROM_PREV_GRID);
} elseif ($toNextGrid) {
if ($entry instanceof FutureEntry) {
$entry->setContinuationType(Entry::TO_NEXT_GRID);
} else {
$fromPrevGrid = $gridStartsAt > $entry->getStart();
$toNextGrid = $gridEndsAt < $entry->getEnd();
if ($fromPrevGrid && $toNextGrid) {
$entry->setContinuationType(Entry::ACROSS_GRID);
} elseif ($fromPrevGrid) {
$entry->setContinuationType(Entry::FROM_PREV_GRID);
} elseif ($toNextGrid) {
$entry->setContinuationType(Entry::TO_NEXT_GRID);
}
}

yield $gridArea => $entry;
Expand Down
7 changes: 7 additions & 0 deletions library/Notifications/Widget/Timeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Icinga\Module\Notifications\Widget\TimeGrid\EntryProvider;
use Icinga\Module\Notifications\Widget\TimeGrid\GridStep;
use Icinga\Module\Notifications\Widget\Timeline\Entry;
use Icinga\Module\Notifications\Widget\Timeline\FutureEntry;
use Icinga\Module\Notifications\Widget\Timeline\MinimalGrid;
use Icinga\Module\Notifications\Widget\Timeline\Rotation;
use ipl\Html\Attributes;
Expand Down Expand Up @@ -169,7 +170,9 @@ public function getEntries(): Traversable

$occupiedCells = [];
foreach ($rotations as $rotation) {
$entryFound = false;
foreach ($rotation->fetchTimeperiodEntries($this->start, $this->getGrid()->getGridEnd()) as $entry) {
$entryFound = true;
if (! $this->minimalLayout) {
$entry->setPosition($maxPriority - $rotation->getPriority());

Expand All @@ -178,6 +181,10 @@ public function getEntries(): Traversable

$occupiedCells += $getDesiredCells($entry);
}

if (! $entryFound && ! $this->minimalLayout) {
yield (new FutureEntry(0))->setPosition($maxPriority - $rotation->getPriority());
}
}

$entryToCellsMap = new SplObjectStorage();
Expand Down
29 changes: 29 additions & 0 deletions library/Notifications/Widget/Timeline/FutureEntry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Icinga\Module\Notifications\Widget\Timeline;

use Icinga\Module\Notifications\Widget\TimeGrid\Entry;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\I18n\Translation;
use ipl\Web\Widget\Icon;

class FutureEntry extends Entry
{
use Translation;

public function getColor(int $transparency): string
{
return sprintf('~"hsl(%d %d%% 50%% / %d%%)"', 166, 90, $transparency);
}

protected function assembleContainer(BaseHtmlElement $container): void
{
$this
->addHtml(new Icon('angle-right'))
->addAttributes(new Attributes([
'class' => 'future',
'title' => $this->translate('rotation starts in the future')
]));
}
}
26 changes: 26 additions & 0 deletions public/css/timeline.less
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,32 @@
.text-ellipsis();
}
}

&.future {
display: flex;
align-items: center;
justify-content: center;

position: relative;
padding-left: 6px; // 2px before + 1px border + 2px after + 1px border

&:before,
&:after {
content: '';
display: block;
position: absolute;
border: 1px solid var(--entry-border-color);
border-right: transparent;
height: ~"calc(100% + 2px)"; // border top and bottom
width: 100%;
left: 2px;
.rounded-corners(0.25em);
}

&:after {
left: 5px; // 2px before + 1px border + 2px after
}
}
}

&::after {
Expand Down
Loading