Merge branch 'feature/menu-item-renderer-backend-4139'

resolves #4139
This commit is contained in:
Alexander Fuhr 2015-04-30 16:15:33 +02:00
commit 15b86e5be7
5 changed files with 160 additions and 9 deletions

View File

@ -234,7 +234,8 @@ class Menu implements RecursiveIterator
$section = $this->add(t('System'), array(
'icon' => 'wrench',
'priority' => 200
'priority' => 200,
'renderer' => 'ProblemMenuItemRenderer'
));
$section->add(t('Configuration'), array(
'url' => 'config',
@ -469,6 +470,26 @@ class Menu implements RecursiveIterator
return $this->permission;
}
/**
* Get parent menu
*
* @return \Icinga\Web\Menu
*/
public function getParent()
{
return $this->parent;
}
/**
* Get submenus
*
* @return array
*/
public function getSubMenus()
{
return $this->subMenus;
}
/**
* Set permission a user is required to have granted to display the menu item
*

View File

@ -0,0 +1,64 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Web\Menu;
use Icinga\Web\Menu;
class ProblemMenuItemRenderer extends MenuItemRenderer
{
/**
* Set of summarized problems from submenus
*
* @var array
*/
protected $summary = array();
/**
* Renders the html content of a single menu item and summarizes submenu problems
*
* @param Menu $menu
*
* @return string
*/
public function render(Menu $menu)
{
if ($menu->getParent() !== null && $menu->hasSubMenus()) {
/** @var $submenu Menu */
foreach ($menu->getSubMenus() as $submenu) {
$renderer = $submenu->getRenderer();
if (method_exists($renderer, 'getSummary')) {
if ($renderer->getSummary() !== null) {
$this->summary[] = $renderer->getSummary();
}
}
}
}
return $this->getBadge() . $this->createLink($menu);
}
/**
* Get the problem badge
*
* @return string
*/
protected function getBadge()
{
if (count($this->summary) > 0) {
$problems = 0;
$titles = array();
foreach ($this->summary as $summary) {
$problems += $summary['problems'];
$titles[] = $summary['title'];
}
return sprintf(
'<div title="%s" class="badge-container"><span class="badge badge-critical">%s</span></div>',
implode(', ', $titles),
$problems
);
}
return '';
}
}

View File

@ -208,7 +208,8 @@ $section->add($this->translate('Alert Summary'), array(
$section = $this->menuSection($this->translate('System'));
$section->add($this->translate('Monitoring Health'), array(
'url' => 'monitoring/process/info',
'priority' => 120
'priority' => 120,
'renderer' => 'Icinga\Module\Monitoring\Web\Menu\BackendAvailabilityMenuItemRenderer'
));
/*

View File

@ -0,0 +1,62 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Web\Menu;
use Icinga\Web\Menu as Menu;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Web\Menu\MenuItemRenderer;
class BackendAvailabilityMenuItemRenderer extends MenuItemRenderer
{
/**
* Checks whether the monitoring backend is running or not
*
* @return mixed
*/
protected function isCurrentlyRunning()
{
return MonitoringBackend::instance()->select()->from(
'programstatus',
array(
'is_currently_running'
)
)->getQuery()->fetchRow()->is_currently_running;
}
/**
* @see MenuItemRenderer::render()
*/
public function render(Menu $menu)
{
return $this->getBadge() . $this->createLink($menu);
}
protected function getBadge()
{
if (! (bool)$this->isCurrentlyRunning()) {
return sprintf(
'<div title="%s" class="badge-container"><span class="badge badge-critical">%s</span></div>',
mt('monitoring', 'monitoring backend is not running'),
1
);
}
return '';
}
/**
* Get the problem data for the summary
*
* @return array|null
*/
public function getSummary()
{
if (! (bool)$this->isCurrentlyRunning()) {
return array(
'problems' => 1,
'title' => mt('monitoring', 'monitoring backend is not running')
);
}
return null;
}
}

View File

@ -173,19 +173,15 @@ form.instance-features span.description, form.object-features span.description {
}
}
table.avp form.object-features div.header h4,
table.avp h4.customvar {
table.avp form.object-features div.header h4 {
margin: 0;
}
table.avp .customvar ul,
table.avp .customvar ul li {
table.avp .customvar ul {
list-style-type: none;
margin: 0;
margin-top: -0.5em;
margin-bottom: -0.5em;
padding: 0;
padding-left: 0.5em;
padding-left: 1.5em;
}
div.selection-info {
@ -219,3 +215,10 @@ hr.command-separator {
border: none;
border-bottom: 2px solid @colorPetrol;
}
div.backend-not-running {
background: @colorCritical;
color: white;
text-align: center;
padding: 0.1em;
}