MonitoredNode: add new simpler url/link helpers

This commit is contained in:
Thomas Gelf 2016-11-28 00:18:53 +01:00
parent a986859fdc
commit 01a982a0bc
3 changed files with 67 additions and 38 deletions

View file

@ -2,7 +2,7 @@
namespace Icinga\Module\Businessprocess;
use Icinga\Module\Businessprocess\Web\Component\Link;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Web\Url;
class HostNode extends MonitoredNode
@ -44,20 +44,9 @@ class HostNode extends MonitoredNode
}
}
public function renderLink($view)
public function getAlias()
{
if ($this->isMissing()) {
return '<span class="missing">' . $view->escape($this->hostname) . '</span>';
}
$params = array(
'host' => $this->getHostname(),
);
if ($this->bp->hasBackendName()) {
$params['backend'] = $this->bp->getBackendName();
}
return Link::create($this->hostname, 'monitoring/host/show', $params)->render();
return $this->getHostname();
}
protected function getActionIcons($view)
@ -86,4 +75,31 @@ class HostNode extends MonitoredNode
{
return $this->hostname;
}
public function getUrl()
{
$params = array(
'host' => $this->getHostname(),
);
if ($this->bp->hasBackendName()) {
$params['backend'] = $this->bp->getBackendName();
}
return Url::fromPath('monitoring/host/show', $params);
}
public function getLink()
{
return Link::create($this->hostname, $this->getUrl());
}
public function renderLink($view)
{
if ($this->isMissing()) {
return '<span class="missing">' . $view->escape($this->hostname) . '</span>';
}
return $this->getLink()->render();
}
}

View file

@ -2,11 +2,22 @@
namespace Icinga\Module\Businessprocess;
use Icinga\Module\Businessprocess\Web\Component\Container;
use Icinga\Module\Businessprocess\Web\Component\Link;
use Icinga\Module\Businessprocess\Html\Container;
use Icinga\Module\Businessprocess\Html\Link;
abstract class MonitoredNode extends Node
{
abstract public function getUrl();
public function getLink()
{
if ($this->isMissing()) {
return Link::create($this->getAlias(), '#');
} else {
return Link::create($this->getAlias(), $this->getUrl());
}
}
protected function prepareActions(Container $actions)
{
$actions->add(

View file

@ -2,7 +2,7 @@
namespace Icinga\Module\Businessprocess;
use Icinga\Module\Businessprocess\Web\Component\Link;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Web\Url;
class ServiceNode extends MonitoredNode
@ -26,27 +26,6 @@ class ServiceNode extends MonitoredNode
}
}
public function renderLink($view)
{
if ($this->isMissing()) {
return '<span class="missing">' . $view->escape($this->getAlias()) . '</span>';
}
$params = array(
'host' => $this->getHostname(),
'service' => $this->getServiceDescription()
);
if ($this->bp->hasBackendName()) {
$params['backend'] = $this->bp->getBackendName();
}
return Link::create(
$this->getAlias(),
'monitoring/service/show',
$params
)->render();
}
protected function getActionIcons($view)
{
$icons = array();
@ -83,4 +62,27 @@ class ServiceNode extends MonitoredNode
{
return $this->hostname . ': ' . $this->service;
}
public function getUrl()
{
$params = array(
'host' => $this->getHostname(),
'service' => $this->getServiceDescription()
);
if ($this->bp->hasBackendName()) {
$params['backend'] = $this->bp->getBackendName();
}
return Url::fromPath('monitoring/service/show', $params);
}
public function renderLink($view)
{
if ($this->isMissing()) {
return '<span class="missing">' . $view->escape($this->getAlias()) . '</span>';
}
return $this->getLink()->render();
}
}