Skip to content

Commit 5d70ce3

Browse files
Schedule detail: Introduce current time indicator
1 parent 92d045d commit 5d70ce3

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%;
@@ -121,6 +122,34 @@
121122
grid-area: ~"1 / -2 / 1 / -1";
122123
}
123124
}
125+
126+
.clock {
127+
display: grid;
128+
grid-template-columns: repeat(var(--primaryColumns), 1fr);
129+
grid-area: ~"3 / 2 / 4 / 3";
130+
border-top: 1px solid transparent; // left not required, otherwise the .time-hand is not aligned properly
131+
132+
.current-day {
133+
display: grid;
134+
grid-template-columns: repeat(var(--columnsPerStep), 1fr);
135+
grid-area: ~"1 / 1 / 2 / 2";
136+
137+
.time-hand {
138+
grid-area: ~"1 / var(--timeStartColumn) / 2 / calc(var(--timeStartColumn) + 1)";
139+
display: flex;
140+
align-items: flex-end;
141+
width: 1px;
142+
border-left: 1px solid red;
143+
z-index: 1;
144+
145+
.now {
146+
.rounded-corners();
147+
padding: 0 .25em;
148+
transform: translate(-50%, 50%);
149+
}
150+
}
151+
}
152+
}
124153
}
125154
}
126155

@@ -191,6 +220,13 @@
191220
color: @gray-semilight;
192221
background: @body-bg-color;
193222
}
223+
224+
.clock .now {
225+
background-color: @gray-light;
226+
font-size: 0.75em;
227+
color: red;
228+
.user-select(none);
229+
}
194230
}
195231

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

0 commit comments

Comments
 (0)