Skip to content

Commit

Permalink
Schedule redesign (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg authored Jun 12, 2024
2 parents 659cc5e + 9247d7c commit 5c3e0e0
Show file tree
Hide file tree
Showing 47 changed files with 4,479 additions and 1,596 deletions.
109 changes: 58 additions & 51 deletions application/controllers/ScheduleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

use Icinga\Module\Notifications\Common\Database;
use Icinga\Module\Notifications\Common\Links;
use Icinga\Module\Notifications\Forms\EntryForm;
use Icinga\Module\Notifications\Forms\MoveRotationForm;
use Icinga\Module\Notifications\Forms\RotationConfigForm;
use Icinga\Module\Notifications\Forms\ScheduleForm;
use Icinga\Module\Notifications\Model\Schedule;
use Icinga\Module\Notifications\Widget\Calendar\Controls;
use Icinga\Module\Notifications\Widget\RecipientSuggestions;
use Icinga\Module\Notifications\Widget\Schedule as ScheduleWidget;
use ipl\Html\Form;
Expand Down Expand Up @@ -37,20 +37,30 @@ public function indexAction(): void
$this->addTitleTab(sprintf(t('Schedule: %s'), $schedule->name));

$this->controls->addHtml(
Html::tag('h2', null, $schedule->name),
(new ButtonLink(
null,
Links::scheduleSettings($id),
'cog'
))->openInModal(),
(new ButtonLink(
$this->translate('Add Rotation'),
Links::rotationAdd($id),
'plus'
))->openInModal()
);

$this->controls->addAttributes(['class' => 'schedule-controls']);
$this->controls->addAttributes(['class' => 'schedule-detail-controls']);

$calendarControls = (new Controls())
$scheduleControls = (new ScheduleWidget\Controls())
->setAction(Url::fromRequest()->getAbsoluteUrl())
->populate(['mode' => $this->params->get('mode')])
->on(Form::ON_SUCCESS, function (ScheduleWidget\Controls $controls) use ($id) {
$this->redirectNow(Links::schedule($id)->with(['mode' => $controls->getMode()]));
})
->handleRequest($this->getServerRequest());

$this->addContent(new ScheduleWidget($calendarControls, $schedule));
$this->addContent(new ScheduleWidget($schedule, $scheduleControls));
}

public function settingsAction(): void
Expand Down Expand Up @@ -99,24 +109,15 @@ public function addAction(): void
$this->addContent($form);
}

