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\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;
|
2019-01-17 07:21:46 -05:00
|
|
|
use ipl\Html\BaseHtmlElement;
|
|
|
|
|
use ipl\Html\Html;
|
2016-11-27 18:12:07 -05:00
|
|
|
|
2019-01-17 07:21:46 -05:00
|
|
|
class NodeTile extends BaseHtmlElement
|
2016-11-27 18:12:07 -05:00
|
|
|
{
|
|
|
|
|
protected $tag = 'div';
|
|
|
|
|
|
2016-12-16 13:39:48 -05:00
|
|
|
protected $renderer;
|
|
|
|
|
|
|
|
|
|
protected $name;
|
|
|
|
|
|
|
|
|
|
protected $node;
|
|
|
|
|
|
|
|
|
|
protected $path;
|
|
|
|
|
|
|
|
|
|
/**
|
2019-01-17 07:21:46 -05:00
|
|
|
* @var BaseHtmlElement
|
2016-12-16 13:39:48 -05:00
|
|
|
*/
|
|
|
|
|
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()
|
|
|
|
|
{
|
2019-01-17 07:21:46 -05:00
|
|
|
$this->actions = Html::tag(
|
|
|
|
|
'div',
|
|
|
|
|
[
|
2016-12-16 13:39:48 -05:00
|
|
|
'class' => 'actions',
|
2018-12-12 09:35:21 -05:00
|
|
|
'data-base-target' => '_self'
|
2019-01-17 07:21:46 -05:00
|
|
|
]
|
2016-12-16 13:39:48 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $this->add($this->actions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
|
{
|
|
|
|
|
$renderer = $this->renderer;
|
|
|
|
|
$node = $this->node;
|
|
|
|
|
|
2019-01-17 07:21:46 -05:00
|
|
|
$attributes = $this->getAttributes();
|
2016-11-27 18:12:07 -05:00
|
|
|
$attributes->add('class', $renderer->getNodeClasses($node));
|
|
|
|
|
$attributes->add('id', 'bp-' . (string) $node);
|
2018-12-17 08:43:40 -05:00
|
|
|
if (! $renderer->isLocked()) {
|
|
|
|
|
$attributes->add('data-node-name', (string) $node);
|
|
|
|
|
}
|
2016-11-27 18:12:07 -05:00
|
|
|
|
2019-01-22 08:09:50 -05:00
|
|
|
if (! $renderer->isBreadcrumb()) {
|
|
|
|
|
$this->addDetailsActions();
|
2016-11-27 18:12:07 -05:00
|
|
|
|
2019-01-22 08:09:50 -05:00
|
|
|
if (! $renderer->isLocked()) {
|
|
|
|
|
$this->addActionLinks();
|
2016-11-27 18:12:07 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-22 08:09:50 -05:00
|
|
|
$link = $this->getMainNodeLink();
|
|
|
|
|
$this->add($link);
|
2016-12-16 13:39:48 -05:00
|
|
|
|
2019-01-22 08:09:50 -05:00
|
|
|
if ($node instanceof BpNode && !$renderer->isBreadcrumb()) {
|
|
|
|
|
$this->add(Html::tag(
|
|
|
|
|
'p',
|
|
|
|
|
['class' => 'children-count'],
|
|
|
|
|
$node->hasChildren()
|
|
|
|
|
? Html::tag(
|
|
|
|
|
'span',
|
|
|
|
|
null,
|
|
|
|
|
sprintf('%u %s', $node->countChildren(), mt('businessprocess', 'Children'))
|
|
|
|
|
)
|
|
|
|
|
: null
|
|
|
|
|
));
|
|
|
|
|
$this->add($renderer->renderStateBadges($node->getStateSummary()));
|
2016-12-16 13:39:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-01-17 07:21:46 -05:00
|
|
|
* @return BaseHtmlElement
|
2016-12-16 13:39:48 -05:00
|
|
|
*/
|
|
|
|
|
protected function getMainNodeLink()
|
|
|
|
|
{
|
|
|
|
|
$node = $this->node;
|
|
|
|
|
$url = $this->getMainNodeUrl($node);
|
2016-11-27 20:09:11 -05:00
|
|
|
if ($node instanceof ServiceNode) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$link = Html::tag('a', ['href' => $url, 'data-base-target' => '_next'], $node->getAlias());
|
2016-11-27 20:09:11 -05:00
|
|
|
} elseif ($node instanceof HostNode) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$link = Html::tag('a', ['href' => $url, 'data-base-target' => '_next'], $node->getHostname());
|
2016-11-27 20:09:11 -05:00
|
|
|
} else {
|
2019-01-17 07:21:46 -05:00
|
|
|
$link = Html::tag('a', ['href' => $url], $node->getAlias());
|
2017-02-16 08:05:16 -05:00
|
|
|
if ($node instanceof ImportedNode) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$link->getAttributes()->add('data-base-target', '_next');
|
2018-12-12 09:36:51 -05:00
|
|
|
} else {
|
2019-01-17 07:21:46 -05:00
|
|
|
$link->getAttributes()->add('data-base-target', '_self');
|
2017-02-16 08:05:16 -05:00
|
|
|
}
|
2016-11-27 20:09:11 -05:00
|
|
|
}
|
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) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$this->actions()->add(Html::tag(
|
|
|
|
|
'a',
|
|
|
|
|
[
|
|
|
|
|
'data-base-target' => '_self',
|
|
|
|
|
'href' => $url->with('mode', 'tile'),
|
|
|
|
|
'title' => mt('businessprocess', 'Show tiles for this subtree')
|
|
|
|
|
],
|
|
|
|
|
Html::tag('i', ['class' => 'icon icon-dashboard'])
|
|
|
|
|
))->add(Html::tag(
|
|
|
|
|
'a',
|
|
|
|
|
[
|
|
|
|
|
'data-base-target' => '_next',
|
|
|
|
|
'href' => $url->with('mode', 'tree'),
|
|
|
|
|
'title' => mt('businessprocess', 'Show this subtree as a tree')
|
|
|
|
|
],
|
|
|
|
|
Html::tag('i', ['class' => 'icon icon-sitemap'])
|
2016-12-16 13:39:48 -05:00
|
|
|
));
|
2018-06-25 09:31:34 -04:00
|
|
|
|
|
|
|
|
$url = $node->getInfoUrl();
|
|
|
|
|
|
|
|
|
|
if ($url !== null) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$link = Html::tag(
|
|
|
|
|
'a',
|
|
|
|
|
[
|
|
|
|
|
'href' => $url,
|
|
|
|
|
'class' => 'node-info',
|
|
|
|
|
'title' => sprintf('%s: %s', mt('businessprocess', 'More information'), $url)
|
|
|
|
|
],
|
|
|
|
|
Html::tag('i', ['class' => 'icon icon-circled'])
|
2018-11-08 05:36:16 -05:00
|
|
|
);
|
|
|
|
|
if (preg_match('#^http(?:s)?://#', $url)) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$link->addAttributes(['target' => '_blank']);
|
2018-11-08 05:36:16 -05:00
|
|
|
}
|
|
|
|
|
$this->actions()->add($link);
|
2018-06-25 09:31:34 -04:00
|
|
|
}
|
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) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$this->actions()->add(Html::tag(
|
|
|
|
|
'a',
|
|
|
|
|
['href' => $node->getUrl(), 'data-base-target' => '_next'],
|
|
|
|
|
Html::tag('i', ['class' => 'icon icon-service'])
|
2016-12-16 13:39:48 -05:00
|
|
|
));
|
|
|
|
|
} elseif ($node instanceof HostNode) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$this->actions()->add(Html::tag(
|
|
|
|
|
'a',
|
|
|
|
|
['href' => $node->getUrl(), 'data-base-target' => '_next'],
|
|
|
|
|
Html::tag('i', ['class' => 'icon icon-host'])
|
2016-12-16 13:39:48 -05:00
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function addActionLinks()
|
|
|
|
|
{
|
|
|
|
|
$node = $this->node;
|
|
|
|
|
$renderer = $this->renderer;
|
2017-02-08 11:59:03 -05:00
|
|
|
if ($node instanceof MonitoredNode) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$this->actions()->add(Html::tag(
|
|
|
|
|
'a',
|
|
|
|
|
[
|
|
|
|
|
'href' => $renderer->getUrl()
|
|
|
|
|
->with('action', 'simulation')
|
|
|
|
|
->with('simulationnode', $this->name),
|
|
|
|
|
'title' => mt(
|
|
|
|
|
'businessprocess',
|
|
|
|
|
'Show the business impact of this node by simulating a specific state'
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
Html::tag('i', ['class' => 'icon icon-magic'])
|
2016-12-16 13:39:48 -05:00
|
|
|
));
|
2018-06-28 03:01:26 -04:00
|
|
|
|
2019-01-17 07:21:46 -05:00
|
|
|
$this->actions()->add(Html::tag(
|
|
|
|
|
'a',
|
|
|
|
|
[
|
|
|
|
|
'href' => $renderer->getUrl()
|
|
|
|
|
->with('action', 'editmonitored')
|
|
|
|
|
->with('editmonitorednode', $node->getName()),
|
|
|
|
|
'title' => mt('businessprocess', 'Modify this monitored node')
|
|
|
|
|
],
|
|
|
|
|
Html::tag('i', ['class' => 'icon icon-edit'])
|
2018-06-28 03:01:26 -04:00
|
|
|
));
|
2016-11-27 18:12:07 -05:00
|
|
|
}
|
2016-12-16 13:39:48 -05:00
|
|
|
|
2018-08-14 04:37:44 -04:00
|
|
|
if (! $this->renderer->getBusinessProcess()->getMetadata()->canModify()
|
|
|
|
|
|| $node->getName() === '__unbound__'
|
|
|
|
|
) {
|
2017-02-08 11:59:03 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($node instanceof BpNode) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$this->actions()->add(Html::tag(
|
|
|
|
|
'a',
|
|
|
|
|
[
|
|
|
|
|
'href' => $renderer->getUrl()
|
|
|
|
|
->with('action', 'edit')
|
|
|
|
|
->with('editnode', $node->getName()),
|
|
|
|
|
'title' => mt('businessprocess', 'Modify this business process node')
|
|
|
|
|
],
|
|
|
|
|
Html::tag('i', ['class' => 'icon icon-edit'])
|
2017-02-08 11:59:03 -05:00
|
|
|
));
|
2019-01-08 03:51:30 -05:00
|
|
|
|
|
|
|
|
$this->actions()->add(Html::tag(
|
|
|
|
|
'a',
|
|
|
|
|
[
|
|
|
|
|
'href' => $renderer->getUrl()->with([
|
|
|
|
|
'action' => 'add',
|
|
|
|
|
'node' => $node->getName()
|
|
|
|
|
]),
|
|
|
|
|
'title' => mt('businessprocess', 'Add a new sub-node to this business process')
|
|
|
|
|
],
|
|
|
|
|
Html::tag('i', ['class' => 'icon icon-plus'])
|
|
|
|
|
));
|
2017-02-08 11:59:03 -05:00
|
|
|
}
|
|
|
|
|
|
2017-01-03 05:20:01 -05:00
|
|
|
$params = array(
|
|
|
|
|
'action' => 'delete',
|
|
|
|
|
'deletenode' => $node->getName(),
|
|
|
|
|
);
|
|
|
|
|
|
2019-01-17 07:21:46 -05:00
|
|
|
$this->actions()->add(Html::tag(
|
|
|
|
|
'a',
|
|
|
|
|
[
|
|
|
|
|
'href' => $renderer->getUrl()->with($params),
|
|
|
|
|
'title' => mt('businessprocess', 'Delete this node')
|
|
|
|
|
],
|
2019-02-01 06:06:46 -05:00
|
|
|
Html::tag('i', ['class' => 'icon icon-cancel'])
|
2016-12-16 13:39:48 -05:00
|
|
|
));
|
2016-11-27 18:12:07 -05:00
|
|
|
}
|
2016-11-27 18:24:36 -05:00
|
|
|
}
|