Merge branch 'feature/configuration-and-preferences-controller-4530'

resolves #4530
This commit is contained in:
Eric Lippmann 2013-08-14 16:09:20 +02:00
commit 3306d3e3c0
33 changed files with 978 additions and 325 deletions

View File

@ -26,7 +26,7 @@
# namespace Icinga\Application\Controllers; # namespace Icinga\Application\Controllers;
use Icinga\Web\ActionController; use Icinga\Web\Controller\ActionController;
use Icinga\Authentication\Credentials; use Icinga\Authentication\Credentials;
use Icinga\Authentication\Manager as AuthManager; use Icinga\Authentication\Manager as AuthManager;
use Icinga\Form\Authentication\LoginForm; use Icinga\Form\Authentication\LoginForm;

View File

@ -0,0 +1,112 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
/**
* Icinga 2 Web - Head for multiple monitoring frontends
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Application\Benchmark;
use Icinga\Authentication\Manager;
use Icinga\Web\Controller\BaseConfigController;
use Icinga\Web\Widget\Tab;
use Icinga\Web\Url;
use Icinga\Web\Hook\Configuration\ConfigurationTabBuilder;
use Icinga\Application\Icinga;
/**
* Application wide controller for application preferences
*
*/
class ConfigController extends BaseConfigController
{
/**
* Create tabs for this configuration controller
*
* @return array
* @see BaseConfigController::createProvidedTabs
*/
public static function createProvidedTabs()
{
return array(
"index" => new Tab(
array(
"name" => "index",
"title" => "Configuration",
"iconCls" => "wrench",
"url" => Url::fromPath("/config")
)
),
"modules" => new Tab(
array(
"name" => "modules",
"title" => "Modules",
"iconCls" => "puzzle-piece",
"url" => Url::fromPath("/config/moduleoverview")
)
)
);
}
/**
* Index action, entry point for configuration
* @TODO: Implement configuration interface (#3777)
*/
public function indexAction()
{
}
/**
* Display the list of all modules
*/
public function moduleoverviewAction()
{
$this->view->modules = Icinga::app()->getModuleManager()->select()
->from('modules')
->order('name');
$this->render('module/overview');
}
/**
* Enable a specific module provided by the 'name' param
*/
public function moduleenableAction()
{
$manager = Icinga::app()->getModuleManager();
$manager->enableModule($this->_getParam('name'));
$manager->loadModule($this->_getParam('name'));
$this->redirectNow('config/moduleoverview?_render=body');
}
/**
* Disable a module specific module provided by the 'name' param
*/
public function moduledisableAction()
{
$manager = Icinga::app()->getModuleManager();
$manager->disableModule($this->_getParam('name'));
$this->redirectNow('config/moduleoverview?_render=body');
}
}
// @codingStandardsIgnoreEnd

View File

@ -27,7 +27,7 @@
*/ */
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Web\ActionController; use Icinga\Web\Controller\ActionController;
use Icinga\Web\Url; use Icinga\Web\Url;
use Icinga\Application\Icinga; use Icinga\Application\Icinga;
use Icinga\Web\Widget\Dashboard; use Icinga\Web\Widget\Dashboard;

View File

