Skip to content

Commit 5c3e0e0

Browse files
authored
Schedule redesign (#183)
resolves #177 **Requirements** * Icinga/ipl-html#137 * Icinga/ipl-web#223 * Icinga/icinga-notifications#204
2 parents 659cc5e + 9247d7c commit 5c3e0e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4479
-1596
lines changed

application/controllers/ScheduleController.php

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
use Icinga\Module\Notifications\Common\Database;
88
use Icinga\Module\Notifications\Common\Links;
9-
use Icinga\Module\Notifications\Forms\EntryForm;
9+
use Icinga\Module\Notifications\Forms\MoveRotationForm;
10+
use Icinga\Module\Notifications\Forms\RotationConfigForm;
1011
use Icinga\Module\Notifications\Forms\ScheduleForm;
1112
use Icinga\Module\Notifications\Model\Schedule;
12-
use Icinga\Module\Notifications\Widget\Calendar\Controls;
1313
use Icinga\Module\Notifications\Widget\RecipientSuggestions;
1414
use Icinga\Module\Notifications\Widget\Schedule as ScheduleWidget;
1515
use ipl\Html\Form;
@@ -37,20 +37,30 @@ public function indexAction(): void
3737
$this->addTitleTab(sprintf(t('Schedule: %s'), $schedule->name));
3838

3939
$this->controls->addHtml(
40+
Html::tag('h2', null, $schedule->name),
4041
(new ButtonLink(
4142
null,
4243
Links::scheduleSettings($id),
4344
'cog'
45+
))->openInModal(),
46+
(new ButtonLink(
47+
$this->translate('Add Rotation'),
48+
Links::rotationAdd($id),
49+
'plus'
4450
))->openInModal()
4551
);
4652

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

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

53-
$this->addContent(new ScheduleWidget($calendarControls, $schedule));
63+
$this->addContent(new ScheduleWidget($schedule, $scheduleControls));
5464
}
5565

5666
public function settingsAction(): void
@@ -99,24 +109,15 @@ public function addAction(): void
99109
$this->addContent($form);
100110
}
101111

