Skip to content

Commit a40eb0f

Browse files
Schedule detail: Introduce current time indicator
1 parent 8d67890 commit a40eb0f

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%;
@@ -109,6 +110,34 @@
109110
}
110111
}
111112
}
113+
114+
.clock {
115+
display: grid;
116+
grid-template-columns: repeat(var(--primaryColumns), 1fr);
117+
grid-area: ~"3 / 2 / 4 / 3";
118+
border-top: 1px solid transparent; // left not required, otherwise the .time-hand is not aligned properly
119+
120+
.current-day {
121+
display: grid;
122+
grid-template-columns: repeat(var(--columnsPerStep), 1fr);
123+
grid-area: ~"1 / 1 / 2 / 2";
124+
125+
.time-hand {
126+
grid-area: ~"1 / var(--timeStartColumn) / 2 / calc(var(--timeStartColumn) + 1)";
127+
display: flex;
128+
align-items: flex-end;
129+
width: 1px;
130+
border-left: 1px solid red;
131+
z-index: 1;
132+
133+
.now {
134+
.rounded-corners();
135+
padding: 0 .25em;
136+
transform: translate(-50%, 50%);
137+
}
138+
}
139+
}
140+
}
112141
}
113142
}
114143

@@ -182,6 +211,13 @@
182211
background: @gray-lighter;
183212
}
184213
}
214+
215+
.clock .now {
216+
background-color: @gray-light;
217+
font-size: 0.75em;
218+
color: red;
219+
cursor: pointer;
220+
}
185221
}
186222

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

0 commit comments

Comments
 (0)