@ -26,7 +26,7 @@
# namespace Icinga\Application\Controllers; # namespace Icinga\Application\Controllers;
use Icinga\Web\ActionController; use Icinga\Web\Controller\ActionController;
/** /**
* Class ErrorController * Class ErrorController

View File

@ -29,7 +29,7 @@
# namespace Icinga\Application\Controllers; # namespace Icinga\Application\Controllers;
use Icinga\Web\ActionController; use Icinga\Web\Controller\ActionController;
use Icinga\Application\Icinga; use Icinga\Application\Icinga;
/** /**
@ -38,6 +38,7 @@ use Icinga\Application\Icinga;
*/ */
class IndexController extends ActionController class IndexController extends ActionController
{ {
/** /**
* @var bool * @var bool
*/ */

View File

@ -1,107 +0,0 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
# namespace Icinga\Application\Controllers;
use Icinga\Web\ActionController;
use Icinga\Application\Icinga;
use Icinga\Web\Hook\Configuration\ConfigurationTabBuilder;
use Icinga\Web\Widget\Tabs;
/**
* Handle module depending frontend actions
*/
class ModulesController extends ActionController
{
/**
* @var ModuleManager
*/
protected $manager;
/**
* Setup this controller
* @see ZfActionController::init
*/
public function init()
{
$this->manager = Icinga::app()->getModuleManager();
}
/**
* Display a list of all modules
*/
public function indexAction()
{
$tabBuilder = new ConfigurationTabBuilder(new Tabs());
$tabBuilder->build();
$this->view->tabs = $tabBuilder->getTabs();
$this->view->modules = $this->manager->select()
->from('modules')
->order('name');
$this->render('overview');
}
/**
* Alias for index
*
* @see self::indexAction
*/
public function overviewAction()
{
$this->indexAction();
}
/**
* Enable a module
*/
public function enableAction()
{
$this->manager->enableModule($this->_getParam('name'));
$this->manager->loadModule($this->_getParam('name'));
$this->getResponse()->setHeader('X-Icinga-Enable-Module', $this->_getParam('name'));
$this->redirectNow('modules/overview?_render=body');
}
/**
* Disable a module
*/
public function disableAction()
{
$this->manager->disableModule($this->_getParam('name'));
$this->redirectNow('modules/overview?_render=body');
}
}
// @codingStandardsIgnoreEnd

View File

@ -0,0 +1,70 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
use \Icinga\Web\Controller\BasePreferenceController;
use \Icinga\Web\Widget\Tab;
use \Icinga\Web\Url;
/**
* Application wide preference controller for user preferences
*
*/
class PreferenceController extends BasePreferenceController
{
/**
* Create tabs for this preference controller
*
* @return array
* @see BasePreferenceController::createProvidedTabs
*/
public static function createProvidedTabs()
{
return array(
"preference" => new Tab(
array(
"name" => "preferences",
"iconCls" => "user",
"title" => "Preferences",
"url" => Url::fromPath("/preference")
)
)
);
}
/**
* @TODO: Implement User preferences (feature #5425)
*
*/
public function indexAction()
{
}
}
// @codingStandardsIgnoreEnd

View File

@ -27,7 +27,7 @@
*/ */
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Web\ActionController; use Icinga\Web\Controller\ActionController;
use Icinga\Application\Icinga, use Icinga\Application\Icinga,
Zend_Controller_Action_Exception as ActionException; Zend_Controller_Action_Exception as ActionException;

View File

@ -17,7 +17,7 @@
<b class="caret"></b> <b class="caret"></b>
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><?= $this->qlink($this->translate('Settings'), 'settings') ?></li> <li><?= $this->qlink($this->translate('Preferences'), 'preference') ?></li>
<li><?= $this->qlink($this->translate('Logout'), 'authentication/logout') ?></li> <li><?= $this->qlink($this->translate('Logout'), 'authentication/logout') ?></li>
</ul> </ul>
</li> </li>

View File

@ -0,0 +1,12 @@
<?= $this->tabs->render($this); ?>
<h3>Configuration</h3>
<div class="alert-block alert">
<h4>Dear developer</h4>
<br/>
<p>
Add shortcuts for often used configuration options so users can quickly change settings without having to
search in the tab overview
</p>
</div>

View File

@ -1,4 +1,6 @@
<?php <?php
use Icinga\Web\Url;
$this->modules->limit(10); $this->modules->limit(10);
$modules = $this->modules->paginate(); $modules = $this->modules->paginate();
@ -11,22 +13,19 @@ $modules = $this->modules->paginate();
<table > <table >
<tbody> <tbody>
<? foreach ($modules as $module): ?> <? 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> <tr>
<td> <td>
<? if ($module->enabled): ?> <? if ($module->enabled): ?>
<i class="icon-ok-sign"></i> <?= $this->qlink( <i class="icon-ok-sign"></i>
$module->name, <a href="<?= $disableUrl ?>"><?= $this->escape($module->name); ?></a>
'modules/disable',
array('name' => $module->name),
array('target'=>'body')
) ?>
<? else: ?> <? else: ?>
<i class="icon-remove-sign"></i> <?= $this->qlink( <i class="icon-remove-sign"></i>
$module->name, <a href="<?= $enableUrl ?>"><?= $this->escape($module->name); ?></a>
'modules/enable',
array('name' => $module->name),
array('target'=>'body')
) ?>
<? endif ?> <? endif ?>
(<?= (<?=
$module->enabled $module->enabled

View File

@ -1,12 +0,0 @@
<?= $this->tabs->render($this); ?>
<h3>Configuration</h3>
<p>
This is the configuration over page. Modules can register their handler to
provide own controllers for configuration.
</p>
<p>
Many thanks for your attention!
</p>

View File

@ -0,0 +1,3 @@
<?= $this->tabs->render($this); ?>
<h3>Preferences </h3>

View File

@ -1,4 +1,4 @@
[menu] [menu]
Dashboard = "/dashboard/index" Dashboard = "/dashboard/index"
Configuration = "/configuration/index" Configuration = "/config/index"

View File

@ -0,0 +1,57 @@
# Module Development: Configuration and Preferences Dialogs
When developing modules, you might want your module's configuration and preferences dialogs to appear in the Icinga Web
Configuration/Preferences interface. This is rather easy to accomplish and should be the preferred way to allow user's
to customize your module.
## Terminology
When talking about 'Configuration' and 'Preference', we have a clear distinction between those words:
- **Configurations** are application/module wide settings that affect every user when being changed. This could be
the data backend of your module or other 'global' settings that affect everyone when being changed
- **Preferences** are settings a user can set for *his* account only, like the page size of pagination, entry points, etc.
## Usage
The two base classes for preferences and configurations are \Icinga\Web\Controller\BasePreferenceController for preferences and
\Icinga\Web\Controller\BaseConfigController for configurations.
If you want to create a preference or configuration panel you have to create a ConfigController and/or PreferenceController
in your Module's a controller directory and make it a subclass of BaseConfigController or BasePreferenceController.
Those controllers can be used like normal controllers, with two exceptions:
- If you want your module to appear as a tab in the applications configuration/preference interface you have to implement
the static createProvidedTabs function that returns an array of tabs to be displayed
- The init() method of the base class must be called in order to make sure tabs are collected and the view's tabs variable
is populated
## Example
We'll just provide an example for ConfigControllers here, as PreferenceController are the same with a different name
use \Icinga\Web\Controller\BaseConfigController;
use \Icinga\Web\Widget\Tab;
use \Icinga\Web\Url;
class My_ConfigController extends BaseConfigController {
static public function createProvidedTabs()
{
return array(
"myModuleTab" => new Tab(array(
"name" => "myModuleTab", // the internal name of the tab
"iconCls" => "myicon", // the icon to be displayed
"title" => "The tab title", // The title of the configuration's tab
"url" => Url::fromPath("/myModule/config") // The Url that will ne called (can also be just a path)
))
);
}
public function indexAction()
{
// create the form here
}
}

View File

@ -1,27 +1,78 @@
<?php <?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Application\Modules; namespace Icinga\Application\Modules;
use Icinga\Exception\ConfigurationError; use \Icinga\Application\ApplicationBootstrap;
use Icinga\Exception\SystemPermissionException; use \Icinga\Application\Icinga;
use Icinga\Exception\ProgrammingError; use \Icinga\Application\Logger;
use \Icinga\Exception\ConfigurationError;
// TODO: show whether enabling/disabling modules is allowed by checking enableDir use \Icinga\Exception\SystemPermissionException;
// perms use \Icinga\Exception\ProgrammingError;
/**
* Module manager that handles detecting, enabling and disabling of modules
*
* Modules can have 3 states:
* * installed, module exists but is disabled
* * enabled, module enabled and should be loaded
* * loaded, module enabled and loaded via the autoloader
*
*/
class Manager class Manager
{ {
protected $installedBaseDirs = null;
protected $enabledDirs = array();
protected $loadedModules = array();
protected $index;
protected $app;
protected $enableDir;
protected $modulePaths = array();
/** /**
* @param $app : The applicaiton bootstrap. This one needs a properly defined interface * Array of all installed module's base directories
* In order to test it correctly, the application now only requires a stdClass *
* @param $dir : * null if modules haven't been scanned yet
*
* @var array|null
*/
private $installedBaseDirs = null;
/**
* Array of all enabled modules base dirs
*
* @var array
*/
private $enabledDirs = array();
/**
* Array of all module names that have been loaded
*
* @var array
*/
private $loadedModules = array();
/**
* Reference to Icinga::app
*
* @var Icinga
*/
private $app;
/**
* The directory that is used to detect enabled modules
*
* @var string
*/
private $enableDir;
/**
* All paths to look for installed modules that can be enabled
*
* @var array
*/
private $modulePaths = array();
/**
* Create a new instance of the module manager
*
* @param ApplicationBootstrap $app
* @param string $enabledDir Enabled modules location. The application maintains symlinks within
* the given path
* @param array $availableDirs Installed modules location
**/ **/
public function __construct($app, $enabledDir = null, array $availableDirs = array()) public function __construct($app, $enabledDir = null, array $availableDirs = array())
{ {
@ -38,11 +89,17 @@ class Manager
$this->detectEnabledModules(); $this->detectEnabledModules();
} }
protected function prepareEssentials($moduleDir) /**
* Set the module dir and checks for existence
*
* @param string $moduleDir The module directory to set for the module manager
* @throws \Icinga\Exception\ProgrammingError
*/
private function prepareEssentials($moduleDir)
{ {
$this->enableDir = $moduleDir; $this->enableDir = $moduleDir;
if (! file_exists($this->enableDir) || ! is_dir($this->enableDir)) { if (!file_exists($this->enableDir) || !is_dir($this->enableDir)) {
throw new ProgrammingError( throw new ProgrammingError(
sprintf( sprintf(
'Missing module directory: %s', 'Missing module directory: %s',
@ -52,13 +109,21 @@ class Manager
} }
} }
/**
* Query interface for the module manager
*
* @return \Icinga\Data\ArrayQuery
*/
public function select() public function select()
{ {
$source = new \Icinga\Data\ArrayDatasource($this->getModuleInfo()); $source = new \Icinga\Data\ArrayDatasource($this->getModuleInfo());
return $source->select(); return $source->select();
} }
protected function detectEnabledModules() /**
* Check for enabled modules and update the internal $enabledDirs property with the enabled modules
*/
private function detectEnabledModules()
{ {
$fh = opendir($this->enableDir); $fh = opendir($this->enableDir);
@ -70,12 +135,23 @@ class Manager
} }
$link = $this->enableDir . '/' . $file; $link = $this->enableDir . '/' . $file;
if (! is_link($link)) { if (!is_link($link)) {
Logger::warn(
'Found invalid module in enabledModule directory "%s": "%s" is not a symlink',
$this->enableDir,
$link
);
continue; continue;
} }
$dir = realpath($link); $dir = realpath($link);
if (! file_exists($dir) || ! is_dir($dir)) { if (!file_exists($dir) || !is_dir($dir)) {
Logger::warn(
'Found invalid module in enabledModule directory "%s": "%s" points to non existing path "%s"',
$this->enableDir,
$link,
$dir
);
continue; continue;
} }
@ -83,6 +159,12 @@ class Manager
} }
} }
/**
* Try to set all enabled modules in loaded sate
*
* @return self
* @see Manager::loadModule()
*/
public function loadEnabledModules() public function loadEnabledModules()
{ {
foreach ($this->listEnabledModules() as $name) { foreach ($this->listEnabledModules() as $name) {
@ -91,6 +173,15 @@ class Manager
return $this; return $this;
} }
/**
* Try to load the module and register it in the application
*
* @param string $name The name of the module to load
* @param mixed $moduleBase Alternative class to use instead of \Icinga\Application\Modules\Module for
* instantiating modules, used for testing
*
* @return self
*/
public function loadModule($name, $moduleBase = null) public function loadModule($name, $moduleBase = null)
{ {
if ($this->hasLoaded($name)) { if ($this->hasLoaded($name)) {
@ -108,9 +199,18 @@ class Manager
return $this; return $this;
} }
/**
* Set the given module to the enabled state
*
* @param string $name The module to enable
*
* @return self
* @throws \Icinga\Exception\ConfigurationError When trying to enable a module that is not installed
* @throws \Icinga\Exception\SystemPermissionException When insufficient permissions for the application exist
*/
public function enableModule($name) public function enableModule($name)
{ {
if (! $this->hasInstalled($name)) { if (!$this->hasInstalled($name)) {
throw new ConfigurationError( throw new ConfigurationError(
sprintf( sprintf(
"Cannot enable module '%s' as it isn't installed", "Cannot enable module '%s' as it isn't installed",
@ -122,7 +222,7 @@ class Manager
clearstatcache(true); clearstatcache(true);
$target = $this->installedBaseDirs[$name]; $target = $this->installedBaseDirs[$name];
$link = $this->enableDir . '/' . $name; $link = $this->enableDir . '/' . $name;
if (! is_writable($this->enableDir)) { if (!is_writable($this->enableDir)) {
throw new SystemPermissionException( throw new SystemPermissionException(
"Insufficient system permissions for enabling modules", "Insufficient system permissions for enabling modules",
"write", "write",
@ -142,32 +242,42 @@ class Manager
return $this; return $this;
} }
/**
* Disable the given module and remove it's enabled state
*
* @param string $name The name of the module to disable
*
* @return self
*
* @throws \Icinga\Exception\ConfigurationError When the module is not installed or it's not symlinked
* @throws \Icinga\Exception\SystemPermissionException When the module can't be disabled
*/
public function disableModule($name) public function disableModule($name)
{ {
if (! $this->hasEnabled($name)) { if (!$this->hasEnabled($name)) {
return $this; return $this;
} }
if (! is_writable($this->enableDir)) { if (!is_writable($this->enableDir)) {
throw new SystemPermissionException("Can't write the module directory", "write", $this->enableDir); throw new SystemPermissionException("Can't write the module directory", "write", $this->enableDir);
return $this; return $this;
} }
$link = $this->enableDir . '/' . $name; $link = $this->enableDir . '/' . $name;
if (!file_exists($link)) { if (!file_exists($link)) {
throw new ConfigurationError("The module $name could not be found, can't disable it"); throw new ConfigurationError('The module ' . $name . ' could not be found, can\'t disable it');
} }
if (!is_link($link)) { if (!is_link($link)) {
throw new ConfigurationError( throw new ConfigurationError(
"The module $name can't be disabled as this would delete the whole module. ". 'The module ' . $name . ' can\'t be disabled as this would delete the whole module. '
"It looks like you have installed this module manually and moved it to your module folder.". . 'It looks like you have installed this module manually and moved it to your module folder. '
"In order to dynamically enable and disable modules, you have to create a symlink to ". . 'In order to dynamically enable and disable modules, you have to create a symlink to '
"the enabled_modules folder" . 'the enabled_modules folder'
); );
} }
if (file_exists($link) && is_link($link)) { if (file_exists($link) && is_link($link)) {
if (!@unlink($link)) { if (!@unlink($link)) {
$error = error_get_last(); $error = error_get_last();
throw new SystemPermissionException($error["message"], "unlink", $link); throw new SystemPermissionException($error['message'], 'unlink', $link);
} }
} else { } else {
@ -176,11 +286,16 @@ class Manager
return $this; return $this;
} }
public function getModuleConfigDir($name) /**
{ * Return the directory of the given module as a string, optionally with a given sub directoy
return $this->getModuleDir($name, '/config'); *
} * @param string $name The module name to return the module directory of
* @param string $subdir The sub directory to append to the path
*
* @return string
*
* @throws \Icinga\Exception\ProgrammingError When the module is not installed or existing
*/
public function getModuleDir($name, $subdir = '') public function getModuleDir($name, $subdir = '')
{ {
if ($this->hasEnabled($name)) { if ($this->hasEnabled($name)) {
@ -199,6 +314,13 @@ class Manager
); );
} }
/**
* Return true when the module with the given name is installed, otherwise false
*
* @param string $name The module to check for being installed
*
* @return bool
*/
public function hasInstalled($name) public function hasInstalled($name)
{ {
if ($this->installedBaseDirs === null) { if ($this->installedBaseDirs === null) {
@ -207,24 +329,54 @@ class Manager
return array_key_exists($name, $this->installedBaseDirs); return array_key_exists($name, $this->installedBaseDirs);
} }
/**
* Return true when the given module is in enabled state, otherwise false
*
* @param string $name The module to check for being enabled
*
* @return bool
*/
public function hasEnabled($name) public function hasEnabled($name)
{ {
return array_key_exists($name, $this->enabledDirs); return array_key_exists($name, $this->enabledDirs);
} }
/**
* Return true when the module is in loaded state, otherwise false
*
* @param string $name The module to check for being loaded
*
* @return bool
*/
public function hasLoaded($name) public function hasLoaded($name)
{ {
return array_key_exists($name, $this->loadedModules); return array_key_exists($name, $this->loadedModules);
} }
/**
* Return an array containing all loaded modules
*
* @return array
*
* @see \Icinga\Application\Modules\Module
*/
public function getLoadedModules() public function getLoadedModules()
{ {
return $this->loadedModules; return $this->loadedModules;
} }
/**
* Return the module instance of the given module when it is loaded
*
* @param string $name The module name to return
*
* @return \Icinga\Application\Modules\Module
*
* @throws \Icinga\Exception\ProgrammingError When the module hasn't been loaded
*/
public function getModule($name) public function getModule($name)
{ {
if (! $this->hasLoaded($name)) { if (!$this->hasLoaded($name)) {
throw new ProgrammingError( throw new ProgrammingError(
sprintf( sprintf(
'Cannot access module %s as it hasn\'t been loaded', 'Cannot access module %s as it hasn\'t been loaded',
@ -235,6 +387,17 @@ class Manager
return $this->loadedModules[$name]; return $this->loadedModules[$name];
} }
/**
* Return an array containing information objects for each available module
*
* Each entry has the following fields
* * name, name of the module as a string
* * path, path where the module is located as a string
* * enabled, whether the module is enabled or not as a boolean
* * loaded, whether the module is loaded or not as a boolean
*
* @return array
*/
public function getModuleInfo() public function getModuleInfo()
{ {
$installed = $this->listInstalledModules(); $installed = $this->listInstalledModules();
@ -255,16 +418,35 @@ class Manager
return $info; return $info;
} }
/**
* Return an array containing all enabled module names as strings
*
* @return array
*/
public function listEnabledModules() public function listEnabledModules()
{ {
return array_keys($this->enabledDirs); return array_keys($this->enabledDirs);
} }
/**
* Return an array containing all loaded module names as strings
*
* @return array
*/
public function listLoadedModules() public function listLoadedModules()
{ {
return array_keys($this->loadedModules); return array_keys($this->loadedModules);
} }
/**
* Return an array containing all installled module names as strings
*
* Calls detectInstalledModules() if no module discovery has been performed yet
*
* @return array
*
* @see detectInstalledModules()
*/
public function listInstalledModules() public function listInstalledModules()
{ {
if ($this->installedBaseDirs === null) { if ($this->installedBaseDirs === null) {
@ -276,6 +458,11 @@ class Manager
} }
} }
/**
* Detect installed modules from every path provided in modulePaths
*
* @return self
*/
public function detectInstalledModules() public function detectInstalledModules()
{ {
foreach ($this->modulePaths as $basedir) { foreach ($this->modulePaths as $basedir) {
@ -293,5 +480,6 @@ class Manager
} }
} }
} }
return $this;
} }
} }

View File

@ -28,11 +28,11 @@
namespace Icinga\Application\Modules; namespace Icinga\Application\Modules;
use Icinga\Application\ApplicationBootstrap; use \Icinga\Application\ApplicationBootstrap;
use \Icinga\Application\Config; use \Icinga\Application\Config;
use Icinga\Application\Icinga; use \Icinga\Application\Icinga;
use Icinga\Web\Hook; use \Icinga\Web\Hook;
use Zend_Controller_Router_Route as Route; use \Zend_Controller_Router_Route as Route;
/** /**
* Module handling * Module handling
@ -109,7 +109,7 @@ class Module
* *
* @param ApplicationBootstrap $app * @param ApplicationBootstrap $app
* @param string $name * @param string $name
* @param strinb $basedir * @param string $basedir
*/ */
public function __construct(ApplicationBootstrap $app, $name, $basedir) public function __construct(ApplicationBootstrap $app, $name, $basedir)
{ {
@ -142,6 +142,7 @@ class Module
* Test for an enabled module by name * Test for an enabled module by name
* *
* @param string $name * @param string $name
*
* @return boolean * @return boolean
*/ */
public static function exists($name) public static function exists($name)
@ -154,7 +155,10 @@ class Module
* *
* @param string $name * @param string $name
* @param bool $autoload * @param bool $autoload
*
* @return mixed * @return mixed
*
* @throws \Icinga\Exception\ProgrammingError When the module is not yet loaded
*/ */
public static function get($name, $autoload = false) public static function get($name, $autoload = false)
{ {
@ -164,7 +168,7 @@ class Module
$manager->loadModule($name); $manager->loadModule($name);
} }
} }
// @throws ProgrammingError: // Throws ProgrammingError when the module is not yet loaded
return $manager->getModule($name); return $manager->getModule($name);
} }
@ -200,6 +204,7 @@ class Module
/** /**
* Getter for base directory * Getter for base directory
*
* @return string * @return string
*/ */
public function getBaseDir() public function getBaseDir()
@ -207,6 +212,11 @@ class Module
return $this->basedir; return $this->basedir;
} }
public function getControllerDir()
{
return $this->controllerdir;
}
/** /**
* Getter for library directory * Getter for library directory
* *
@ -240,7 +250,8 @@ class Module
/** /**
* Getter for module config object * Getter for module config object
* *
* @param null|string $file * @param string $file
*
* @return Config * @return Config
*/ */
public function getConfig($file = null) public function getConfig($file = null)
@ -378,6 +389,7 @@ class Module
* @param string $name * @param string $name
* @param string $class * @param string $class
* @param string $key * @param string $key
*
* @return self * @return self
*/ */
protected function registerHook($name, $key, $class) protected function registerHook($name, $key, $class)

View File

@ -25,19 +25,18 @@
* @author Icinga Development Team <info@icinga.org> * @author Icinga Development Team <info@icinga.org>
*/ */
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Web\Controller;
namespace Icinga\Web; use \Icinga\Authentication\Manager as AuthManager;
use \Icinga\Application\Benchmark;
use Icinga\Authentication\Manager as AuthManager; use \Icinga\Exception;
use Icinga\Application\Benchmark;
use Icinga\Exception;
use \Icinga\Application\Config; use \Icinga\Application\Config;
use Icinga\Web\Notification; use \Icinga\Web\Notification;
use Zend_Layout as ZfLayout; use \Zend_Layout as ZfLayout;
use Zend_Controller_Action as ZfController; use \Zend_Controller_Action as ZfController;
use Zend_Controller_Request_Abstract as ZfRequest; use \Zend_Controller_Request_Abstract as ZfRequest;
use Zend_Controller_Response_Abstract as ZfResponse; use \Zend_Controller_Response_Abstract as ZfResponse;
use Zend_Controller_Action_HelperBroker as ZfActionHelper; use \Zend_Controller_Action_HelperBroker as ZfActionHelper;
/* /*
* @TODO(el): There was a note from tg that the following line is temporary. Ask him why. * @TODO(el): There was a note from tg that the following line is temporary. Ask him why.
@ -224,12 +223,14 @@ class ActionController extends ZfController
// TODO(el): What is this, why do we need that here? // TODO(el): What is this, why do we need that here?
$this->view->compact = $this->_request->getParam('view') === 'compact'; $this->view->compact = $this->_request->getParam('view') === 'compact';
Benchmark::measure(sprintf( Benchmark::measure(
sprintf(
'Action::preDispatched(): %s / %s / %s', 'Action::preDispatched(): %s / %s / %s',
$this->module_name, $this->module_name,
$this->controller_name, $this->controller_name,
$this->action_name $this->action_name
)); )
);
//$this->quickRedirect('/authentication/login?a=e'); //$this->quickRedirect('/authentication/login?a=e');
} }
@ -285,22 +286,6 @@ class ActionController extends ZfController
// TODO: We need a way to retrieve public dir, even if located elsewhere // TODO: We need a way to retrieve public dir, even if located elsewhere
$css = $less->compileFile($cssdir . '/pdfprint.less'); $css = $less->compileFile($cssdir . '/pdfprint.less');
/*
foreach (\Icinga\Application\Icinga::app()->getModuleManager()->getLoadedModules() as $name => $module) {
if ($module->hasCss()) {
$css .= $less->compile(
'.icinga-module.module-'
. $name
. " {\n"
. file_get_contents($module->getCssFilename())
. "}\n\n"
);
}
}
*/
// END of CSS test
$this->render( $this->render(
null, null,
$this->_helper->viewRenderer->getResponseSegment(), $this->_helper->viewRenderer->getResponseSegment(),
@ -318,9 +303,6 @@ class ActionController extends ZfController
$html = '<style>' . $css . '</style>' . $html; $html = '<style>' . $css . '</style>' . $html;
//$html .= $this->view->action('services', 'list', 'monitoring', array('limit' => 10));
// $html = preg_replace('~icinga-module.module-bpapp~', 'csstest', $html);
// echo $html; exit;
$pdf = new Pdf(); $pdf = new Pdf();
$pdf->AddPage(); $pdf->AddPage();
$pdf->setFontSubsetting(false); $pdf->setFontSubsetting(false);
@ -357,6 +339,5 @@ class ActionController extends ZfController
Benchmark::measure('Response ready'); Benchmark::measure('Response ready');
$this->_helper->layout()->benchmark = $this->renderBenchmark(); $this->_helper->layout()->benchmark = $this->renderBenchmark();
} }
} }
} }

View File

@ -0,0 +1,66 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Web\Controller;
use \Icinga\Application\Icinga;
/**
* Base class for Configuration Controllers
*
* Module preferences use this class to make sure they are automatically
* added to the application's configuration dialog. If you create a subclass of
* BasePreferenceController and overwrite @see init(), make sure you call
* parent::init(), otherwise you won't have the $tabs property in your view.
*
*/
class BaseConfigController extends ActionController
{
/*
* Return an array of tabs provided by this configuration controller.
*
* Those tabs will automatically be added to the application's configuration dialog
*
* @return array
*/
public static function createProvidedTabs()
{
return array();
}
/**
* Initialize the controller and collect all tabs for it from the application and it's modules
*
* @see ActionController::init
*/
public function init()
{
parent::init();
$this->view->tabs = ControllerTabCollector::collectControllerTabs('ConfigController');
}
}

View File

@ -0,0 +1,64 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Web\Controller;
/**
* Base class for Preference Controllers
*
* Module preferences use this class to make sure they are automatically
* added to the general preferences dialog. If you create a subclass of
* BasePreferenceController and overwrite @see init(), make sure you call
* parent::init(), otherwise you won't have the $tabs property in your view.
*
*/
class BasePreferenceController extends ActionController
{
/**
* Return an array of tabs provided by this preference controller.
*
* Those tabs will automatically be added to the application's preference dialog
*
* @return array
*/
public static function createProvidedTabs()
{
return array();
}
/**
* Initialize the controller and collect all tabs for it from the application and it's modules
*
* @see ActionController::init()
*/
public function init()
{
parent::init();
$this->view->tabs = ControllerTabCollector::collectControllerTabs('PreferenceController');
}
}

View File

@ -0,0 +1,125 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Web\Controller;
use \Icinga\Application\Modules\Module;
use \Icinga\Application\Icinga;
use \Icinga\Web\Widget\Tabs;
/**
* Static helper class that collects tabs provided by the 'createProvidedTabs' method
* of controllers.
*
*/
class ControllerTabCollector
{
/**
* Scan all controllers with the provided name
* in the application and (loaded) module folders and collects their provided tabs
*
* @param string $controller The name of the controllers to use for tab collection
*
* @return Tabs A @see Tabs instance containing the application tabs first
* followed by the tabs provided from the modules
*/
public static function collectControllerTabs($controller)
{
require_once(Icinga::app()->getApplicationDir('/controllers/'.$controller.'.php'));
$applicationTabs = $controller::createProvidedTabs();
$moduleTabs = self::collectModuleTabs($controller);
$tabs = new Tabs();
foreach ($applicationTabs as $name => $tab) {
$tabs->add($name, $tab);
}
foreach ($moduleTabs as $name => $tab) {
// don't overwrite application tabs if the module wants to
if ($tabs->has($name)) {
continue;
}
$tabs->add($name, $tab);
}
return $tabs;
}
/**
* Collect module tabs for all modules containing the given controller
*
* @param string $controller The controller name to use for tab collection
*
* @return array An array of Tabs objects or arrays containing Tab descriptions
*/
private static function collectModuleTabs($controller)
{
$moduleManager = Icinga::app()->getModuleManager();
$modules = $moduleManager->listEnabledModules();
$tabs = array();
foreach ($modules as $module) {
$tabs += self::createModuleConfigurationTabs($controller, $moduleManager->getModule($module));
}
return $tabs;
}
/**
* Collects the tabs from the createProvidedTabs() method in the configuration controller
*
* If the module doesn't have the given controller or createProvidedTabs method in the controller
* an empty array will be returned
*
* @param string $controller The name of the controller that provides tabs via createProvidedTabs
* @param Module $module The module instance that provides the controller
*
* @return array
*/
private static function createModuleConfigurationTabs($controller, Module $module)
{
$controllerDir = $module->getControllerDir();
$name = $module->getName();
$controllerDir = $controllerDir . '/' . $controller . '.php';
$controllerName = ucfirst($name) . '_' . $controller;
if (is_readable($controllerDir)) {
require_once(realpath($controllerDir));
if (!method_exists($controllerName, "createProvidedTabs")) {
return array();
}
$tab = $controllerName::createProvidedTabs();
if (!is_array($tab)) {
$tab = array($name => $tab);
}
return $tab;
}
return array();
}
}

View File

@ -26,7 +26,7 @@
/** /**
* Module action controller * Module action controller
*/ */
namespace Icinga\Web; namespace Icinga\Web\Controller;
use \Icinga\Application\Config as IcingaConfig; use \Icinga\Application\Config as IcingaConfig;
use Icinga\Application\Icinga; use Icinga\Application\Icinga;

View File

@ -1,6 +1,5 @@
<?php <?php
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
/** /**
* This file is part of Icinga 2 Web. * This file is part of Icinga 2 Web.
@ -35,7 +34,7 @@ use \Icinga\Application\Config;
use Icinga\Application\Logger; use Icinga\Application\Logger;
use Icinga\Authentication\Manager; use Icinga\Authentication\Manager;
use Icinga\Web\Form; use Icinga\Web\Form;
use Icinga\Web\ModuleActionController; use Icinga\Web\Controller\ModuleActionController;
use Icinga\Protocol\Commandpipe\Comment; use Icinga\Protocol\Commandpipe\Comment;
use Icinga\Protocol\Commandpipe\CommandPipe; use Icinga\Protocol\Commandpipe\CommandPipe;
use Icinga\Exception\ConfigurationError; use Icinga\Exception\ConfigurationError;

View File

@ -1,9 +1,10 @@
<?php <?php
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
/** /**
* Icinga 2 Web - Head for multiple monitoring frontends * This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team * Copyright (C) 2013 Icinga Development Team
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -21,39 +22,33 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* *
* @copyright 2013 Icinga Development Team <info@icinga.org> * @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org> * @author Icinga Development Team <info@icinga.org>
*/ */
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Application\Benchmark; use \Icinga\Web\Controller\BaseConfigController;
use Icinga\Authentication\Manager; use \Icinga\Web\Widget\Tab;
use Icinga\Web\ActionController; use \Icinga\Web\Url;
use Icinga\Web\Widget\Tabs;
use Icinga\Web\Hook\Configuration\ConfigurationTabBuilder;
/** class Monitoring_ConfigController extends BaseConfigController {
* Class ConfigurationController
*/ static public function createProvidedTabs()
class ConfigurationController extends ActionController
{
public function init()
{ {
parent::init(); return array(
} "backends" => new Tab(array(
"name" => "backends",
"iconCls" => "hdd",
/** "title" => "Monitoring Backends",
* Index action "url" => Url::fromPath("/monitoring/config/backend")
*/ ))
public function indexAction()
{
$tabBuilder = new ConfigurationTabBuilder(
new Tabs()
); );
$tabBuilder->build();
$this->view->tabs = $tabBuilder->getTabs();
} }
}
public function backendAction()
{
$this->redirectNow("/config");
}
}
// @codingStandardsIgnoreEnd // @codingStandardsIgnoreEnd

View File

@ -1,6 +1,32 @@
<?php <?php
// @codingStandardsIgnoreStart
use Icinga\Web\ModuleActionController; // {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Web\Controller\ModuleActionController;
use Icinga\Web\Hook; use Icinga\Web\Hook;
use Icinga\File\Csv; use Icinga\File\Csv;
use Monitoring\Backend; use Monitoring\Backend;
@ -9,9 +35,26 @@ use Icinga\Web\Widget\Tabs;
class Monitoring_ListController extends ModuleActionController class Monitoring_ListController extends ModuleActionController
{ {
/**
* The backend used for this controller
*
* @var \Icinga\Backend
*/
protected $backend; protected $backend;
/**
* Set to a string containing the compact layout name to use when
* 'compact' is set as the layout parameter, otherwise null
*
* @var string|null
*/
private $compactView = null; private $compactView = null;
/**
* Retrieve backend and hooks for this controller
*
* @see ActionController::init
*/
public function init() public function init()
{ {
$this->view->tabs = $this->getTabs() $this->view->tabs = $this->getTabs()
@ -21,6 +64,9 @@ class Monitoring_ListController extends ModuleActionController
$this->view->grapher = Hook::get('grapher'); $this->view->grapher = Hook::get('grapher');
} }
/**
* Display host list
*/
public function hostsAction() public function hostsAction()
{ {
Benchmark::measure("hostsAction::query()"); Benchmark::measure("hostsAction::query()");
@ -50,6 +96,9 @@ class Monitoring_ListController extends ModuleActionController
); );
} }
/**
* Display service list
*/
public function servicesAction() public function servicesAction()
{ {
$state_type = $this->_getParam('_statetype', 'soft'); $state_type = $this->_getParam('_statetype', 'soft');
@ -93,6 +142,11 @@ class Monitoring_ListController extends ModuleActionController
$this->inheritCurrentSortColumn(); $this->inheritCurrentSortColumn();
} }
/**
* Display hostgroup list
*
* @TODO Implement hostgroup overview (feature #4184)
*/
public function hostgroupsAction() public function hostgroupsAction()
{ {
$this->view->hostgroups = $this->backend->select() $this->view->hostgroups = $this->backend->select()
@ -102,6 +156,11 @@ class Monitoring_ListController extends ModuleActionController
))->applyRequest($this->_request); ))->applyRequest($this->_request);
} }
/**
* Display servicegroup list
*
* @TODO Implement servicegroup overview (feature #4185)
*/
public function servicegroupsAction() public function servicegroupsAction()
{ {
$this->view->servicegroups = $this->backend->select() $this->view->servicegroups = $this->backend->select()
@ -111,6 +170,11 @@ class Monitoring_ListController extends ModuleActionController
))->applyRequest($this->_request); ))->applyRequest($this->_request);
} }
/**
* Display contactgroups overview
*
*
*/
public function contactgroupsAction() public function contactgroupsAction()
{ {
$this->view->contactgroups = $this->backend->select() $this->view->contactgroups = $this->backend->select()
@ -120,33 +184,6 @@ class Monitoring_ListController extends ModuleActionController
))->applyRequest($this->_request); ))->applyRequest($this->_request);
} }
public function contactsAction()
{
$this->view->contacts = $this->backend->select()
->from('contact', array(
'contact_name',
'contact_alias',
'contact_email',
'contact_pager'
))->applyRequest($this->_request);
}
// TODO: Search helper playground
public function searchAction()
{
$data = array(
'service_description',
'service_state',
'service_acknowledged',
'service_handled',
'service_output',
// '_host_satellite',
'service_last_state_change'
);
echo json_encode($data);
exit;
}
/** /**
* Fetch the current downtimes and put them into the view * Fetch the current downtimes and put them into the view
* property 'downtimes' * property 'downtimes'
@ -177,6 +214,14 @@ class Monitoring_ListController extends ModuleActionController
$this->inheritCurrentSortColumn(); $this->inheritCurrentSortColumn();
} }
/**
* Create a query for the given view
*
* @param string $view An string identifying view to query
* @param array $columns An array with the column names to display
*
* @return \Icinga\Data\Db\Query
*/
protected function query($view, $columns) protected function query($view, $columns)
{ {
$extra = preg_split( $extra = preg_split(
@ -194,6 +239,11 @@ class Monitoring_ListController extends ModuleActionController
return $query; return $query;
} }
/**
* Handle the 'format' and 'view' parameter
*
* @param \Icinga\Data\Db\Query $query The current query
*/
protected function handleFormatRequest($query) protected function handleFormatRequest($query)
{ {
if ($this->compactView !== null && ($this->_getParam('view', false) === 'compact')) { if ($this->compactView !== null && ($this->_getParam('view', false) === 'compact')) {
@ -220,6 +270,11 @@ class Monitoring_ListController extends ModuleActionController
} }
} }
/**
* Return all tabs for this controller
*
* @return Tabs
*/
protected function getTabs() protected function getTabs()
{ {
$tabs = new Tabs(); $tabs = new Tabs();
@ -275,3 +330,4 @@ class Monitoring_ListController extends ModuleActionController
} }
} }
} }
// @codingStandardsIgnoreEnd

View File

@ -28,7 +28,7 @@
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
use Monitoring\Backend; use Monitoring\Backend;
use Icinga\Web\ModuleActionController; use Icinga\Web\Controller\ModuleActionController;
use Icinga\Web\Hook; use Icinga\Web\Hook;
use Monitoring\Object\Host; use Monitoring\Object\Host;
use Monitoring\Object\Service; use Monitoring\Object\Service;

View File

@ -1,10 +1,14 @@
<?php <?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
use \Zend_Soap_Server as ZfSoapServer;
use \Zend_Soap_AutoDiscover as ZfSoapAutoDiscover;
use \Icinga\Web\Controller\ModuleActionController;
use \Icinga\Web\Url;
use \Monitoring\Backend;
use Icinga\Web\ModuleActionController;
use Icinga\Web\Url;
use Monitoring\Backend;
use Zend_Soap_Server as ZfSoapServer;
use Zend_Soap_AutoDiscover as ZfSoapAutoDiscover;
class Api class Api
{ {
@ -47,3 +51,4 @@ class Monitoring_SoapController extends ModuleActionController
exit; exit;
} }
} }
// @codingStandardsIgnoreEnd

