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
This commit is contained in:
Thomas Gelf 2014-05-26 14:41:47 +00:00
parent 4f1b7f16e4
commit 70ba36aad6
3 changed files with 30 additions and 8 deletions

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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();