From 78193137f0687f5b445d3f07a006b67468263855 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sat, 21 Jun 2014 02:27:27 +0200 Subject: [PATCH] config/modules: show metadata, improve usability Well... I didn't want to commit this before creating single-button forms for enabling/disabling modules. However part of this accidentally made it through, so let's finish it. Still some work to do, but it already looks far better like this. refs #4095 --- application/controllers/ConfigController.php | 50 ++++++++++++------- application/views/scripts/config/module.phtml | 14 ++++++ .../views/scripts/config/modules.phtml | 30 ++++------- .../Icinga/Data/DataArray/ArrayDatasource.php | 9 ++++ public/js/icinga/history.js | 11 ++-- public/js/icinga/loader.js | 3 ++ 6 files changed, 74 insertions(+), 43 deletions(-) diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 932318ba9..9a17c7aae 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -27,23 +27,24 @@ */ // {{{ICINGA_LICENSE_HEADER}}} -use \Icinga\Web\Controller\BaseConfigController; -use \Icinga\Web\Widget\Tab; -use \Icinga\Web\Widget\AlertMessageBox; +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; -use \Icinga\Data\ResourceFactory; -use \Icinga\Form\Config\GeneralForm; -use \Icinga\Form\Config\Authentication\ReorderForm; -use \Icinga\Form\Config\Authentication\LdapBackendForm; -use \Icinga\Form\Config\Authentication\DbBackendForm; -use \Icinga\Form\Config\ResourceForm; -use \Icinga\Form\Config\LoggingForm; -use \Icinga\Form\Config\ConfirmRemovalForm; -use \Icinga\Config\PreservingIniWriter; +use Icinga\Web\Url; +use Icinga\Web\Widget; +use Icinga\Application\Icinga; +use Icinga\Application\Config as IcingaConfig; +use Icinga\Data\ResourceFactory; +use Icinga\Form\Config\GeneralForm; +use Icinga\Form\Config\Authentication\ReorderForm; +use Icinga\Form\Config\Authentication\LdapBackendForm; +use Icinga\Form\Config\Authentication\DbBackendForm; +use Icinga\Form\Config\ResourceForm; +use Icinga\Form\Config\LoggingForm; +use Icinga\Form\Config\ConfirmRemovalForm; +use Icinga\Config\PreservingIniWriter; /** @@ -158,8 +159,7 @@ class ConfigController extends BaseConfigController $this->view->modules = Icinga::app()->getModuleManager()->select() ->from('modules') ->order('enabled', 'desc') - ->order('name'); - $this->render('module/overview'); + ->order('name')->paginate(); } public function moduleAction() @@ -168,11 +168,17 @@ class ConfigController extends BaseConfigController $app = Icinga::app(); $manager = $app->getModuleManager(); if ($manager->hasInstalled($name)) { + $this->view->moduleData = Icinga::app()->getModuleManager()->select() + ->from('modules')->where('name', $name)->fetchRow(); $module = new Module($app, $name, $manager->getModuleDir($name)); $this->view->module = $module; } else { $this->view->module = false; } + $this->view->tabs = Widget::create('tabs')->add('info', array( + 'url' => Url::fromRequest(), + 'title' => 'Module info' + ))->activate('info'); } /** @@ -186,7 +192,10 @@ class ConfigController extends BaseConfigController $manager->enableModule($module); $manager->loadModule($module); Notification::success('Module "' . $module . '" enabled'); - $this->redirectNow('config/modules_render=layout&_reload=css'); + $this->redirectNow(Url::fromPath('config/modules', array( + '_render' => 'layout', + '_reload' => 'css' + ))); return; } catch (Exception $e) { $this->view->exceptionMesssage = $e->getMessage(); @@ -206,7 +215,10 @@ class ConfigController extends BaseConfigController try { $manager->disableModule($module); Notification::success('Module "' . $module . '" disabled'); - $this->redirectNow('config/modules?_render=layout&_reload=css'); + $this->redirectNow(Url::fromPath('config/modules', array( + '_render' => 'layout', + '_reload' => 'css' + ))); return; } catch (Exception $e) { $this->view->exceptionMessage = $e->getMessage(); diff --git a/application/views/scripts/config/module.phtml b/application/views/scripts/config/module.phtml index ceb14feb2..8b82b02be 100644 --- a/application/views/scripts/config/module.phtml +++ b/application/views/scripts/config/module.phtml @@ -9,6 +9,7 @@ $dependencies = $module->getDependencies(); $restrictions = $module->getProvidedRestrictions(); $permissions = $module->getProvidedPermissions(); +$state = $moduleData->enabled ? ($moduleData->loaded ? 'enabled' : 'failed') : 'disabled' ?>

