Skip to content

Timeline: Visualize future rotations #309

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

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
15 changes: 15 additions & 0 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 @@ -421,6 +422,20 @@ final protected function yieldFixedEntries(Traversable $entries): Generator
}

$rowStart = $position + $rowStartModifier;

if ($entry instanceof FutureEntry) {
$gridArea = $this->getGridArea(
$rowStart,
$rowStart + 1,
1,
$gridBorderAt + 1
);

yield $gridArea => $entry;

continue;
}

if ($rowStart > $lastRow) {
$lastRow = $rowStart;
}
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 @@ -14,6 +14,7 @@
use Icinga\Module\Notifications\Widget\TimeGrid\Timescale;
use Icinga\Module\Notifications\Widget\TimeGrid\Util;
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 IntlDateFormatter;
Expand Down Expand Up @@ -173,7 +174,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 @@ -182,6 +185,10 @@ public function getEntries(): Traversable

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

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

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

/* Icinga Notifications Web | (c) 2025 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Notifications\Widget\Timeline;

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

/**
* FutureEntry
*
* Visualize a future entry of the rotation
*
* @extends Entry<0>
*/
class FutureEntry extends Entry
{
public function __construct()
{
parent::__construct(0);

$this->setContinuationType(Entry::TO_NEXT_GRID);
}

public function getColor(int $transparency): string
{
// --base-disabled (#d0d3da) -> hsl(222, 12%, 84%) + transparency
return sprintf('~"hsl(222 12%% 84%% / %d%%)"', $transparency);
}

protected function assembleContainer(BaseHtmlElement $container): void
{
$futureBadge = new HtmlElement(
'div',
new Attributes([
'title' => $this->translate('Rotation starts in the future'),
$container->getAttributes()->get('class')
]),
new Icon('angle-right')
);

$container
->setAttribute('class', 'future-entry') // override the default class
->addHtml($futureBadge);
}
}
56 changes: 45 additions & 11 deletions public/css/timeline.less
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,53 @@
}
}

.overlay .entry {
margin-top: 1em;
margin-bottom: 1em;
z-index: 2; // overlap the .clock .time-hand
.overlay {
.entry {
margin-top: 1em;
margin-bottom: 1em;
z-index: 2; // overlap the .clock .time-hand

.title {
height: 100%;
flex-wrap: nowrap;
align-items: baseline;
padding: .15em .5em;

.name {
.text-ellipsis();
}
}
}

.title {
height: 100%;
flex-wrap: nowrap;
align-items: baseline;
padding: .15em .5em;
.future-entry {
display: flex;
justify-content: end;

.name {
.text-ellipsis();
.entry {
display: flex;
align-items: center;
justify-content: end;
flex-shrink: 0;
position: relative;
padding-right: .25em;
width: 3em;

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

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