Skip to content

Commit da076f5

Browse files
Redesign non-empty schedule view
- Add button to the .overlay element - Merge sidebar entry to the button row
1 parent 87ea6a0 commit da076f5

File tree

4 files changed

+73
-5
lines changed

4 files changed

+73
-5
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/calendar.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
.grid,
8484
.overlay {
8585
display: grid;
86-
overflow: hidden;
86+
// overflow: hidden; //TODO(sd): is this required?
8787
grid-template-rows: repeat(~"calc(var(--primaryRows) * var(--rowsPerStep))", var(--stepRowHeight));
8888
grid-template-columns: repeat(~"calc(var(--primaryColumns) * var(--columnsPerStep))", minmax(var(--minimumStepColumnWidth), 1fr));
8989
border-width: 1px 0 0 1px;

public/css/timeline.less

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,33 @@
6767
}
6868
}
6969

70+
.sidebar .placeholderXXX {
71+
background-color: fade(@gray-light, 25%);
72+
border-top: 1px solid @gray-lighter;
73+
margin-top: -1px; // to cover the border-bottom area of the previous sibling
74+
}
75+
7076
.btn-container {
7177
display: flex;
7278
justify-content: center;
7379
align-items: center;
7480
text-align: center;
7581
height: var(--primaryRowHeight);
82+
margin-left: ~"calc(var(--sidebarWidth) * -1)"; // overlap sidebar
83+
}
84+
85+
.overlay .btn-container {
86+
pointer-events: all; // allow to click on the buttons
87+
88+
.button-link:not(:hover) {
89+
color: @disabled-gray;
90+
background: none;
91+
}
92+
93+
.hint {
94+
margin-left: .5em;
95+
color: @text-color-light;
96+
}
7697
}
7798

7899
.overlay .entry {
@@ -240,7 +261,8 @@
240261
}
241262

242263
.btn-container {
243-
background-color: fade(@gray-light, 25%);
264+
background-color: mix(@gray-light, @body-bg-color, 25%);
265+
margin-left: ~"calc(var(--sidebarWidth) * -1)";
244266

245267
.empty-notice {
246268
margin-right: 1em;
@@ -311,3 +333,9 @@
311333
#layout.twocols .schedule .timescale:has(:nth-child(n+62)) { // month view (--timestampsPerDay * --primaryColumns = 62)
312334
display: none;
313335
}
336+
337+
@light-mode: {
338+
.timeline .btn-container {
339+
background-color: mix(#d0d3da, #F5F9FA, 25%); //@gray-light, @light-body-bg-color
340+
}
341+
};

0 commit comments

Comments
 (0)