Revert "Fixes unaccepted behavior in module configuration"

This reverts commit 236d384bab3c1b64f3fd9954487accc33aafe48a.
This commit is contained in:
Alexander Fuhr 2014-09-02 04:21:56 -04:00
parent a47c376fb3
commit bb0e1dc105
6 changed files with 74 additions and 115 deletions

View File

@ -177,7 +177,6 @@ class Module
/** /**
* Add a pane to dashboard * Add a pane to dashboard
* *
* @param $id
* @param $name * @param $name
* @return Pane * @return Pane
*/ */
@ -201,21 +200,19 @@ class Module
/** /**
* Add a menu Section to the Sidebar menu * Add a menu Section to the Sidebar menu
* *
* @param string $id * @param $name
* @param string $name
* @param array $properties * @param array $properties
* @return mixed * @return mixed
*/ */
protected function menuSection($id, $name, array $properties = array()) protected function menuSection($name, array $properties = array())
{ {
if (array_key_exists($id, $this->menuItems)) { if (array_key_exists($name, $this->menuItems)) {
$this->menuItems[$id]->setProperties($properties); $this->menuItems[$name]->setProperties($properties);
} else { } else {
$this->menuItems[$id] = new Menu($id, new Zend_Config($properties)); $this->menuItems[$name] = new Menu($name, new Zend_Config($properties));
$this->menuItems[$id]->setTitle($name);
} }
return $this->menuItems[$id]; return $this->menuItems[$name];
} }
/** /**

View File

@ -5,7 +5,6 @@
namespace Icinga\Web; namespace Icinga\Web;
use Icinga\Exception\ConfigurationError; use Icinga\Exception\ConfigurationError;
use Icinga\Logger\Logger;
use Zend_Config; use Zend_Config;
use RecursiveIterator; use RecursiveIterator;
use Icinga\Application\Config; use Icinga\Application\Config;
@ -173,34 +172,34 @@ class Menu implements RecursiveIterator
*/ */
protected function addMainMenuItems() protected function addMainMenuItems()
{ {
$this->add('dashboard', t('Dashboard'), array( $this->add(t('Dashboard'), array(
'url' => 'dashboard', 'url' => 'dashboard',
'icon' => 'img/icons/dashboard.png', 'icon' => 'img/icons/dashboard.png',
'priority' => 10 'priority' => 10
)); ));
$section = $this->add('system', t('System'), array( $section = $this->add(t('System'), array(
'icon' => 'img/icons/configuration.png', 'icon' => 'img/icons/configuration.png',
'priority' => 200 'priority' => 200
)); ));
$section->add('preferences', t('Preferences'), array( $section->add(t('Preferences'), array(
'url' => 'preference', 'url' => 'preference',
'priority' => 200 'priority' => 200
)); ));
$section->add('configuration', t('Configuration'), array( $section->add(t('Configuration'), array(
'url' => 'config', 'url' => 'config',
'priority' => 300 'priority' => 300
)); ));
$section->add('modules', t('Modules'), array( $section->add(t('Modules'), array(
'url' => 'config/modules', 'url' => 'config/modules',
'priority' => 400 'priority' => 400
)); ));
$section->add('applicationlog', t('ApplicationLog'), array( $section->add(t('ApplicationLog'), array(
'url' => 'list/applicationlog', 'url' => 'list/applicationlog',
'priority' => 500 'priority' => 500
)); ));
$this->add('logout', t('Logout'), array( $this->add(t('Logout'), array(
'url' => 'authentication/logout', 'url' => 'authentication/logout',
'icon' => 'img/icons/logout.png', 'icon' => 'img/icons/logout.png',
'priority' => 300 'priority' => 300
@ -428,10 +427,9 @@ class Menu implements RecursiveIterator
* @param array $config * @param array $config
* @return Menu * @return Menu
*/ */
public function add($id, $name, $config = array()) public function add($name, $config = array())
{ {
$config['title'] = $name; return $this->addSubMenu($name, new Zend_Config($config));
return $this->addSubMenu($id, new Zend_Config($config));
} }
/** /**

View File

@ -30,13 +30,6 @@ class Component extends AbstractWidget
*/ */
private $url; private $url;
/**
* The id of this Component
*
* @var string
*/
private $id;
/** /**
* The title being displayed on top of the component * The title being displayed on top of the component
* @var * @var
@ -67,14 +60,12 @@ EOD;
/** /**
* Create a new component displaying the given url in the provided pane * Create a new component displaying the given url in the provided pane
* *
* @param string $id The id to use for this component
* @param string $title The title to use for this component * @param string $title The title to use for this component
* @param Url|string $url The url this component uses for displaying information * @param Url|string $url The url this component uses for displaying information
* @param Pane $pane The pane this Component will be added to * @param Pane $pane The pane this Component will be added to
*/ */
public function __construct($id, $title, $url, Pane $pane) public function __construct($title, $url, Pane $pane)
{ {
$this->id = $id;
$this->title = $title; $this->title = $title;
$this->pane = $pane; $this->pane = $pane;
if ($url instanceof Url) { if ($url instanceof Url) {
@ -195,14 +186,14 @@ EOD;
/** /**
* Create a @see Component instance from the given Zend config, using the provided title * Create a @see Component instance from the given Zend config, using the provided title
* @param $id The id for this component *
* @param $title The title for this component * @param $title The title for this component
* @param Zend_Config $config The configuration defining url, parameters, height, width, etc. * @param Zend_Config $config The configuration defining url, parameters, height, width, etc.
* @param Pane $pane The pane this component belongs to * @param Pane $pane The pane this component belongs to
* *
* @return Component A newly created Component for use in the Dashboard * @return Component A newly created Component for use in the Dashboard
*/ */
public static function fromIni($id, $title, Zend_Config $config, Pane $pane) public static function fromIni($title, Zend_Config $config, Pane $pane)
{ {
$height = null; $height = null;
$width = null; $width = null;
@ -210,27 +201,7 @@ EOD;
$parameters = $config->toArray(); $parameters = $config->toArray();
unset($parameters['url']); // otherwise there's an url = parameter in the Url unset($parameters['url']); // otherwise there's an url = parameter in the Url
$cmp = new Component($id, $title, Url::fromPath($url, $parameters), $pane); $cmp = new Component($title, Url::fromPath($url, $parameters), $pane);
return $cmp; return $cmp;
} }
/**
* Set the components id
*
* @param $id string
*/
public function setId($id)
{
$this->id = $id;
}
/**
* Retrieve the components id
*
* @return string
*/
public function getId()
{
return $this->id;
}
} }

View File

@ -83,44 +83,44 @@ class Pane extends AbstractWidget
/** /**
* Return true if a component with the given title exists in this pane * Return true if a component with the given title exists in this pane
* *
* @param string $id The id of the component to check for existence * @param string $title The title of the component to check for existence
* *
* @return bool * @return bool
*/ */
public function hasComponent($id) public function hasComponent($title)
{ {
return array_key_exists($id, $this->components); return array_key_exists($title, $this->components);
} }
/** /**
* Return a component with the given name if existing * Return a component with the given name if existing
* *
* @param string $id The id of the component to return * @param string $title The title of the component to return
* *
* @return Component The component with the given title * @return Component The component with the given title
* @throws ProgrammingError If the component doesn't exist * @throws ProgrammingError If the component doesn't exist
*/ */
public function getComponent($id) public function getComponent($title)
{ {
if ($this->hasComponent($id)) { if ($this->hasComponent($title)) {
return $this->components[$id]; return $this->components[$title];
} }
throw new ProgrammingError( throw new ProgrammingError(
'Trying to access invalid component: %s', 'Trying to access invalid component: %s',
$id $title
); );
} }
/** /**
* Removes the component with the given id if it exists in this pane * Removes the component with the given title if it exists in this pane
* *
* @param string $id The pane * @param string $title The pane
* @return Pane $this * @return Pane $this
*/ */
public function removeComponent($id) public function removeComponent($title)
{ {
if ($this->hasComponent($id)) { if ($this->hasComponent($title)) {
unset($this->components[$id]); unset($this->components[$title]);
} }
return $this; return $this;
} }
@ -146,7 +146,6 @@ class Pane extends AbstractWidget
/** /**
* Add a component to this pane, optionally creating it if $component is a string * Add a component to this pane, optionally creating it if $component is a string
* *
* @param string $id An unique Identifier
* @param string|Component $component The component object or title * @param string|Component $component The component object or title
* (if a new component will be created) * (if a new component will be created)
* @param string|null $url An Url to be used when component is a string * @param string|null $url An Url to be used when component is a string
@ -154,12 +153,12 @@ class Pane extends AbstractWidget
* @return self * @return self
* @throws \Icinga\Exception\ConfigurationError * @throws \Icinga\Exception\ConfigurationError
*/ */
public function addComponent($id, $component, $url = null) public function addComponent($component, $url = null)
{ {
if ($component instanceof Component) { if ($component instanceof Component) {
$this->components[$component->getId()] = $component; $this->components[$component->getTitle()] = $component;
} elseif (is_string($id) && is_string($component) && $url !== null) { } elseif (is_string($component) && $url !== null) {
$this->components[$id] = new Component($id, $component, $url, $this); $this->components[$component] = new Component($component, $url, $this);
} else { } else {
throw new ConfigurationError('Invalid component added: %s', $component); throw new ConfigurationError('Invalid component added: %s', $component);
} }
@ -176,15 +175,15 @@ class Pane extends AbstractWidget
{ {
/* @var $component Component */ /* @var $component Component */
foreach ($components as $component) { foreach ($components as $component) {
if (array_key_exists($component->getId(), $this->components)) { if (array_key_exists($component->getTitle(), $this->components)) {
if (preg_match('/-(\d+)$/', $component->getId(), $m)) { if (preg_match('/_(\d+)$/', $component->getTitle(), $m)) {
$name = preg_replace('/-\d+$/', $m[1]++, $component->getId()); $name = preg_replace('/_\d+$/', $m[1]++, $component->getTitle());
} else { } else {
$name = $component->getId() . '-2'; $name = $component->getTitle() . '_2';
} }
$this->components[$name] = $component; $this->components[$name] = $component;
} else { } else {
$this->components[$component->getId()] = $component; $this->components[$component->getTitle()] = $component;
} }
} }
@ -194,18 +193,17 @@ class Pane extends AbstractWidget
/** /**
* Add a component to the current pane * Add a component to the current pane
* *
* @param $id
* @param $title * @param $title
* @param null $url * @param $url
* @return mixed * @return Component
* *
* @see addComponent() * @see addComponent()
*/ */
public function add($id, $title, $url = null) public function add($title, $url = null)
{ {
$this->addComponent($id, $title, $url); $this->addComponent($title, $url);
return $this->components[$id]; return $this->components[$title];
} }
/** /**

View File

@ -4,7 +4,8 @@
/* @var $this \Icinga\Application\Modules\Module */ /* @var $this \Icinga\Application\Modules\Module */
$section = $this->menuSection('documentation', $this->translate('Documentation'), array( $section = $this->menuSection($this->translate('Documentation'), array(
'title' => 'Documentation',
'icon' => 'img/icons/comment.png', 'icon' => 'img/icons/comment.png',
'url' => 'doc', 'url' => 'doc',
'priority' => 80 'priority' => 80

View File

@ -22,73 +22,72 @@ $this->provideConfigTab('security', array(
/* /*
* Problems Section * Problems Section
*/ */
$section = $this->menuSection('problems', $this->translate('Problems'), array( $section = $this->menuSection($this->translate('Problems'), array(
'icon' => 'img/icons/error.png', 'icon' => 'img/icons/error.png',
'priority' => 20 'priority' => 20
)); ));
$section->add('unhandled hosts', $this->translate('Unhandled Hosts'), array( $section->add($this->translate('Unhandled Hosts'), array(
'url' => 'monitoring/list/hosts?host_problem=1&host_handled=0', 'url' => 'monitoring/list/hosts?host_problem=1&host_handled=0',
'priority' => 40 'priority' => 40
)); ));
$section->add('unhandled services', $this->translate('Unhandled Services'), array( $section->add($this->translate('Unhandled Services'), array(
'url' => 'monitoring/list/services?service_problem=1&service_handled=0&sort=service_severity', 'url' => 'monitoring/list/services?service_problem=1&service_handled=0&sort=service_severity',
'priority' => 40 'priority' => 40
)); ));
$section->add('host problems', $this->translate('Host Problems'), array( $section->add($this->translate('Host Problems'), array(
'url' => 'monitoring/list/hosts?host_problem=1&sort=host_severity', 'url' => 'monitoring/list/hosts?host_problem=1&sort=host_severity',
'priority' => 50 'priority' => 50
)); ));
$section->add('service prolems', $this->translate('Service Problems'), array( $section->add($this->translate('Service Problems'), array(
'url' => 'monitoring/list/services?service_problem=1&sort=service_severity&dir=desc', 'url' => 'monitoring/list/services?service_problem=1&sort=service_severity&dir=desc',
'priority' => 50 'priority' => 50
)); ));
$section->add('current downtimes', $this->translate('Current Downtimes')) $section->add($this->translate('Current Downtimes'))->setUrl('monitoring/list/downtimes?downtime_is_in_effect=1');
->setUrl('monitoring/list/downtimes?downtime_is_in_effect=1');
/* /*
* Overview Section * Overview Section
*/ */
$section = $this->menuSection('overview', $this->translate('Overview'), array( $section = $this->menuSection($this->translate('Overview'), array(
'icon' => 'img/icons/hostgroup.png', 'icon' => 'img/icons/hostgroup.png',
'priority' => 30 'priority' => 30
)); ));
$section->add('tactical overview', $this->translate('Tactical Overview'), array( $section->add($this->translate('Tactical Overview'), array(
'url' => 'monitoring/tactical', 'url' => 'monitoring/tactical',
'priority' => 40 'priority' => 40
)); ));
$section->add('hosts', $this->translate('Hosts'), array( $section->add($this->translate('Hosts'), array(
'url' => 'monitoring/list/hosts', 'url' => 'monitoring/list/hosts',
'priority' => 50 'priority' => 50
)); ));
$section->add('services', $this->translate('Services'), array( $section->add($this->translate('Services'), array(
'url' => 'monitoring/list/services', 'url' => 'monitoring/list/services',
'priority' => 50 'priority' => 50
)); ));
$section->add('servicematrix', $this->translate('Servicematrix'), array( $section->add($this->translate('Servicematrix'), array(
'url' => 'monitoring/list/servicematrix?service_problem=1', 'url' => 'monitoring/list/servicematrix?service_problem=1',
'priority' => 51 'priority' => 51
)); ));
$section->add('servicegroups', $this->translate('Servicegroups'), array( $section->add($this->translate('Servicegroups'), array(
'url' => 'monitoring/list/servicegroups', 'url' => 'monitoring/list/servicegroups',
'priority' => 60 'priority' => 60
)); ));
$section->add('hostgroups', $this->translate('Hostgroups'), array( $section->add($this->translate('Hostgroups'), array(
'url' => 'monitoring/list/hostgroups', 'url' => 'monitoring/list/hostgroups',
'priority' => 60 'priority' => 60
)); ));
$section->add('contactgroups', $this->translate('Contactgroups'), array( $section->add($this->translate('Contactgroups'), array(
'url' => 'monitoring/list/contactgroups', 'url' => 'monitoring/list/contactgroups',
'priority' => 61 'priority' => 61
)); ));
$section->add('downtimes', $this->translate('Downtimes'), array( $section->add($this->translate('Downtimes'), array(
'url' => 'monitoring/list/downtimes', 'url' => 'monitoring/list/downtimes',
'priority' => 71 'priority' => 71
)); ));
$section->add('comments', $this->translate('Comments'), array( $section->add($this->translate('Comments'), array(
'url' => 'monitoring/list/comments?comment_type=(comment|ack)', 'url' => 'monitoring/list/comments?comment_type=(comment|ack)',
'priority' => 70 'priority' => 70
)); ));
$section->add('contacts', $this->translate('Contacts'), array( $section->add($this->translate('Contacts'), array(
'url' => 'monitoring/list/contacts', 'url' => 'monitoring/list/contacts',
'priority' => 70 'priority' => 70
)); ));
@ -96,33 +95,31 @@ $section->add('contacts', $this->translate('Contacts'), array(
/* /*
* History Section * History Section
*/ */
$section = $this->menuSection('history', $this->translate('History'), array( $section = $this->menuSection($this->translate('History'), array(
'title' => $this->translate('History'),
'icon' => 'img/icons/history.png' 'icon' => 'img/icons/history.png'
)); ));
$section->add('critical events', $this->translate('Critical Events'), array( $section->add($this->translate('Critical Events'), array(
'title' => $this->translate('Critical Events'),
'url' => 'monitoring/list/statehistorysummary', 'url' => 'monitoring/list/statehistorysummary',
'priority' => 50 'priority' => 50
)); ));
$section->add('notifications', $this->translate('Notifications'), array( $section->add($this->translate('Notifications'), array(
'url' => 'monitoring/list/notifications' 'url' => 'monitoring/list/notifications'
)); ));
$section->add('events', $this->translate('Events'), array( $section->add($this->translate('Events'), array(
'title' => $this->translate('All Events'), 'title' => $this->translate('All Events'),
'url' => 'monitoring/list/eventhistory?timestamp>=-7%20days' 'url' => 'monitoring/list/eventhistory?timestamp>=-7%20days'
)); ));
$section->add('timeline', $this->translate('Timeline'))->setUrl('monitoring/timeline'); $section->add($this->translate('Timeline'))->setUrl('monitoring/timeline');
/* /*
* System Section * System Section
*/ */
$section = $this->menuSection('system', $this->translate('System')); $section = $this->menuSection($this->translate('System'));
$section->add('process info', $this->translate('Process Info'), array( $section->add($this->translate('Process Info'), array(
'url' => 'monitoring/process/info', 'url' => 'monitoring/process/info',
'priority' => 120 'priority' => 120
)); ));
$section->add('performance info', $this->translate('Performance Info'), array( $section->add($this->translate('Performance Info'), array(
'url' => 'monitoring/process/performance', 'url' => 'monitoring/process/performance',
'priority' => 130 'priority' => 130
)); ));
@ -130,19 +127,16 @@ $section->add('performance info', $this->translate('Performance Info'), array(
/* /*
* Dashboard * Dashboard
*/ */
$dashboard = $this->dashboard('current-incidents', $this->translate('Current Incidents')); $dashboard = $this->dashboard($this->translate('Current Incidents'));
$dashboard->add( $dashboard->add(
'service problems',
$this->translate('Service Problems'), $this->translate('Service Problems'),
'monitoring/list/services?service_problem=1&limit=10&sort=service_severity' 'monitoring/list/services?service_problem=1&limit=10&sort=service_severity'
); );
$dashboard->add( $dashboard->add(
'recently recovered services',
$this->translate('Recently Recovered Services'), $this->translate('Recently Recovered Services'),
'monitoring/list/services?service_state=0&limit=10&sort=service_last_state_change&dir=desc' 'monitoring/list/services?service_state=0&limit=10&sort=service_last_state_change&dir=desc'
); );
$dashboard->add( $dashboard->add(
'host problems',
$this->translate('Host Problems'), $this->translate('Host Problems'),
'monitoring/list/hosts?host_problem=1&sort=host_severity' 'monitoring/list/hosts?host_problem=1&sort=host_severity'
); );