Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/menu-item-renderer-backend-4139'
resolves #4139
- Loading branch information
Showing
5 changed files
with
160 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
modules/monitoring/library/Monitoring/Web/Menu/BackendAvailabilityMenuItemRenderer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters