2016-11-27 18:12:07 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Businessprocess\Renderer\TileRenderer;
|
|
|
|
|
|
|
|
|
|
use Icinga\Module\Businessprocess\BpNode;
|
2016-11-27 20:09:11 -05:00
|
|
|
use Icinga\Module\Businessprocess\HostNode;
|
2016-11-27 18:12:07 -05:00
|
|
|
use Icinga\Module\Businessprocess\Html\BaseElement;
|
2016-12-16 13:39:48 -05:00
|
|
|
use Icinga\Module\Businessprocess\Html\Container;
|
2016-11-27 20:09:11 -05:00
|
|
|
use Icinga\Module\Businessprocess\Html\HtmlString;
|
|
|
|
|
use Icinga\Module\Businessprocess\Html\Icon;
|
2016-11-27 18:12:07 -05:00
|
|
|
use Icinga\Module\Businessprocess\Html\Link;
|
|
|
|
|
use Icinga\Module\Businessprocess\ImportedNode;
|
|
|
|
|
use Icinga\Module\Businessprocess\MonitoredNode;
|
|
|
|
|
use Icinga\Module\Businessprocess\Node;
|
2016-11-28 16:12:56 -05:00
|
|
|
use Icinga\Module\Businessprocess\Renderer\Renderer;
|
2016-11-27 20:09:11 -05:00
|
|
|
use Icinga\Module\Businessprocess\ServiceNode;
|
2016-11-27 18:12:07 -05:00
|
|
|
|
|
|
|
|
class NodeTile extends BaseElement
|
|
|
|
|
{
|
|
|
|
|
protected $tag = 'div';
|
|
|
|
|
|
2016-12-16 13:39:48 -05:00
|
|
|
protected $renderer;
|
|
|
|
|
|
|
|
|
|
protected $name;
|
|
|
|
|
|
|
|
|
|
protected $node;
|
|
|
|
|
|
|
|
|
|
protected $path;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var Container
|
|
|
|
|
*/
|
|
|
|
|
private $actions;
|
|
|
|
|
|
2016-11-27 20:09:11 -05:00
|
|
|
/**
|
|
|
|
|
* NodeTile constructor.
|
2016-11-28 16:12:56 -05:00
|
|
|
* @param Renderer $renderer
|
2016-11-27 20:09:11 -05:00
|
|
|
* @param $name
|
|
|
|
|
* @param Node $node
|
|
|
|
|
* @param null $path
|
|
|
|
|
*/
|
2016-11-28 16:12:56 -05:00
|
|
|
public function __construct(Renderer $renderer, $name, Node $node, $path = null)
|
2016-11-27 18:12:07 -05:00
|
|
|
{
|
2016-12-16 13:39:48 -05:00
|
|
|
$this->renderer = $renderer;
|
|
|
|
|
$this->name = $name;
|
|
|
|
|
$this->node = $node;
|
|
|
|
|
$this->path = $path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function actions()
|
|
|
|
|
{
|
|
|
|
|
if ($this->actions === null) {
|
|
|
|
|
$this->addActions();
|
|
|
|
|
}
|
|
|
|
|
return $this->actions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function addActions()
|
|
|
|
|
{
|
|
|
|
|
$this->actions = Container::create(
|
|
|
|
|
array(
|
|
|
|
|
'class' => 'actions',
|
|
|
|
|
'data-base-target' => '_self'
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $this->add($this->actions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
|
{
|
|
|
|
|
$renderer = $this->renderer;
|
|
|
|
|
$node = $this->node;
|
|
|
|
|
|
2016-11-27 18:12:07 -05:00
|
|
|
$attributes = $this->attributes();
|
|
|
|
|
$attributes->add('class', $renderer->getNodeClasses($node));
|
|
|
|
|
$attributes->add('id', 'bp-' . (string) $node);
|
|
|
|
|
|
2016-12-16 13:39:48 -05:00
|
|
|
$this->addActions();
|
2016-11-27 18:12:07 -05:00
|
|
|
|
2016-12-16 13:39:48 -05:00
|
|
|
$link = $this->getMainNodeLink();
|
|
|
|
|
$this->add($link);
|
2016-11-27 18:12:07 -05:00
|
|
|
|
2016-12-16 13:39:48 -05:00
|
|
|
if ($node instanceof BpNode) {
|
|
|
|
|
if ($renderer->isBreadcrumb()) {
|
|
|
|
|
$link->addContent($renderer->renderStateBadges($node->getStateSummary()));
|
|
|
|
|
} else {
|
|
|
|
|
$this->addContent($renderer->renderStateBadges($node->getStateSummary()));
|
2016-11-27 18:12:07 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-16 13:39:48 -05:00
|
|
|
if (! $renderer->isBreadcrumb()) {
|
|
|
|
|
$this->addDetailsActions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! $renderer->isLocked()) {
|
|
|
|
|
$this->addActionLinks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return parent::render();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getMainNodeUrl(Node $node)
|
|
|
|
|
{
|
|
|
|
|
if ($node instanceof BpNode) {
|
|
|
|
|
return $this->makeBpUrl($node);
|
|
|
|
|
} else {
|
|
|
|
|
/** @var MonitoredNode $node */
|
|
|
|
|
return $node->getUrl();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-03 05:20:01 -05:00
|
|
|
protected function buildBaseNodeUrl(Node $node)
|
2016-12-16 13:39:48 -05:00
|
|
|
{
|
|
|
|
|
$path = $this->path;
|
|
|
|
|
$name = $this->name; // TODO: ??
|
|
|
|
|
$renderer = $this->renderer;
|
|
|
|
|
|
|
|
|
|
$bp = $renderer->getBusinessProcess();
|
|
|
|
|
$params = array(
|
|
|
|
|
'config' => $node instanceof ImportedNode ?
|
|
|
|
|
$node->getConfigName() :
|
|
|
|
|
$bp->getName()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($name !== null) {
|
|
|
|
|
$params['node'] = $name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$url = $renderer->getBaseUrl();
|
|
|
|
|
$p = $url->getParams();
|
|
|
|
|
$p->mergeValues($params);
|
|
|
|
|
if (! empty($path)) {
|
|
|
|
|
$p->addValues('path', $path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-03 05:20:01 -05:00
|
|
|
protected function makeBpUrl(BpNode $node)
|
|
|
|
|
{
|
|
|
|
|
return $this->buildBaseNodeUrl($node);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-16 13:39:48 -05:00
|
|
|
protected function makeMonitoredNodeUrl(MonitoredNode $node)
|
|
|
|
|
{
|
|
|
|
|
$path = $this->path;
|
|
|
|
|
$name = $this->name; // TODO: ??
|
|
|
|
|
$renderer = $this->renderer;
|
|
|
|
|
|
|
|
|
|
$bp = $renderer->getBusinessProcess();
|
|
|
|
|
$params = array(
|
|
|
|
|
'config' => $bp->getName()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($name !== null) {
|
|
|
|
|
$params['node'] = $node->getName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$url = $renderer->getBaseUrl();
|
|
|
|
|
$p = $url->getParams();
|
|
|
|
|
$p->mergeValues($params);
|
|
|
|
|
if (! empty($path)) {
|
|
|
|
|
$p->addValues('path', $path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Link
|
|
|
|
|
*/
|
|
|
|
|
protected function getMainNodeLink()
|
|
|
|
|
{
|
|
|
|
|
$node = $this->node;
|
|
|
|
|
$url = $this->getMainNodeUrl($node);
|
2016-11-27 20:09:11 -05:00
|
|
|
if ($node instanceof ServiceNode) {
|
|
|
|
|
$link = Link::create(
|
2016-12-16 13:39:48 -05:00
|
|
|
$node->getAlias(),
|
2016-12-17 13:18:15 -05:00
|
|
|
$url,
|
|
|
|
|
null,
|
|
|
|
|
array('data-base-target' => '_next')
|
2016-12-16 13:39:48 -05:00
|
|
|
);
|
2016-11-27 20:09:11 -05:00
|
|
|
} elseif ($node instanceof HostNode) {
|
2016-12-16 13:39:48 -05:00
|
|
|
$link = Link::create(
|
|
|
|
|
$node->getHostname(),
|
2016-12-17 13:18:15 -05:00
|
|
|
$url,
|
|
|
|
|
null,
|
|
|
|
|
array('data-base-target' => '_next')
|
2016-12-16 13:39:48 -05:00
|
|
|
);
|
2016-11-27 20:09:11 -05:00
|
|
|
} else {
|
|
|
|
|
$link = Link::create($node->getAlias(), $url);
|
|
|
|
|
}
|
2016-11-27 18:12:07 -05:00
|
|
|
|
2016-12-16 13:39:48 -05:00
|
|
|
return $link;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function addDetailsActions()
|
|
|
|
|
{
|
|
|
|
|
$node = $this->node;
|
|
|
|
|
$url = $this->getMainNodeUrl($node);
|
|
|
|
|
|
|
|
|
|
if ($node instanceof BpNode) {
|
|
|
|
|
$this->actions()->add(Link::create(
|
|
|
|
|
Icon::create('dashboard'),
|
|
|
|
|
$url->with('mode', 'tile'),
|
|
|
|
|
null,
|
2016-12-17 13:18:15 -05:00
|
|
|
array(
|
|
|
|
|
'title' => $this->translate('Show tiles for this subtree'),
|
|
|
|
|
'data-base-target' => '_next'
|
|
|
|
|
)
|
2016-12-16 13:39:48 -05:00
|
|
|
))->add(Link::create(
|
|
|
|
|
Icon::create('sitemap'),
|
|
|
|
|
$url->with('mode', 'tree'),
|
|
|
|
|
null,
|
|
|
|
|
array(
|
|
|
|
|
'title' => $this->translate('Show this subtree as a tree'),
|
2016-12-17 13:18:15 -05:00
|
|
|
'data-base-target' => '_next'
|
2016-12-16 13:39:48 -05:00
|
|
|
)
|
|
|
|
|
));
|
|
|
|
|
} else {
|
2016-12-17 13:18:15 -05:00
|
|
|
// $url = $this->makeMonitoredNodeUrl($node);
|
2016-12-16 13:39:48 -05:00
|
|
|
if ($node instanceof ServiceNode) {
|
|
|
|
|
$this->actions()->add(Link::create(
|
|
|
|
|
Icon::create('service'),
|
2016-12-17 13:18:15 -05:00
|
|
|
$node->getUrl(),
|
2016-12-16 13:39:48 -05:00
|
|
|
null,
|
|
|
|
|
array('data-base-target' => '_next')
|
|
|
|
|
));
|
|
|
|
|
} elseif ($node instanceof HostNode) {
|
|
|
|
|
$this->actions()->add(Link::create(
|
|
|
|
|
Icon::create('host'),
|
2016-12-17 13:18:15 -05:00
|
|
|
$node->getUrl(),
|
2016-12-16 13:39:48 -05:00
|
|
|
null,
|
|
|
|
|
array('data-base-target' => '_next')
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function addActionLinks()
|
|
|
|
|
{
|
|
|
|
|
$node = $this->node;
|
|
|
|
|
$renderer = $this->renderer;
|
|
|
|
|
|
2016-11-27 18:12:07 -05:00
|
|
|
if ($node instanceof BpNode) {
|
2016-12-16 13:39:48 -05:00
|
|
|
$this->actions()->add(Link::create(
|
|
|
|
|
Icon::create('edit'),
|
2017-01-03 05:20:01 -05:00
|
|
|
$renderer->getUrl()->with('action', 'edit')->with('editnode', $node->getName()),
|
2016-12-16 13:39:48 -05:00
|
|
|
null,
|
|
|
|
|
array('title' => $this->translate('Modify this business process node'))
|
|
|
|
|
));
|
2017-01-03 05:20:01 -05:00
|
|
|
} elseif ($node instanceof MonitoredNode) {
|
2016-12-16 13:39:48 -05:00
|
|
|
$this->actions()->add(Link::create(
|
|
|
|
|
Icon::create('magic'),
|
2017-01-03 05:20:01 -05:00
|
|
|
$renderer->getUrl()->with('action', 'simulation')
|
|
|
|
|
->with('simulationnode', $this->name),
|
2016-12-16 13:39:48 -05:00
|
|
|
null,
|
2017-01-03 05:20:01 -05:00
|
|
|
array('title' => $this->translate(
|
|
|
|
|
'Show the business impact of this node by simulating a specific state'
|
|
|
|
|
))
|
2016-12-16 13:39:48 -05:00
|
|
|
));
|
2016-11-27 18:12:07 -05:00
|
|
|
}
|
2016-12-16 13:39:48 -05:00
|
|
|
|
2017-01-03 05:20:01 -05:00
|
|
|
$params = array(
|
|
|
|
|
'action' => 'delete',
|
|
|
|
|
'deletenode' => $node->getName(),
|
|
|
|
|
);
|
|
|
|
|
|
2016-12-16 13:39:48 -05:00
|
|
|
$this->actions()->add(Link::create(
|
|
|
|
|
Icon::create('cancel'),
|
2017-01-03 05:20:01 -05:00
|
|
|
$renderer->getUrl()->with($params),
|
2016-12-16 13:39:48 -05:00
|
|
|
null,
|
|
|
|
|
array('title' => $this->translate('Delete this node'))
|
|
|
|
|
));
|
2016-11-27 18:12:07 -05:00
|
|
|
}
|
2016-11-27 18:24:36 -05:00
|
|
|
}
|