mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-09-29 04:39:06 +02:00
Allow the data backend, columns and generated tooltips to be defined in the configuration instead of providing subclasses for every new configuration. Provide an abstract BadgeMenuItemRenderer that allows creating Badges with less boilerplate. fixes #9694
66 lines
1.4 KiB
PHP
66 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Icinga\Web\Menu;
|
|
|
|
use Icinga\Web\Menu;
|
|
|
|
abstract class BadgeMenuItemRenderer extends MenuItemRenderer
|
|
{
|
|
const STATE_OK = 'ok';
|
|
const STATE_CRITICAL = 'critical';
|
|
const STATE_WARNING = 'warning';
|
|
const STATE_PENDING = 'pending';
|
|
const STATE_UNKNOWN = 'unknown';
|
|
|
|
/**
|
|
* Defines the color of the badge
|
|
*
|
|
* @return string
|
|
*/
|
|
abstract public function getState();
|
|
|
|
/**
|
|
* The amount of items to display in the badge
|
|
*
|
|
* @return int
|
|
*/
|
|
abstract public function getCount();
|
|
|
|
/**
|
|
* The tooltip title
|
|
*
|
|
* @return string
|
|
*/
|
|
abstract public function getTitle();
|
|
|
|
/**
|
|
* Renders the html content of a single menu item
|
|
*
|
|
* @param Menu $menu
|
|
*
|
|
* @return string
|
|
*/
|
|
public function render(Menu $menu)
|
|
{
|
|
return $this->renderBadge() . $this->createLink($menu);
|
|
}
|
|
|
|
/**
|
|
* Render the badge
|
|
*
|
|
* @return string
|
|
*/
|
|
protected function renderBadge()
|
|
{
|
|
if ($count = $this->getCount()) {
|
|
return sprintf(
|
|
'<div title="%s" class="badge-container"><span class="badge badge-%s">%s</span></div>',
|
|
$this->getView()->escape($this->getTitle()),
|
|
$this->getView()->escape($this->getState()),
|
|
$count
|
|
);
|
|
}
|
|
return '';
|
|
}
|
|
}
|