Skip to content

Commit fead6e6

Browse files
Schedule detail: Introduce current time indicator
1 parent 48cb522 commit fead6e6

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;
@@ -24,6 +26,7 @@
2426
use ipl\Web\Url;
2527
use ipl\Web\Widget\Icon;
2628
use ipl\Web\Widget\Link;
29+
use Locale;
2730
use SplObjectStorage;
2831
use Traversable;
2932

@@ -318,8 +321,41 @@ protected function assemble()
318321
)
319322
);
320323

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

325361
$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

@@ -49,6 +49,7 @@
4949
.overlay .entry {
5050
margin-top: 1em;
5151
margin-bottom: 1em;
52+
z-index: 2; // overlap the .clock .time-hand
5253

5354
.title {
5455
height: 100%;
@@ -115,6 +116,34 @@
115116
grid-area: ~"1 / -2 / 1 / -1";
116117
}
117118
}
119+
120+
.clock {
121+
display: grid;
122+
grid-template-columns: repeat(var(--primaryColumns), 1fr);
123+
grid-area: ~"3 / 2 / 4 / 3";
124+
border-top: 1px solid transparent; // left not required, otherwise the .time-hand is not aligned properly
125+
126+
.current-day {
127+
display: grid;
128+
grid-template-columns: repeat(var(--columnsPerStep), 1fr);
129+
grid-area: ~"1 / 1 / 2 / 2";
130+
131+
.time-hand {
132+
grid-area: ~"1 / var(--timeStartColumn) / 2 / calc(var(--timeStartColumn) + 1)";
133+
display: flex;
134+
align-items: flex-end;
135+
width: 1px;
136+
border-left: 1px solid red;
137+
z-index: 1;
138+
139+
.now {
140+
.rounded-corners();
141+
padding: 0 .25em;
142+
transform: translate(-50%, 50%);
143+
}
144+
}
145+
}
146+
}
118147
}
119148
}
120149

@@ -185,6 +214,13 @@
185214
color: @gray-semilight;
186215
background: @body-bg-color;
187216
}
217+
218+
.clock .now {
219+
background-color: @gray-light;
220+
font-size: 0.75em;
221+
color: red;
222+
user-select: none;
223+
}
188224
}
189225

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

0 commit comments

Comments
 (0)