Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Jun 14, 2024
1 parent ba627b4 commit 120b7fe
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 18 deletions.
1 change: 1 addition & 0 deletions application/controllers/ScheduleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public function moveRotationAction(): void

$form = new MoveRotationForm(Database::get());
$form->on(MoveRotationForm::ON_SUCCESS, function (MoveRotationForm $form) {
$this->sendExtraUpdates(['#col1']);
$this->redirectNow(Links::schedule($form->getScheduleId()));
});

Expand Down
19 changes: 18 additions & 1 deletion library/Notifications/Widget/ItemList/ScheduleListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@

namespace Icinga\Module\Notifications\Widget\ItemList;

use DateTime;
use Icinga\Module\Notifications\Common\Links;
use Icinga\Module\Notifications\Model\Schedule;
use Icinga\Module\Notifications\Widget\Timeline;
use Icinga\Module\Notifications\Widget\Timeline\Rotation;
use Icinga\Util\Csp;
use ipl\Html\BaseHtmlElement;
use ipl\Web\Common\BaseListItem;
use ipl\Web\Style;
use ipl\Web\Widget\Link;

/**
Expand Down Expand Up @@ -43,6 +48,18 @@ protected function assembleHeader(BaseHtmlElement $header): void

protected function assembleMain(BaseHtmlElement $main): void
{
$main->addHtml($this->createHeader());
// Number of days set to 7 as default mode for schedule is week and the start day should be the current day
$timeline = new Timeline((new DateTime())->setTime(0, 0), 7, true);
$timeline->setStyle(
(new Style())
->setNonce(Csp::getStyleNonce())
->setModule('notifications')
);

foreach ($this->item->rotation->with('timeperiod')->orderBy('first_handoff', SORT_DESC) as $rotation) {
$timeline->addRotation(new Rotation($rotation));
}

$main->addHtml($this->createHeader(), $timeline);
}
}
51 changes: 34 additions & 17 deletions library/Notifications/Widget/Timeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Timeline extends BaseHtmlElement implements EntryProvider
/** @var ?DynamicGrid */
protected $grid;

protected $ignoreRotations = false;

/**
* Set the style object to register inline styles in
*
Expand Down Expand Up @@ -81,10 +83,11 @@ public function getStyle(): Style
* @param DateTime $start The day the grid should start on
* @param int $days Number of days to show on the grid
*/
public function __construct(DateTime $start, int $days)
public function __construct(DateTime $start, int $days, $ignoreRotations = false)
{
$this->start = $start;
$this->days = $days;
$this->ignoreRotations = $ignoreRotations;
}

/**
Expand Down Expand Up @@ -145,13 +148,21 @@ public function getEntries(): Traversable
}, 0);

$occupiedCells = [];
$resultPosition = $maxPriority + 1;

if ($this->ignoreRotations) {
$resultPosition = 0;
} else {
$resultPosition = $maxPriority + 1;
}

foreach ($rotations as $rotation) {
$rotationPosition = $maxPriority - $rotation->getPriority();
foreach ($rotation->fetchTimeperiodEntries($this->start, $this->getGrid()->getGridEnd()) as $entry) {
$entry->setPosition($rotationPosition);

yield $entry;
if (! $this->ignoreRotations) {
yield $entry;
}

$occupiedCells += $getDesiredCells($entry);
}
Expand Down Expand Up @@ -221,15 +232,17 @@ protected function getGrid(): DynamicGrid
$this->grid = new DynamicGrid($this, $this->getStyle(), $this->start);
$this->grid->setDays($this->days);

$rotations = $this->rotations;
usort($rotations, function (Rotation $a, Rotation $b) {
return $b->getPriority() <=> $a->getPriority();
});
$occupiedPriorities = [];
foreach ($rotations as $rotation) {
if (! isset($occupiedPriorities[$rotation->getPriority()])) {
$occupiedPriorities[$rotation->getPriority()] = true;
$this->grid->addToSideBar($this->assembleSidebarEntry($rotation));
if (! $this->ignoreRotations) {
$rotations = $this->rotations;
usort($rotations, function (Rotation $a, Rotation $b) {
return $b->getPriority() <=> $a->getPriority();
});
$occupiedPriorities = [];
foreach ($rotations as $rotation) {
if (! isset($occupiedPriorities[$rotation->getPriority()])) {
$occupiedPriorities[$rotation->getPriority()] = true;
$this->grid->addToSideBar($this->assembleSidebarEntry($rotation));
}
}
}
}
Expand Down Expand Up @@ -259,6 +272,11 @@ protected function assembleSidebarEntry(Rotation $rotation): BaseHtmlElement

protected function assemble()
{
$this->addHtml(
$this->getGrid(),
$this->getStyle()
);

if (empty($this->rotations)) {
$this->getGrid()->addToSideBar(
new HtmlElement(
Expand All @@ -267,6 +285,10 @@ protected function assemble()
Text::create($this->translate('No rotations configured'))
)
);

if ($this->ignoreRotations) {
return;
}
}

$this->getGrid()->addToSideBar(
Expand All @@ -276,10 +298,5 @@ protected function assemble()
Text::create($this->translate('Result'))
)
);

$this->addHtml(
$this->getGrid(),
$this->getStyle()
);
}
}
19 changes: 19 additions & 0 deletions public/css/list/schedule-list.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* Icinga Notifications Web | (c) 2024 Icinga GmbH | GPLv2 */
.item-list.schedule-list {
.list-item {
.main {
.header {
background: none;
}

.entry {
pointer-events: none;
}
}

.timeline {
margin-left: 5em;
height: auto;
}
}
}

0 comments on commit 120b7fe

Please sign in to comment.