Use the new navigation to render the menu

refs #5600
This commit is contained in:
Johannes Meyer 2015-09-04 10:53:01 +02:00
parent 5ff3db8a3c
commit 294f9022f2
4 changed files with 119 additions and 20 deletions

View File

@ -3,11 +3,8 @@
namespace Icinga\Controllers;
use Icinga\Application\Icinga;
use Icinga\Web\Controller\ActionController;
use Icinga\Web\Hook;
use Icinga\Web\Menu;
use Icinga\Web\MenuRenderer;
use Icinga\Web\Url;
/**
* Create complex layout parts
@ -21,9 +18,6 @@ class LayoutController extends ActionController
{
$this->setAutorefreshInterval(15);
$this->_helper->layout()->disableLayout();
$url = Url::fromRequest();
$menu = new MenuRenderer(Menu::load(), $url->getRelativeUrl());
$this->view->menuRenderer = $menu->useCustomRenderer();
$this->view->menuRenderer = Icinga::app()->getMenu()->getRenderer();
}
}

View File

@ -1,8 +1,6 @@
<?php
use Icinga\Web\Url;
use Icinga\Web\Menu;
use Icinga\Web\MenuRenderer;
use Icinga\Application\Icinga;
// Don't render a menu for unauthenticated users unless menu is auth aware
if (! $this->auth()->isAuthenticated()) {
@ -27,10 +25,7 @@ if (! $this->auth()->isAuthenticated()) {
'layout/menu.phtml',
'default',
array(
'menuRenderer' => new MenuRenderer(
Menu::load(),
Url::fromRequest()->without('renderLayout')->getRelativeUrl()
)
'menuRenderer' => Icinga::app()->getMenu()->getRenderer()
)
) ?>
</div>

View File

@ -12,8 +12,5 @@ if ($searchDashboard->search('dummy')->getPane('search')->hasDashlets()): ?>
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
/>
</form>
<? endif; ?>
<nav>
<h1 id="navigation" class="sr-only"><?= t('Navigation'); ?></h1>
<?= $menuRenderer; ?>
</nav>
<?php endif; ?>
<?= $menuRenderer->setHeading(t('Navigation')); ?>

View File

@ -16,6 +16,7 @@ use Icinga\User;
use Icinga\Util\TimezoneDetect;
use Icinga\Util\Translator;
use Icinga\Web\Controller\Dispatcher;
use Icinga\Web\Navigation\Navigation;
use Icinga\Web\Notification;
use Icinga\Web\Session;
use Icinga\Web\Session\Session as BaseSession;
@ -139,6 +140,118 @@ class Web extends EmbeddedWeb
return $this->viewRenderer;
}
/**
* Return the app's menu
*
* @return Navigation
*/
public function getMenu()
{
if ($this->user !== null) {
$menu = array(
'dashboard' => array(
'label' => t('Dashboard'),
'url' => 'dashboard',
'icon' => 'dashboard',
'priority' => 10
),
'system' => array(
'label' => t('System'),
'icon' => 'services',
'priority' => 700,
'renderer' => array(
'SummaryNavigationItemRenderer',
'state' => 'critical'
),
'children' => array(
'about' => array(
'label' => t('About'),
'url' => 'about',
'priority' => 701
)
)
),
'configuration' => array(
'label' => t('Configuration'),
'icon' => 'wrench',
'permission' => 'config/*',
'priority' => 800,
'children' => array(
'application' => array(
'label' => t('Application'),
'url' => 'config/general',
'permission' => 'config/application/*',
'priority' => 810
),
'authentication' => array(
'label' => t('Authentication'),
'url' => 'config/userbackend',
'permission' => 'config/authentication/*',
'priority' => 820
),
'roles' => array(
'label' => t('Roles'),
'url' => 'role/list',
'permission' => 'config/authentication/roles/show',
'priority' => 830
),
'users' => array(
'label' => t('Users'),
'url' => 'user/list',
'permission' => 'config/authentication/users/show',
'priority' => 840
),
'groups' => array(
'label' => t('Usergroups'),
'url' => 'group/list',
'permission' => 'config/authentication/groups/show',
'priority' => 850
),
'modules' => array(
'label' => t('Modules'),
'url' => 'config/modules',
'permission' => 'config/modules',
'priority' => 890
)
)
),
'user' => array(
'label' => $this->user->getUsername(),
'icon' => 'user',
'priority' => 900,
'children' => array(
'preferences' => array(
'label' => t('Preferences'),
'url' => 'preference',
'priority' => 910
),
'logout' => array(
'label' => t('Logout'),
'url' => 'authentication/logout',
'priority' => 990,
'renderer' => array(
'NavigationItemRenderer',
'target' => '_self'
)
)
)
)
);
if (Logger::writesToFile()) {
$menu['system']['children']['application_log'] = array(
'label' => t('Application Log'),
'url' => 'list/applicationlog',
'priority' => 710
);
}
} else {
$menu = array();
}
return Navigation::fromArray($menu);
}
/**
* Dispatch public interface
*/