From 70ba36aad66bf44d8fbb4b9863c1e31dd5b5201a Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 26 May 2014 14:41:47 +0000 Subject: [PATCH] notifications: improve client- and serverside This is just a first step, trying to catch a few gotchas: * it doesn't send notifications to the browser when issueing a redirect as redirects can currently not be catched in jQuery response handlers * it tries to find a better notification handling place in the response handler (JS) - still imperfect * it explicitely stores sessions once modified by notifications. Still need to crosscheck whether this is really needed and how we can get rid of this. refs #6280 --- .../Web/Controller/ActionController.php | 5 ++- library/Icinga/Web/Notification.php | 2 ++ public/js/icinga/loader.js | 31 ++++++++++++++----- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/library/Icinga/Web/Controller/ActionController.php b/library/Icinga/Web/Controller/ActionController.php index 5893a3c3f..889be721c 100644 --- a/library/Icinga/Web/Controller/ActionController.php +++ b/library/Icinga/Web/Controller/ActionController.php @@ -81,6 +81,8 @@ class ActionController extends Zend_Controller_Action private $windowId; + protected $isRedirect = false; + // TODO: This would look better if we had a ModuleActionController public function Config($file = null) { @@ -371,6 +373,7 @@ class ActionController extends Zend_Controller_Action $url = Url::fromPath($url)->getRelativeUrl(); } $this->_helper->Redirector->gotoUrlAndExit(preg_replace('~&~', '&', $url)); + $this->isRedirect = true; } /** @@ -412,7 +415,7 @@ class ActionController extends Zend_Controller_Action } $notifications = Notification::getInstance(); - if ($isXhr && $notifications->hasMessages()) { + if ($isXhr && ! $this->isRedirect && $notifications->hasMessages()) { foreach ($notifications->getMessages() as $m) { header('X-Icinga-Notification: ' . $m->type . ' ' . $m->message); } diff --git a/library/Icinga/Web/Notification.php b/library/Icinga/Web/Notification.php index 6a29cfc3f..941654277 100644 --- a/library/Icinga/Web/Notification.php +++ b/library/Icinga/Web/Notification.php @@ -112,6 +112,7 @@ class Notification $msgs = $session->messages; $msgs[] = $mo; $session->messages = $msgs; + $session->write(); } public function hasMessages() @@ -125,6 +126,7 @@ class Notification $session = Session::getSession(); $msgs = $session->messages; $session->messages = array(); + $session->write(); return $msgs; } diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js index ead489be7..d3343c75c 100644 --- a/public/js/icinga/loader.js +++ b/public/js/icinga/loader.js @@ -287,13 +287,6 @@ } var notifications = req.getResponseHeader('X-Icinga-Notification'); - if (notifications) { - var parts = notifications.split(' '); - this.createNotice( - parts.shift(), - parts.join(' ') - ); - } // var target = req.getResponseHeader('X-Icinga-Container'); @@ -310,6 +303,14 @@ newBody = true; } + if (! newBody && notifications) { + var parts = notifications.split(' '); + this.createNotice( + parts.shift(), + parts.join(' ') + ); + } + var moduleName = req.getResponseHeader('X-Icinga-Module'); classes = $.grep(req.$target.classes(), function (el) { if (el === 'icinga-module' || el.match(/^module\-/)) { @@ -424,6 +425,14 @@ */ if (rendered) { + + if (newBody && notifications) { + var parts = notifications.split(' '); + this.createNotice( + parts.shift(), + parts.join(' ') + ); + } return; } @@ -435,6 +444,14 @@ if (newBody) { this.icinga.ui.fixDebugVisibility().triggerWindowResize(); } + if (newBody && notifications) { + var parts = notifications.split(' '); + this.createNotice( + parts.shift(), + parts.join(' ') + ); + } + if (active) { var focusedUrl = this.icinga.ui.getFocusedContainerDataUrl();