Skip to content

Commit

Permalink
Merge branch 'feature/menu-item-renderer-backend-4139'
Browse files Browse the repository at this point in the history
resolves #4139
  • Loading branch information
Alexander Fuhr committed Apr 30, 2015
2 parents 7c0be30 + 8484a27 commit 15b86e5
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 9 deletions.
23 changes: 22 additions & 1 deletion library/Icinga/Web/Menu.php
Expand Up @@ -234,7 +234,8 @@ protected function addMainMenuItems()

$section = $this->add(t('System'), array(
'icon' => 'wrench',
'priority' => 200
'priority' => 200,
'renderer' => 'ProblemMenuItemRenderer'
));
$section->add(t('Configuration'), array(
'url' => 'config',
Expand Down Expand Up @@ -469,6 +470,26 @@ public function getPermission()
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
*
Expand Down
64 changes: 64 additions & 0 deletions library/Icinga/Web/Menu/ProblemMenuItemRenderer.php
@@ -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 '';
}
}
3 changes: 2 additions & 1 deletion modules/monitoring/configuration.php
Expand Up @@ -208,7 +208,8 @@
$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'
));

/*
Expand Down
@@ -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;
}
}
17 changes: 10 additions & 7 deletions modules/monitoring/public/css/module.less
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

0 comments on commit 15b86e5

Please sign in to comment.