View File

@ -1,6 +1,32 @@
<?php <?php
// @codingStandardsIgnoreStart
use Icinga\Web\ModuleActionController; // {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Web\Controller\ModuleActionController;
use Icinga\Backend; use Icinga\Backend;
use Icinga\Web\Widget\Tabs; use Icinga\Web\Widget\Tabs;
@ -68,3 +94,4 @@ class Monitoring_SummaryController extends ModuleActionController
} }
} }
// @codingStandardsIgnoreEnd

View File

@ -2,7 +2,7 @@
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Web namespace Icinga\Web\Controller
{ {
/** /**
* Mocked controller base class to avoid the complete * Mocked controller base class to avoid the complete
@ -82,7 +82,7 @@ namespace Test\Monitoring\Testlib
require_once 'Zend/View.php'; require_once 'Zend/View.php';
use Icinga\Protocol\Statusdat\Reader; use Icinga\Protocol\Statusdat\Reader;
use Icinga\Web\ActionController; use Icinga\Web\Controller\ActionController;
use Test\Monitoring\Testlib\DataSource\TestFixture; use Test\Monitoring\Testlib\DataSource\TestFixture;
use Test\Monitoring\Testlib\DataSource\DataSourceTestSetup; use Test\Monitoring\Testlib\DataSource\DataSourceTestSetup;
use Monitoring\Backend\Ido; use Monitoring\Backend\Ido;

View File

@ -87,9 +87,9 @@ var onLinkTagClick = function(ev) {
'.layout-main-detail * a' : { '.layout-main-detail * a' : {
'click' : onLinkTagClick 'click' : onLinkTagClick
}, },
'a' : { /* 'a' : {
'click' : onOuterLinkClick 'click' : onOuterLinkClick
}, },*/
'.layout-main-detail .icinga-container#icinga-detail' : { '.layout-main-detail .icinga-container#icinga-detail' : {
'focus' : expandDetailView 'focus' : expandDetailView
} }

View File

@ -12,7 +12,7 @@ require '../../library/Icinga/Exception/ProgrammingError.php';
require '../../library/Icinga/Application/Benchmark.php'; require '../../library/Icinga/Application/Benchmark.php';
require '../../library/Icinga/Application/Config.php'; require '../../library/Icinga/Application/Config.php';
require '../../library/Icinga/Application/Icinga.php'; require '../../library/Icinga/Application/Icinga.php';
require '../../library/Icinga/Web/ActionController.php'; require '../../library/Icinga/Web/Controller/ActionController.php';
require '../../library/Icinga/Web/Notification.php'; require '../../library/Icinga/Web/Notification.php';
require '../../library/Icinga/Application/Platform.php'; require '../../library/Icinga/Application/Platform.php';

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Tests\Icinga\Web\ActionController; namespace Tests\Icinga\Web\Controller\ActionController;