public function addEntryAction(): void
public function addRotationAction(): void
{
$scheduleId = (int) $this->params->getRequired('schedule');
$start = $this->params->get('start');

$form = new EntryForm();
$form->setAction($this->getRequest()->getUrl()->getAbsoluteUrl());
$form = new RotationConfigForm($scheduleId, Database::get());
$form->setAction($this->getRequest()->getUrl()->setParam('showCompact')->getAbsoluteUrl());
$form->setSuggestionUrl(Url::fromPath('notifications/schedule/suggest-recipient'));
$form->populate(['when' => ['start' => $start]]);
$form->on(EntryForm::ON_SUCCESS, function ($form) use ($scheduleId) {
$form->addEntry($scheduleId);
$this->sendExtraUpdates(['#col2']);
$this->redirectNow('__CLOSE__');
});
$form->on(EntryForm::ON_SENT, function () use ($form) {
if ($form->hasBeenCancelled()) {
$this->redirectNow('__CLOSE__');
} elseif (! $form->hasBeenSubmitted()) {
$form->on(RotationConfigForm::ON_SENT, function ($form) {
if (! $form->hasBeenSubmitted()) {
foreach ($form->getPartUpdates() as $update) {
if (! is_array($update)) {
$update = [$update];
Expand All @@ -126,44 +127,42 @@ public function addEntryAction(): void
}
}
});
$form->on(RotationConfigForm::ON_SUCCESS, function (RotationConfigForm $form) use ($scheduleId) {
$form->addRotation();
$this->closeModalAndRefreshRelatedView(Links::schedule($scheduleId));
});

$form->handleRequest($this->getServerRequest());

if (empty($this->parts)) {
$this->addPart(Html::tag(
'div',
['id' => $this->getRequest()->getHeader('X-Icinga-Container')],
[
Html::tag('h2', null, $this->translate('Add Entry')),
$form
]
));
$this->setTitle($this->translate('Add Rotation'));
$this->addContent($form);
}
}

public function editEntryAction(): void
public function editRotationAction(): void
{
$entryId = (int) $this->params->getRequired('id');
$id = (int) $this->params->getRequired('id');
$scheduleId = (int) $this->params->getRequired('schedule');

$form = new EntryForm();
$form = new RotationConfigForm($scheduleId, Database::get());
$form->disableModeSelection();
$form->setShowRemoveButton();
$form->loadEntry($scheduleId, $entryId);
$form->loadRotation($id);
$form->setSubmitLabel($this->translate('Save Changes'));
$form->setAction($this->getRequest()->getUrl()->getAbsoluteUrl());
$form->setAction($this->getRequest()->getUrl()->setParam('showCompact')->getAbsoluteUrl());
$form->setSuggestionUrl(Url::fromPath('notifications/schedule/suggest-recipient'));
$form->on(EntryForm::ON_SUCCESS, function () use ($form, $entryId, $scheduleId) {
$form->editEntry($scheduleId, $entryId);
$this->sendExtraUpdates(['#col2']);
$this->redirectNow('__CLOSE__');
$form->on(RotationConfigForm::ON_SUCCESS, function (RotationConfigForm $form) use ($id, $scheduleId) {
$form->editRotation($id);
$this->closeModalAndRefreshRelatedView(Links::schedule($scheduleId));
});
$form->on(EntryForm::ON_SENT, function ($form) use ($entryId, $scheduleId) {
if ($form->hasBeenCancelled()) {
$this->redirectNow('__CLOSE__');
} elseif ($form->hasBeenRemoved()) {
$form->removeEntry($scheduleId, $entryId);
$this->sendExtraUpdates(['#col2']);
$this->redirectNow('__CLOSE__');
$form->on(RotationConfigForm::ON_SENT, function (RotationConfigForm $form) use ($id, $scheduleId) {
if ($form->hasBeenRemoved()) {
$form->removeRotation($id);
$this->closeModalAndRefreshRelatedView(Links::schedule($scheduleId));
} elseif ($form->hasBeenWiped()) {
$form->wipeRotation();
$this->closeModalAndRefreshRelatedView(Links::schedule($scheduleId));
} elseif (! $form->hasBeenSubmitted()) {
foreach ($form->getPartUpdates() as $update) {
if (! is_array($update)) {
Expand All @@ -178,17 +177,25 @@ public function editEntryAction(): void
$form->handleRequest($this->getServerRequest());

if (empty($this->parts)) {
$this->addPart(Html::tag(
'div',
['id' => $this->getRequest()->getHeader('X-Icinga-Container')],
[
Html::tag('h2', null, $this->translate('Edit Entry')),
$form
]
));
$this->setTitle($this->translate('Edit Rotation'));
$this->addContent($form);
}
}

public function moveRotationAction(): void
{
$this->assertHttpMethod('POST');

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

$form->handleRequest($this->getServerRequest());

$this->addContent($form);
}

public function suggestRecipientAction(): void
{
$suggestions = new RecipientSuggestions();
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/SchedulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function indexAction(): void
$this->addControl($sortControl);
$this->addControl($limitControl);
$this->addControl($searchBar);
$this->addControl(
$this->addContent(
(new ButtonLink(
t('New Schedule'),
Links::scheduleAdd(),
Expand Down
Loading

0 comments on commit 5c3e0e0

Please sign in to comment.