mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-31 01:34:09 +02:00
parent
7db05fa043
commit
95d1ce371c
@ -5,14 +5,13 @@ namespace Icinga\Controllers;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Icinga\Application\Config;
|
use Icinga\Application\Config;
|
||||||
use Icinga\Application\Icinga;
|
|
||||||
use Icinga\Exception\IcingaException;
|
|
||||||
use Icinga\Exception\NotFoundError;
|
use Icinga\Exception\NotFoundError;
|
||||||
use Icinga\Data\DataArray\ArrayDatasource;
|
use Icinga\Data\DataArray\ArrayDatasource;
|
||||||
use Icinga\Forms\ConfirmRemovalForm;
|
use Icinga\Forms\ConfirmRemovalForm;
|
||||||
use Icinga\Forms\Navigation\NavigationConfigForm;
|
use Icinga\Forms\Navigation\NavigationConfigForm;
|
||||||
use Icinga\Web\Controller;
|
use Icinga\Web\Controller;
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
|
use Icinga\Web\Navigation\Navigation;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
|
|
||||||
@ -22,18 +21,11 @@ use Icinga\Web\Url;
|
|||||||
class NavigationController extends Controller
|
class NavigationController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The default item types provided by Icinga Web 2
|
* The global navigation item type configuration
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $defaultItemTypes;
|
protected $itemTypeConfig;
|
||||||
|
|
||||||
/**
|
|
||||||
* The item types provided by Icinga Web 2's modules
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $moduleItemTypes;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@ -41,30 +33,7 @@ class NavigationController extends Controller
|
|||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
parent::init();
|
parent::init();
|
||||||
$this->defaultItemTypes = array(
|
$this->itemTypeConfig = Navigation::getItemTypeConfiguration();
|
||||||
'menu-item' => array(
|
|
||||||
'label' => $this->translate('Menu Entry'),
|
|
||||||
'config' => 'menu'
|
|
||||||
),
|
|
||||||
'dashlet' => array(
|
|
||||||
'label' => 'Dashlet',
|
|
||||||
'config' => 'dashboard'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$moduleItemTypes = array();
|
|
||||||
$moduleManager = Icinga::app()->getModuleManager();
|
|
||||||
foreach ($moduleManager->getLoadedModules() as $module) {
|
|
||||||
if ($this->hasPermission($moduleManager::MODULE_PERMISSION_NS . $module->getName())) {
|
|
||||||
foreach ($module->getNavigationItems() as $type => $options) {
|
|
||||||
if (! isset($moduleItemTypes[$type])) {
|
|
||||||
$moduleItemTypes[$type] = $options;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->moduleItemTypes = $moduleItemTypes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,19 +41,11 @@ class NavigationController extends Controller
|
|||||||
*
|
*
|
||||||
* @param string $type
|
* @param string $type
|
||||||
*
|
*
|
||||||
* @return string It's $type if no label can be found
|
* @return string $type if no label can be found
|
||||||
*/
|
*/
|
||||||
protected function getItemLabel($type)
|
protected function getItemLabel($type)
|
||||||
{
|
{
|
||||||
if (isset($this->moduleItemTypes[$type]['label'])) {
|
return isset($this->itemTypeConfig[$type]['label']) ? $this->itemTypeConfig[$type]['label'] : $type;
|
||||||
return $this->moduleItemTypes[$type]['label'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($this->defaultItemTypes[$type]['label'])) {
|
|
||||||
return $this->defaultItemTypes[$type]['label'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,11 +56,7 @@ class NavigationController extends Controller
|
|||||||
protected function listItemTypes()
|
protected function listItemTypes()
|
||||||
{
|
{
|
||||||
$types = array();
|
$types = array();
|
||||||
foreach ($this->defaultItemTypes as $type => $options) {
|
foreach ($this->itemTypeConfig as $type => $options) {
|
||||||
$types[$type] = isset($options['label']) ? $options['label'] : $type;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->moduleItemTypes as $type => $options) {
|
|
||||||
$types[$type] = isset($options['label']) ? $options['label'] : $type;
|
$types[$type] = isset($options['label']) ? $options['label'] : $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,6 +451,39 @@ class Navigation implements ArrayAccess, Countable, IteratorAggregate
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the global navigation item type configuration
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getItemTypeConfiguration()
|
||||||
|
{
|
||||||
|
$defaultItemTypes = array(
|
||||||
|
'menu-item' => array(
|
||||||
|
'label' => t('Menu Entry'),
|
||||||
|
'config' => 'menu'
|
||||||
|
),
|
||||||
|
'dashlet' => array(
|
||||||
|
'label' => 'Dashlet',
|
||||||
|
'config' => 'dashboard'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$moduleItemTypes = array();
|
||||||
|
$moduleManager = Icinga::app()->getModuleManager();
|
||||||
|
foreach ($moduleManager->getLoadedModules() as $module) {
|
||||||
|
if (Auth::getInstance()->hasPermission($moduleManager::MODULE_PERMISSION_NS . $module->getName())) {
|
||||||
|
foreach ($module->getNavigationItems() as $type => $options) {
|
||||||
|
if (! isset($moduleItemTypes[$type])) {
|
||||||
|
$moduleItemTypes[$type] = $options;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_merge($defaultItemTypes, $moduleItemTypes);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create and return a new set of navigation items for the given configuration
|
* Create and return a new set of navigation items for the given configuration
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user