Autorefresh: should work also on initial page load

fixes #6296
This commit is contained in:
Thomas Gelf 2014-06-21 01:54:32 +02:00
parent e2f7a1054e
commit 216c2ca770
5 changed files with 31 additions and 56 deletions

View File

@ -30,6 +30,8 @@
use \Icinga\Web\Controller\BaseConfigController;
use \Icinga\Web\Widget\Tab;
use \Icinga\Web\Widget\AlertMessageBox;
use Icinga\Web\Notification;
use Icinga\Application\Modules\Module;
use \Icinga\Web\Url;
use \Icinga\Application\Icinga;
use \Icinga\Application\Config as IcingaConfig;
@ -43,6 +45,7 @@ use \Icinga\Form\Config\LoggingForm;
use \Icinga\Form\Config\ConfirmRemovalForm;
use \Icinga\Config\PreservingIniWriter;
/**
* Application wide controller for application preferences
*/
@ -97,7 +100,7 @@ class ConfigController extends BaseConfigController
array(
'name' => 'modules',
'title' => 'Modules',
'url' => Url::fromPath('/config/moduleoverview')
'url' => Url::fromPath('/config/modules')
)
)
);
@ -149,11 +152,9 @@ class ConfigController extends BaseConfigController
/**
* Display the list of all modules
*/
public function moduleoverviewAction()
public function modulesAction()
{
$this->view->messageBox = new AlertMessageBox(true);
$this->view->tabs->activate('modules');
$this->view->modules = Icinga::app()->getModuleManager()->select()
->from('modules')
->order('enabled', 'desc')
@ -161,6 +162,19 @@ class ConfigController extends BaseConfigController
$this->render('module/overview');
}
public function moduleAction()
{
$name = $this->getParam('name');
$app = Icinga::app();
$manager = $app->getModuleManager();
if ($manager->hasInstalled($name)) {
$module = new Module($app, $name, $manager->getModuleDir($name));
$this->view->module = $module;
} else {
$this->view->module = false;
}
}
/**
* Enable a specific module provided by the 'name' param
*/
@ -171,8 +185,8 @@ class ConfigController extends BaseConfigController
try {
$manager->enableModule($module);
$manager->loadModule($module);
$this->addSuccessMessage('Module "' . $module . '" enabled');
$this->redirectNow('config/moduleoverview?_render=layout&_reload=css');
Notification::success('Module "' . $module . '" enabled');
$this->redirectNow('config/modules_render=layout&_reload=css');
return;
} catch (Exception $e) {
$this->view->exceptionMesssage = $e->getMessage();
@ -191,8 +205,8 @@ class ConfigController extends BaseConfigController
$manager = Icinga::app()->getModuleManager();
try {
$manager->disableModule($module);
$this->addSuccessMessage('Module "' . $module . '" disabled');
$this->redirectNow('config/moduleoverview?_render=layout&_reload=css');
Notification::success('Module "' . $module . '" disabled');
$this->redirectNow('config/modules?_render=layout&_reload=css');
return;
} catch (Exception $e) {
$this->view->exceptionMessage = $e->getMessage();

View File

@ -16,6 +16,11 @@ if ($moduleName) {
$moduleClass = '';
}
$refresh = '';
if ($this->layout()->autorefreshInterval) {
$refresh = ' data-icinga-refresh="' . $this->layout()->autorefreshInterval . '"';
}
$notifications = Notification::getInstance();
if ($notifications->hasMessages()) {
foreach ($notifications->getMessages() as $m) {
@ -31,7 +36,7 @@ if ($notifications->hasMessages()) {
<?php echo $this->render('parts/navigation.phtml') ?>
</div>
<div id="main" role="main">
<div id="col1" class="container<?= $moduleClass ?>"<?php if ($moduleName): ?> data-icinga-module="<?= $moduleName ?>" <?php endif ?> data-icinga-url="<?= Url::fromRequest() ?>" style="display: block">
<div id="col1" class="container<?= $moduleClass ?>"<?php if ($moduleName): ?> data-icinga-module="<?= $moduleName ?>" <?php endif ?> data-icinga-url="<?= Url::fromRequest() ?>"<?= $refresh ?> style="display: block">
<?= $this->render('inline.phtml') ?>
</div>
<div id="col2" class="container">

View File

@ -1,46 +0,0 @@
<?php
use Icinga\Web\Url;
$this->modules->limit(10);
$modules = $this->modules->paginate();
?>
<div class="controls">
<?= $this->tabs->render($this); ?>
</div>
<div class="content">
<h3>Installed Modules</h3>
<?php if (isset($this->messageBox)): ?>
<?= $this->messageBox->render() ?>
<?php endif ?>
<?= $this->paginationControl($modules, null, null, array(
'preserve' => $this->preserve
));
?>
<table class="action">
<tbody>
<? foreach ($modules as $module): ?>
<?php
$enableUrl = Url::fromPath('config/moduleenable/',array('name' => $module->name))->getAbsoluteUrl();
$disableUrl = Url::fromPath('config/moduledisable/',array('name' => $module->name))->getAbsoluteUrl();
?>
<tr>
<td>
<? if ($module->enabled): ?>
<i class="icinga-icon-success"></i>
<a href="<?= $disableUrl ?>" data-icinga-target="main"><?= $this->escape($module->name); ?></a>
<? else: ?>
<i class="icinga-icon-remove"></i>
<a href="<?= $enableUrl ?>" data-icinga-target="main"><?= $this->escape($module->name); ?></a>
<? endif ?>
(<?=
$module->enabled ? ($module->loaded ? 'enabled' : 'failed') : 'disabled' ?>)
</td>
</tr>
<? endforeach ?>
</tbody>
</table>
</div>

View File

@ -1,2 +1,2 @@
<h1>Welcome to Icinga!</h1>
You should install/configure some <a href="<?= $this->href('config/moduleoverview');?>">modules</a> now!
You should install/configure some <a href="<?= $this->href('config/modules');?>">modules</a> now!

View File

@ -328,12 +328,14 @@ class ActionController extends Zend_Controller_Action
);
}
$this->autorefreshInterval = $interval;
$this->_helper->layout()->autorefreshInterval = $interval;
return $this;
}
public function disableAutoRefresh()
{
$this->autorefreshInterval = null;
$this->_helper->layout()->autorefreshInterval = null;
return $this;
}