Skip to content

Commit 9663a31

Browse files
Redesign non-empty schedule view
- Add button to the .overlay element - Merge sidebar entry to the button row
1 parent 601ffc7 commit 9663a31

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
@@ -255,7 +255,7 @@ protected function getGrid()
255255
$this->grid = (new DynamicGrid($this, $this->getStyle(), $this->start))->setDays($this->days);
256256
}
257257

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

public/css/timeline.less

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
}
6565
}
6666

67+
.sidebar .placeholder {
68+
background-color: @gray-lighter;
69+
border-top: 1px solid @gray-lighter;
70+
margin-top: -1px; // to cover the border-bottom area of the previous sibling
71+
}
72+
6773
.btn-container {
6874
display: flex;
6975
justify-content: center;
@@ -72,6 +78,22 @@
7278
height: var(--primaryRowHeight);
7379
}
7480

81+
.overlay .btn-container {
82+
// Make the button gray and add the hint text
83+
pointer-events: all; // allow to click on the buttons
84+
padding-right: var(--sidebarWidth); // center the button taking the sidebar width into account
85+
86+
.button-link:not(:hover) {
87+
color: @disabled-gray;
88+
background: none;
89+
}
90+
91+
.hint {
92+
margin-left: .5em;
93+
color: @text-color-light;
94+
}
95+
}
96+
7597
.overlay .entry {
7698
margin-top: 1em;
7799
margin-bottom: 1em;

0 commit comments

Comments
 (0)