Nodes: add render functionality

This commit is contained in:
Thomas Gelf 2014-11-30 11:30:59 +01:00
parent 31626b4728
commit 7562ebd181
4 changed files with 126 additions and 0 deletions

View file

@ -234,4 +234,15 @@ class BusinessProcess
$this->warnings[] = $msg; $this->warnings[] = $msg;
} }
} }
public function renderHtml($view)
{
$html = '<div class="bp">';
foreach ($this->getRootNodes() as $name => $node) {
// showNode($this, $node, $this->slas, $this->opened, 'bp_')
$html .= $node->renderHtml($view);
}
$html .= '</div>';
return $html;
}
} }

View file

@ -14,6 +14,19 @@ class HostNode extends Node
$this->setState($object->state); $this->setState($object->state);
} }
public function renderLink($view)
{
if ($this->bp->isSimulationMode()) {
return $view->qlink($this->getHostname(), 'bpapp/host/simulate', array(
'node' => $this->name
));
} else {
return $view->qlink($this->getHostname(), 'monitoring/host/show', array(
'host' => $this->getHostname
));
}
}
public function getHostname() public function getHostname()
{ {
return $this->hostname; return $this->hostname;

View file

@ -49,6 +49,11 @@ abstract class Node
return $this->missing; return $this->missing;
} }
public function hasInfoUrl()
{
return false;
}
public function addChild(Node $node) public function addChild(Node $node)
{ {
if (array_key_exists((string) $node, $this->children)) { if (array_key_exists((string) $node, $this->children)) {
@ -175,6 +180,89 @@ abstract class Node
return array(); return array();
} }
protected function renderHtmlForChildren($view)
{
$html = '';
if ($this->hasChildren()) {
foreach ($this->getChildren() as $name => $child) {
$html .= '<tr><td>'
. $child->renderHtml($view)
. '</td></tr>';
}
}
return $html;
}
protected function getId($prefix = '')
{
return md5($prefix . (string) $this);
}
public function renderHtml($view, $prefix = '')
{
$id = $this->getId($prefix);
$state = strtolower($this->getStateName());
$handled = $this->isAcknowledged() || $this->isInDowntime();
$html = sprintf(
'<table class="bp %s%s%s" id="%s"><tbody><tr>',
$state === 'ok' ? 'ok' : 'problem ' . $state,
$handled ? ' handled' : '',
$this->hasChildren() ? ' operator process' : ' node service',
$id
);
if ($this->hasChildren()) {
$html .= sprintf(
'<th%s><span class="op">%s</span></th>',
sprintf(' rowspan="%d"', $this->countChildren() + 1),
$this->operatorHtml()
);
}
$title = preg_replace('~(</a>)~', implode('', $this->getIcons($view)) . '$1', $this->renderLink($view));
if ($this->hasInfoUrl()) {
$title = ' <a href="' . $this->getInfoUrl() . '" title="'
. mt('bpapp', 'More information') . ': ' . $this->getInfoUrl()
. '" style="float: right">'
. $view->icon('help')
. '</a>' . $title;
}
$html .= sprintf(
'<td>%s</td></tr>',
$title
);
foreach ($this->getChildren() as $name => $child) {
$html .= '<tr><td>' . $child->renderHtml($view, $id . '-') . '</td></tr>';
}
$html .= '</tbody></table>';
return $html;
}
public function renderLink($view)
{
return '<a href="#">' . $this->name . '</a>';
}
public function getIcons($view)
{
$icons = array();
if ($this->isInDowntime()) {
$icons[] = $view->icon('moon');
}
if ($this->isAcknowledged()) {
$icons[] = $view->icon('ok');
}
return $icons;
}
public function operatorHtml()
{
return '&nbsp;';
}
public function __toString() public function __toString()
{ {
return $this->name; return $this->name;

View file

@ -16,6 +16,20 @@ class ServiceNode extends Node
$this->setState($object->state); $this->setState($object->state);
} }
public function renderLink($view)
{
if ($this->bp->isSimulationMode()) {
return $view->qlink($this->getAlias(), 'bpapp/node/simulate', array(
'node' => $this->name
));
} else {
return $view->qlink($this->getAlias(), 'monitoring/show/service', array(
'host' => $this->getHostname(),
'service' => $this->getServiceDescription()
));
}
}
public function getHostname() public function getHostname()
{ {
return $this->hostname; return $this->hostname;