Skip to content

Commit 90c1773

Browse files
Schedule detail: Introduce current time indicator
1 parent 6494311 commit 90c1773

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

library/Notifications/Widget/Timeline.php

Lines changed: 37 additions & 1 deletion
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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
.time-grid-header {
1717
box-sizing: border-box;
1818
position: sticky;
19-
z-index: 1;
19+
z-index: 2; // overlap the .clock .time-hand
2020
top: 0;
2121
height: var(--daysHeaderHeight);
2222
}
@@ -51,6 +51,7 @@
5151
.overlay .entry {
5252
margin-top: 1em;
5353
margin-bottom: 1em;
54+
z-index: 2; // overlap the .clock .time-hand
5455

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

@@ -192,6 +221,13 @@
192221
color: @gray-semilight;
193222
background: @body-bg-color;
194223
}
224+
225+
.clock .now {
226+
background-color: @gray-light;
227+
font-size: 0.75em;
228+
color: red;
229+
.user-select(none);
230+
}
195231
}
196232

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

0 commit comments

Comments
 (0)