Skip to content

Commit 7bd4f54

Browse files
Redesign non-empty schedule view
- Add button to the .overlay element - Merge sidebar entry to the button row
1 parent ad9a0cd commit 7bd4f54

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

library/Notifications/Widget/TimeGrid/BaseGrid.php

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
use DateInterval;
88
use DateTime;
99
use Generator;
10+
use Icinga\Module\Notifications\Common\Links;
1011
use ipl\Html\Attributes;
1112
use ipl\Html\BaseHtmlElement;
1213
use ipl\Html\HtmlElement;
14+
use ipl\Html\Text;
1315
use ipl\I18n\Translation;
1416
use ipl\Web\Style;
17+
use ipl\Web\Url;
18+
use ipl\Web\Widget\ButtonLink;
1519
use ipl\Web\Widget\Link;
1620
use LogicException;
1721
use SplObjectStorage;
@@ -471,7 +475,7 @@ final protected function yieldFixedEntries(Traversable $entries): Generator
471475
}
472476

473477
$this->style->addFor($this, [
474-
'--primaryRows' => $lastRow === 1 ? 1 : $lastRow - $rowStartModifier + 1,
478+
'--primaryRows' => $lastRow === 1 ? 1 : $lastRow - $rowStartModifier + 1 + 1, // +1 to create extra row for add rotation button
475479
'--rowsPerStep' => 1
476480
]);
477481
}
@@ -490,11 +494,44 @@ protected function assembleGridOverlay(BaseHtmlElement $overlay): void
490494
$generator = $this->yieldFixedEntries($entries);
491495
}
492496

497+
$addButtonCreated = false;
493498
foreach ($generator as $gridArea => $entry) {
499+
[$rowStart, $colStart, $rowEnd, $colEnd] = $gridArea;
500+
501+
if (! $addButtonCreated && $entry->getAttributes()->has('data-rotation-position')) {
502+
$btn = new HtmlElement('div', new Attributes(['class' => 'btn-container']));
503+
504+
$btn->addHtml(
505+
(new ButtonLink(
506+
$this->translate('Add another Rotation'),
507+
Links::rotationAdd(Url::fromRequest()->getParam('id')),
508+
'plus'
509+
))->openInModal(),
510+
new HtmlElement(
511+
'span',
512+
new Attributes(['class' => 'hint']),
513+
new Text($this->translate('to override rotations above'))
514+
)
515+
);
516+
517+
// take up the entire row
518+
$this->style->addFor($btn, [
519+
'grid-area' => sprintf('~"%d / %d / %d / %d"', $rowStart, 1, $rowEnd, -1)
520+
]);
521+
522+
$overlay->addHtml($btn);
523+
$addButtonCreated = true;
524+
}
525+
526+
if ($addButtonCreated) { // result row must be below
527+
$rowStart++;
528+
$rowEnd++;
529+
}
530+
494531
$this->style->addFor($entry, [
495532
'--entry-bg' => $entry->getColor(10),
496533
'--entry-border-color' => $entry->getColor(50),
497-
'grid-area' => sprintf('~"%d / %d / %d / %d"', ...$gridArea)
534+
'grid-area' => sprintf('~"%d / %d / %d / %d"', $rowStart, $colStart, $rowEnd, $colEnd)
498535
]);
499536

500537
$overlay->addHtml($entry);

library/Notifications/Widget/Timeline.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ protected function getGrid()
254254
$this->grid = (new DynamicGrid($this, $this->getStyle(), $this->start))->setDays($this->days);
255255
}
256256

257-
if (! $this->minimalLayout) {
257+
if (! $this->minimalLayout && $this->rotations) {
258258
$rotations = $this->rotations;
259259
usort($rotations, function (Rotation $a, Rotation $b) {
260260
return $b->getPriority() <=> $a->getPriority();
@@ -266,6 +266,9 @@ protected function getGrid()
266266
$this->grid->addToSideBar($this->assembleSidebarEntry($rotation));
267267
}
268268
}
269+
270+
// placeholder for new add button row
271+
$this->grid->addToSideBar(new HtmlElement('div', new Attributes(['class' => 'placeholder'])));
269272
}
270273
}
271274

public/css/timeline.less

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
}
5050
}
5151

52+
.sidebar .placeholder {
53+
background-color: @gray-lighter;
54+
border-top: 1px solid @gray-lighter;
55+
margin-top: -1px; // to cover the border-bottom area of the previous sibling
56+
}
57+
5258
.btn-container {
5359
display: flex;
5460
justify-content: center;
@@ -57,6 +63,22 @@
5763
height: var(--primaryRowHeight);
5864
}
5965

66+
.overlay .btn-container {
67+
// Make the button gray and add the hint text
68+
pointer-events: all; // allow to click on the buttons
69+
padding-right: var(--sidebarWidth); // center the button taking the sidebar width into account
70+
71+
.button-link:not(:hover) {
72+
color: @disabled-gray;
73+
background: none;
74+
}
75+
76+
.hint {
77+
margin-left: .5em;
78+
color: @text-color-light;
79+
}
80+
}
81+
6082
.overlay .entry {
6183
margin-top: 1em;
6284
margin-bottom: 1em;

0 commit comments

Comments
 (0)