diff --git a/application/controllers/ReportController.php b/application/controllers/ReportController.php index 8371382c..2c597b82 100644 --- a/application/controllers/ReportController.php +++ b/application/controllers/ReportController.php @@ -5,6 +5,7 @@ namespace Icinga\Module\Reporting\Controllers; use Icinga\Application\Hook; +use Icinga\Application\Version; use Icinga\Module\Pdfexport\ProvidedHook\Pdfexport; use Icinga\Module\Reporting\Database; use Icinga\Module\Reporting\Model; @@ -89,7 +90,12 @@ public function cloneAction() ->setAction((string) Url::fromRequest()) ->populate($values) ->on(ReportForm::ON_SUCCESS, function () { - $this->redirectNow('__CLOSE__'); + Notification::success($this->translate('Cloned report successfully')); + + // Refresh the col1 container after cloning a report + $this->sendExtraUpdates(['#col1']); + + $this->redirectNow("reporting/report?id={$this->report->getId()}"); }) ->handleRequest($this->getServerRequest()); @@ -119,7 +125,26 @@ public function editAction() $form = ReportForm::fromId($this->report->getId()) ->setAction((string) Url::fromRequest()) ->populate($values) - ->on(ReportForm::ON_SUCCESS, function () { + ->on(ReportForm::ON_SUCCESS, function (ReportForm $form) { + $extraUpdates = ['#col1']; + if ($form->getPressedSubmitElement()->getName() === 'remove') { + $extraUpdates['col2'] = '__CLOSE__'; + + Notification::success($this->translate('Removed report successfully')); + } else { + if ($this->params->shift('fromCol1', false) === false) { + $extraUpdates[] = '#col2'; + } + + Notification::success($this->translate('Updated report successfully')); + } + + // Older Icinga Web 2 versions close the #col2 container automatically when redirecting using CLOSE. + // So, we need to send the extra updates only when using Icinga Web 2.12 or newer. + if (version_compare(Version::VERSION, '2.12', '>=')) { + $this->sendExtraUpdates($extraUpdates); + } + $this->redirectNow('__CLOSE__'); }) ->handleRequest($this->getServerRequest()); diff --git a/application/controllers/ReportsController.php b/application/controllers/ReportsController.php index f1c60e61..567c7676 100644 --- a/application/controllers/ReportsController.php +++ b/application/controllers/ReportsController.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Reporting\Controllers; +use Icinga\Application\Version; use Icinga\Module\Icingadb\ProvidedHook\Reporting\HostSlaReport; use Icinga\Module\Icingadb\ProvidedHook\Reporting\ServiceSlaReport; use Icinga\Module\Reporting\Database; @@ -11,6 +12,7 @@ use Icinga\Module\Reporting\Web\Controller; use Icinga\Module\Reporting\Web\Forms\ReportForm; use Icinga\Module\Reporting\Web\ReportsTimeframesAndTemplatesTabs; +use Icinga\Web\Notification; use ipl\Html\Html; use ipl\Web\Url; use ipl\Web\Widget\ButtonLink; @@ -67,7 +69,7 @@ public function indexAction() Html::tag('td', ['class' => 'icon-col'], [ new Link( new Icon('edit'), - Url::fromPath('reporting/report/edit', ['id' => $report->id]), + Url::fromPath('reporting/report/edit', ['fromCol1' => true, 'id' => $report->id]), [ 'data-icinga-modal' => true, 'data-no-icinga-ajax' => true @@ -132,7 +134,13 @@ public function newAction() 'reportlet' => $class ]) ->on(ReportForm::ON_SUCCESS, function () { - $this->getResponse()->setHeader('X-Icinga-Container', 'modal-content', true); + Notification::success($this->translate('Created report successfully')); + + if (version_compare(Version::VERSION, '2.12.0', '<')) { + // Former Icinga Web 2 versions don't refresh the modal openers container when + // redirecting using __CLOSE__. + $this->sendExtraUpdates(['#col1']); + } $this->redirectNow('__CLOSE__'); }) diff --git a/application/controllers/TemplateController.php b/application/controllers/TemplateController.php index e8cebb0b..26dbeb2d 100644 --- a/application/controllers/TemplateController.php +++ b/application/controllers/TemplateController.php @@ -7,12 +7,14 @@ use DateTime; use Exception; use GuzzleHttp\Psr7\ServerRequest; +use Icinga\Application\Version; use Icinga\Module\Reporting\Database; use Icinga\Module\Reporting\Model; use Icinga\Module\Reporting\Web\Controller; use Icinga\Module\Reporting\Web\Forms\TemplateForm; use Icinga\Module\Reporting\Web\Widget\Template; use Icinga\Web\Notification; +use ipl\Html\Form; use ipl\Stdlib\Filter; use ipl\Web\Url; @@ -62,8 +64,21 @@ public function editAction() $form = TemplateForm::fromTemplate($template) ->setAction((string) Url::fromRequest()) - ->on(TemplateForm::ON_SUCCESS, function () { - Notification::success($this->translate('Updated template successfully')); + ->on(TemplateForm::ON_SUCCESS, function (Form $form) { + $extraUpdates = ['#col1']; + if ($form->getPressedSubmitElement()->getName() === 'remove') { + Notification::success($this->translate('Removed template successfully')); + + $extraUpdates['col2'] = '__CLOSE__'; + } else { + Notification::success($this->translate('Updated template successfully')); + } + + // Older Icinga Web 2 versions close #col2 container automatically when redirecting using close. + // So, we need to send the extra updates only when using Icinga Web 2.12 or newer. + if (version_compare(Version::VERSION, '2.12', '>=')) { + $this->sendExtraUpdates($extraUpdates); + } $this->redirectNow('__CLOSE__'); }) diff --git a/application/controllers/TemplatesController.php b/application/controllers/TemplatesController.php index e300c53a..eee39c22 100644 --- a/application/controllers/TemplatesController.php +++ b/application/controllers/TemplatesController.php @@ -115,9 +115,7 @@ public function newAction() ->on(TemplateForm::ON_SUCCESS, function () { Notification::success($this->translate('Created template successfully')); - $this->getResponse()->setHeader('X-Icinga-Container', 'modal-content', true); - - $this->redirectNow('__CLOSE__'); + $this->redirectNow('reporting/templates'); }) ->handleRequest($this->getServerRequest()); diff --git a/application/controllers/TimeframeController.php b/application/controllers/TimeframeController.php index 667d5bf9..88783834 100644 --- a/application/controllers/TimeframeController.php +++ b/application/controllers/TimeframeController.php @@ -10,6 +10,8 @@ use Icinga\Module\Reporting\Timeframe; use Icinga\Module\Reporting\Web\Controller; use Icinga\Module\Reporting\Web\Forms\TimeframeForm; +use Icinga\Web\Notification; +use ipl\Html\Form; use ipl\Web\Url; use ipl\Stdlib\Filter; @@ -47,10 +49,14 @@ public function editAction() $form = TimeframeForm::fromId($this->timeframe->getId()) ->setAction((string) Url::fromRequest()) ->populate($values) - ->on(TimeframeForm::ON_SUCCESS, function () { - $this->getResponse()->setHeader('X-Icinga-Container', 'modal-content', true); + ->on(TimeframeForm::ON_SUCCESS, function (Form $form) { + if ($form->getPressedSubmitElement()->getName() === 'remove') { + Notification::success($this->translate('Removed timeframe successfully')); + } else { + Notification::success($this->translate('Update timeframe successfully')); + } - $this->redirectNow('__CLOSE__'); + $this->redirectNow('reporting/timeframes'); })->handleRequest($this->getServerRequest()); $this->addContent($form); diff --git a/application/controllers/TimeframesController.php b/application/controllers/TimeframesController.php index 698f16c7..1c4de05b 100644 --- a/application/controllers/TimeframesController.php +++ b/application/controllers/TimeframesController.php @@ -9,6 +9,7 @@ use Icinga\Module\Reporting\Web\Controller; use Icinga\Module\Reporting\Web\Forms\TimeframeForm; use Icinga\Module\Reporting\Web\ReportsTimeframesAndTemplatesTabs; +use Icinga\Web\Notification; use ipl\Html\Html; use ipl\Web\Url; use ipl\Web\Widget\ButtonLink; @@ -116,9 +117,9 @@ public function newAction() $form = (new TimeframeForm()) ->setAction((string) Url::fromRequest()) ->on(TimeframeForm::ON_SUCCESS, function () { - $this->getResponse()->setHeader('X-Icinga-Container', 'modal-content', true); + Notification::success($this->translate('Created timeframe successfully')); - $this->redirectNow('__CLOSE__'); + $this->redirectNow('reporting/timeframes'); })->handleRequest($this->getServerRequest()); $this->addContent($form);