escape($module->getTitle()) ?>

@@ -17,6 +18,19 @@ $permissions = $module->getProvidedPermissions(); escape('Name') ?> escape($module->getName()) ?> + + translate('State') ?> + + qlink('disable', 'config/moduledisable', array( + 'name' => $module->getName() + )) ?> + + + qlink('enable', 'config/moduleenable', array( + 'name' => $module->getName() + )) ?> + + escape('Version') ?> escape($module->getVersion()) ?> diff --git a/application/views/scripts/config/modules.phtml b/application/views/scripts/config/modules.phtml index b4210d4d4..086d0a61a 100644 --- a/application/views/scripts/config/modules.phtml +++ b/application/views/scripts/config/modules.phtml @@ -1,25 +1,10 @@ -modules->limit(10); -$modules = $this->modules->paginate(); - -?>
-tabs->render($this); ?> +tabs ?> +

Installed Modules

+paginationControl($modules) ?>
-

Installed Modules

- -messageBox)): ?> - messageBox->render() ?> - - -paginationControl($modules, null, null, array( - 'preserve' => $this->preserve -)); -?> @@ -30,9 +15,12 @@ $modules = $this->modules->paginate(); icon('remove.png', 'Module is disabled') ?> - escape($module->name); ?> - (enabled ? ($module->loaded ? 'enabled' : 'failed') : 'disabled' ?>) + escape($module->name); ?> (enabled ? ($module->loaded ? 'enabled' : 'failed') : 'disabled' + ?>) diff --git a/library/Icinga/Data/DataArray/ArrayDatasource.php b/library/Icinga/Data/DataArray/ArrayDatasource.php index 55dc597f0..dd5aa9d27 100644 --- a/library/Icinga/Data/DataArray/ArrayDatasource.php +++ b/library/Icinga/Data/DataArray/ArrayDatasource.php @@ -57,6 +57,15 @@ class ArrayDatasource implements Selectable return $result; } + public function fetchRow(SimpleQuery $query) + { + $result = $this->getResult($query); + if (empty($result)) { + return false; + } + return $result[0]; + } + public function fetchAll(SimpleQuery $query) { return $this->getResult($query); diff --git a/public/js/icinga/history.js b/public/js/icinga/history.js index de3505e74..121bfbb17 100644 --- a/public/js/icinga/history.js +++ b/public/js/icinga/history.js @@ -71,7 +71,6 @@ icinga.logger.debug('Pushing current state to history'); var url = ''; - var blacklist = ['_render', '_reload']; // We only store URLs of containers sitting directly under #main: $('#main > .container').each(function (idx, container) { @@ -90,7 +89,7 @@ // Did we find any URL? Then push it! if (url !== '') { - window.history.pushState({icinga: true}, null, url); + window.history.pushState({icinga: true}, null, this.cleanupUrl(url)); } }, @@ -99,7 +98,13 @@ if (!this.enabled) { return; } - window.history.pushState({icinga: true}, null, url); + window.history.pushState({icinga: true}, null, this.cleanupUrl(url)); + }, + + cleanupUrl: function(url) { + url = url.replace(/_render=[a-z0-9]+&/, '').replace(/&_render=[a-z0-9]+/, '').replace(/\?_render=[a-z0-9]+$/, ''); + url = url.replace(/_reload=[a-z0-9]+&/, '').replace(/&_reload=[a-z0-9]+/, '').replace(/\?_reload=[a-z0-9]+$/, ''); + return url; }, /** diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js index a7e802216..384a75348 100644 --- a/public/js/icinga/loader.js +++ b/public/js/icinga/loader.js @@ -343,6 +343,9 @@ delete this.requests[req.$target.attr('id')]; req.$target = $('#' + target); + + // We assume target === 'layout' right now. This might not be correct + this.icinga.ui.layout1col(); newBody = true; }