Skip to content

Commit 0384a27

Browse files
Schedule detail: Introduce current time indicator
1 parent 17c46b3 commit 0384a27

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-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($this->translate('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

+37-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
.time-grid-header {
1616
box-sizing: border-box;
1717
position: sticky;
18-
z-index: 1;
18+
z-index: 2; // overlap the .clock .time-hand
1919
top: 0;
2020
}
2121

@@ -35,6 +35,7 @@
3535
.overlay .entry {
3636
margin-top: 1em;
3737
margin-bottom: 1em;
38+
z-index: 2; // overlap the .clock .time-hand
3839

3940
.title {
4041
height: 100%;
@@ -95,6 +96,34 @@
9596
}
9697
}
9798
}
99+
100+
.clock {
101+
display: grid;
102+
grid-template-columns: repeat(var(--primaryColumns), 1fr);
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-area: ~"1 / 1 / 2 / 2";
110+
111+
.time-hand {
112+
grid-area: ~"1 / var(--timeStartColumn) / 2 / calc(var(--timeStartColumn) + 1)";
113+
display: flex;
114+
align-items: flex-end;
115+
width: 1px;
116+
border-left: 1px solid red;
117+
z-index: 1;
118+
119+
.now {
120+
.rounded-corners();
121+
padding: 0 .25em;
122+
transform: translate(-50%, 50%);
123+
}
124+
}
125+
}
126+
}
98127
}
99128
}
100129

@@ -151,6 +180,13 @@
151180
background: @gray-lighter;
152181
}
153182
}
183+
184+
.clock .now {
185+
background-color: @gray-light;
186+
font-size: 0.75em;
187+
color: red;
188+
cursor: pointer;
189+
}
154190
}
155191

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

0 commit comments

Comments
 (0)