102-
public function addEntryAction(): void
112+
public function addRotationAction(): void
103113
{
104114
$scheduleId = (int) $this->params->getRequired('schedule');
105-
$start = $this->params->get('start');
106115

107-
$form = new EntryForm();
108-
$form->setAction($this->getRequest()->getUrl()->getAbsoluteUrl());
116+
$form = new RotationConfigForm($scheduleId, Database::get());
117+
$form->setAction($this->getRequest()->getUrl()->setParam('showCompact')->getAbsoluteUrl());
109118
$form->setSuggestionUrl(Url::fromPath('notifications/schedule/suggest-recipient'));
110-
$form->populate(['when' => ['start' => $start]]);
111-
$form->on(EntryForm::ON_SUCCESS, function ($form) use ($scheduleId) {
112-
$form->addEntry($scheduleId);
113-
$this->sendExtraUpdates(['#col2']);
114-
$this->redirectNow('__CLOSE__');
115-
});
116-
$form->on(EntryForm::ON_SENT, function () use ($form) {
117-
if ($form->hasBeenCancelled()) {
118-
$this->redirectNow('__CLOSE__');
119-
} elseif (! $form->hasBeenSubmitted()) {
119+
$form->on(RotationConfigForm::ON_SENT, function ($form) {
120+
if (! $form->hasBeenSubmitted()) {
120121
foreach ($form->getPartUpdates() as $update) {
121122
if (! is_array($update)) {
122123
$update = [$update];
@@ -126,44 +127,42 @@ public function addEntryAction(): void
126127
}
127128
}
128129
});
130+
$form->on(RotationConfigForm::ON_SUCCESS, function (RotationConfigForm $form) use ($scheduleId) {
131+
$form->addRotation();
132+
$this->closeModalAndRefreshRelatedView(Links::schedule($scheduleId));
133+
});
129134

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

132137
if (empty($this->parts)) {
133-
$this->addPart(Html::tag(
134-
'div',
135-
['id' => $this->getRequest()->getHeader('X-Icinga-Container')],
136-
[
137-
Html::tag('h2', null, $this->translate('Add Entry')),
138-
$form
139-
]
140-
));
138+
$this->setTitle($this->translate('Add Rotation'));
139+
$this->addContent($form);
141140
}
142141
}
143142

144-
public function editEntryAction(): void
143+
public function editRotationAction(): void
145144
{
146-
$entryId = (int) $this->params->getRequired('id');
145+
$id = (int) $this->params->getRequired('id');
147146
$scheduleId = (int) $this->params->getRequired('schedule');
148147

149-
$form = new EntryForm();
148+
$form = new RotationConfigForm($scheduleId, Database::get());
149+
$form->disableModeSelection();
150150
$form->setShowRemoveButton();
151-
$form->loadEntry($scheduleId, $entryId);
151+
$form->loadRotation($id);
152152
$form->setSubmitLabel($this->translate('Save Changes'));
153-
$form->setAction($this->getRequest()->getUrl()->getAbsoluteUrl());
153+
$form->setAction($this->getRequest()->getUrl()->setParam('showCompact')->getAbsoluteUrl());
154154
$form->setSuggestionUrl(Url::fromPath('notifications/schedule/suggest-recipient'));
155-
$form->on(EntryForm::ON_SUCCESS, function () use ($form, $entryId, $scheduleId) {
156-
$form->editEntry($scheduleId, $entryId);
157-
$this->sendExtraUpdates(['#col2']);
158-
$this->redirectNow('__CLOSE__');
155+
$form->on(RotationConfigForm::ON_SUCCESS, function (RotationConfigForm $form) use ($id, $scheduleId) {
156+
$form->editRotation($id);
157+
$this->closeModalAndRefreshRelatedView(Links::schedule($scheduleId));
159158
});
160-
$form->on(EntryForm::ON_SENT, function ($form) use ($entryId, $scheduleId) {
161-
if ($form->hasBeenCancelled()) {
162-
$this->redirectNow('__CLOSE__');
163-
} elseif ($form->hasBeenRemoved()) {
164-
$form->removeEntry($scheduleId, $entryId);
165-
$this->sendExtraUpdates(['#col2']);
166-
$this->redirectNow('__CLOSE__');
159+
$form->on(RotationConfigForm::ON_SENT, function (RotationConfigForm $form) use ($id, $scheduleId) {
160+
if ($form->hasBeenRemoved()) {
161+
$form->removeRotation($id);
162+
$this->closeModalAndRefreshRelatedView(Links::schedule($scheduleId));
163+
} elseif ($form->hasBeenWiped()) {
164+
$form->wipeRotation();
165+
$this->closeModalAndRefreshRelatedView(Links::schedule($scheduleId));
167166
} elseif (! $form->hasBeenSubmitted()) {
168167
foreach ($form->getPartUpdates() as $update) {
169168
if (! is_array($update)) {
@@ -178,17 +177,25 @@ public function editEntryAction(): void
178177
$form->handleRequest($this->getServerRequest());
179178

180179
if (empty($this->parts)) {
181-
$this->addPart(Html::tag(
182-
'div',
183-
['id' => $this->getRequest()->getHeader('X-Icinga-Container')],
184-
[
185-
Html::tag('h2', null, $this->translate('Edit Entry')),
186-
$form
187-
]
188-
));
180+
$this->setTitle($this->translate('Edit Rotation'));
181+
$this->addContent($form);
189182
}
190183
}
191184

185+
public function moveRotationAction(): void
186+
{
187+
$this->assertHttpMethod('POST');
188+
189+
$form = new MoveRotationForm(Database::get());
190+
$form->on(MoveRotationForm::ON_SUCCESS, function (MoveRotationForm $form) {
191+
$this->redirectNow(Links::schedule($form->getScheduleId()));
192+
});
193+
194+
$form->handleRequest($this->getServerRequest());
195+
196+
$this->addContent($form);
197+
}
198+
192199
public function suggestRecipientAction(): void
193200
{
194201
$suggestions = new RecipientSuggestions();

application/controllers/SchedulesController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function indexAction(): void
5959
$this->addControl($sortControl);
6060
$this->addControl($limitControl);
6161
$this->addControl($searchBar);
62-
$this->addControl(
62+
$this->addContent(
6363
(new ButtonLink(
6464
t('New Schedule'),
6565
Links::scheduleAdd(),

0 commit comments

Comments
 (0)