Skip to content

Commit 505ac04

Browse files
Schedule detail: Introduce current time indicator
1 parent 4a91756 commit 505ac04

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

library/Notifications/Widget/Timeline.php

+37-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
use Icinga\Module\Notifications\Widget\TimeGrid\EntryProvider;
1313
use Icinga\Module\Notifications\Widget\TimeGrid\GridStep;
1414
use Icinga\Module\Notifications\Widget\TimeGrid\Timescale;
15+
use Icinga\Module\Notifications\Widget\TimeGrid\Util;
1516
use Icinga\Module\Notifications\Widget\Timeline\Entry;
1617
use Icinga\Module\Notifications\Widget\Timeline\MinimalGrid;
1718
use Icinga\Module\Notifications\Widget\Timeline\Rotation;
19+
use IntlDateFormatter;
1820
use ipl\Html\Attributes;
1921
use ipl\Html\BaseHtmlElement;
2022
use ipl\Html\HtmlElement;
@@ -23,6 +25,7 @@
2325
use ipl\Web\Style;
2426
use ipl\Web\Url;
2527
use ipl\Web\Widget\Icon;
28+
use Locale;
2629
use SplObjectStorage;
2730
use Traversable;
2831

@@ -314,8 +317,41 @@ protected function assemble()
314317
)
315318
);
316319

320+
$dateFormatter = new IntlDateFormatter(
321+
Locale::getDefault(),
322+
IntlDateFormatter::NONE,
323+
IntlDateFormatter::SHORT
324+
);
325+
326+
$now = new DateTime();
327+
$currentTime = new HtmlElement(
328+
'div',
329+
new Attributes(['class' => 'time-hand']),
330+
new HtmlElement(
331+
'div',
332+
new Attributes(['class' => 'now', 'title' => $dateFormatter->format($now)]),
333+
Text::create('now')
334+
)
335+
);
336+
337+
$now = Util::roundToNearestThirtyMinute($now);
338+
339+
$this->getStyle()->addFor($currentTime, [
340+
'--timeStartColumn' =>
341+
$now->format('G') * 2 // 2 columns per hour
342+
+ ($now->format('i') >= 30 ? 1 : 0) // 1 column for the half hour
343+
+ 1 // CSS starts counting columns from 1, not zero
344+
]);
345+
346+
$clock = new HtmlElement(
347+
'div',
348+
new Attributes(['class' => 'clock']),
349+
new HtmlElement('div', new Attributes(['class' => 'current-day']), $currentTime)
350+
);
351+
317352
$this->getGrid()
318-
->addHtml(new Timescale($this->days, $this->getStyle()));
353+
->addHtml(new Timescale($this->days, $this->getStyle()))
354+
->addHtml($clock);
319355
}
320356

321357
$this->addHtml(

public/css/timeline.less

+39-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
.time-grid-header {
1515
box-sizing: border-box;
1616
position: sticky;
17-
z-index: 1;
17+
z-index: 2; // overlap the .clock .time-hand
1818
top: 0;
1919
}
2020

@@ -34,6 +34,7 @@
3434
.overlay .entry {
3535
margin-top: 1em;
3636
margin-bottom: 1em;
37+
z-index: 2; // overlap the .clock .time-hand
3738

3839
.title {
3940
height: 100%;
@@ -94,6 +95,36 @@
9495
}
9596
}
9697
}
98+
99+
.clock {
100+
display: grid;
101+
grid-template-columns: repeat(var(--primaryColumns), 1fr);
102+
grid-template-rows: ~"calc(var(--primaryRows) * var(--primaryRowHeight))";
103+
grid-area: ~"3 / 2 / 4 / 3";
104+
border-top: 1px solid transparent; // left not required, otherwise the .time-hand is not aligned properly
105+
106+
.current-day {
107+
display: grid;
108+
grid-template-columns: repeat(var(--columnsPerStep), 1fr);
109+
grid-template-rows: ~"calc(var(--primaryRows) * var(--primaryRowHeight))";
110+
grid-area: ~"1 / 1 / 2 / 2";
111+
112+
.time-hand {
113+
grid-area: ~"1 / var(--timeStartColumn) / 2 / calc(var(--timeStartColumn) + 1)";
114+
display: flex;
115+
align-items: flex-end;
116+
width: 1px;
117+
border-left: 1px solid red;
118+
z-index: 1;
119+
120+
.now {
121+
.rounded-corners();
122+
padding: 0 .25em;
123+
transform: translate(-50%, 50%);
124+
}
125+
}
126+
}
127+
}
97128
}
98129
}
99130

@@ -146,6 +177,13 @@
146177
.timescale .timestamp::after {
147178
background: @gray-lighter;
148179
}
180+
181+
.clock .now {
182+
background-color: @gray-light;
183+
font-size: 0.75em;
184+
color: red;
185+
cursor: pointer;
186+
}
149187
}
150188

151189
.timeline.minimal-layout .empty-notice {

0 commit comments

Comments
 (0)