mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2026-02-14 16:33:14 -05:00
TileRenderer, Node: change rendering again...
...use a container div and provide multiple links now, this gives more flexibility
This commit is contained in:
parent
549c07b457
commit
6f33705173
2 changed files with 232 additions and 38 deletions
|
|
@ -26,13 +26,9 @@ class TileRenderer extends Renderer
|
|||
)
|
||||
);
|
||||
|
||||
if ($this->wantsRootNodes()) {
|
||||
$nodes = $bp->getChildren();
|
||||
} else {
|
||||
$nodes = $this->parent->getChildren();
|
||||
}
|
||||
$nodes = $this->getChildNodes();
|
||||
|
||||
if (! $this->isLocked()) {
|
||||
if (! $this->isLocked() && count($nodes) > 8) {
|
||||
$this->add($this->addNewNode());
|
||||
}
|
||||
|
||||
|
|
@ -77,10 +73,26 @@ class TileRenderer extends Renderer
|
|||
|
||||
protected function addNewNode()
|
||||
{
|
||||
return Element::create(
|
||||
'div',
|
||||
$div = Container::create(
|
||||
array('class' => 'addnew')
|
||||
)->add(
|
||||
);
|
||||
|
||||
$actions = Container::create(
|
||||
array(
|
||||
'class' => 'actions',
|
||||
'data-base-target' => '_self'
|
||||
)
|
||||
);
|
||||
|
||||
$link = Link::create(
|
||||
$this->translate('Add'),
|
||||
$this->getUrl()->with('action', 'add'),
|
||||
null,
|
||||
array(
|
||||
'title' => $this->translate('Add a new business process node')
|
||||
)
|
||||
);
|
||||
$actions->add(
|
||||
Link::create(
|
||||
Icon::create('plus'),
|
||||
$this->getUrl()->with('action', 'add'),
|
||||
|
|
@ -88,7 +100,9 @@ class TileRenderer extends Renderer
|
|||
array(
|
||||
'title' => $this->translate('Add a new business process node')
|
||||
)
|
||||
)->addContent($this->translate('Add'))
|
||||
)
|
||||
);
|
||||
|
||||
return $div->add($actions)->add($link);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace Icinga\Module\Businessprocess\Renderer\TileRenderer;
|
|||
use Icinga\Module\Businessprocess\BpNode;
|
||||
use Icinga\Module\Businessprocess\HostNode;
|
||||
use Icinga\Module\Businessprocess\Html\BaseElement;
|
||||
use Icinga\Module\Businessprocess\Html\Container;
|
||||
use Icinga\Module\Businessprocess\Html\HtmlString;
|
||||
use Icinga\Module\Businessprocess\Html\Icon;
|
||||
use Icinga\Module\Businessprocess\Html\Link;
|
||||
|
|
@ -18,6 +19,19 @@ class NodeTile extends BaseElement
|
|||
{
|
||||
protected $tag = 'div';
|
||||
|
||||
protected $renderer;
|
||||
|
||||
protected $name;
|
||||
|
||||
protected $node;
|
||||
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* @var Container
|
||||
*/
|
||||
private $actions;
|
||||
|
||||
/**
|
||||
* NodeTile constructor.
|
||||
* @param Renderer $renderer
|
||||
|
|
@ -27,52 +41,218 @@ class NodeTile extends BaseElement
|
|||
*/
|
||||
public function __construct(Renderer $renderer, $name, Node $node, $path = null)
|
||||
{
|
||||
$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;
|
||||
|
||||
$attributes = $this->attributes();
|
||||
$attributes->add('class', $renderer->getNodeClasses($node));
|
||||
$attributes->add('id', 'bp-' . (string) $node);
|
||||
|
||||
if ($node instanceof MonitoredNode) {
|
||||
$attributes->add('data-base-target', '_next');
|
||||
$url = $node->getUrl();
|
||||
} else {
|
||||
$bp = $renderer->getBusinessProcess();
|
||||
$params = array(
|
||||
'config' => $node instanceof ImportedNode ?
|
||||
$node->getConfigName() :
|
||||
$bp->getName()
|
||||
);
|
||||
$this->addActions();
|
||||
|
||||
if ($name !== null) {
|
||||
$params['node'] = $name;
|
||||
}
|
||||
$link = $this->getMainNodeLink();
|
||||
$this->add($link);
|
||||
|
||||
$url = $renderer->getBaseUrl();
|
||||
$p = $url->getParams();
|
||||
$p->mergeValues($params);
|
||||
if (! empty($path)) {
|
||||
$p->addValues('path', $path);
|
||||
if ($node instanceof BpNode) {
|
||||
if ($renderer->isBreadcrumb()) {
|
||||
$link->addContent($renderer->renderStateBadges($node->getStateSummary()));
|
||||
} else {
|
||||
$this->addContent($renderer->renderStateBadges($node->getStateSummary()));
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
protected function makeBpUrl(BpNode $node)
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
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);
|
||||
if ($node instanceof ServiceNode) {
|
||||
$link = Link::create(
|
||||
Icon::create('service'),
|
||||
$node->getAlias(),
|
||||
$url
|
||||
)->addContent($node->getHostname())
|
||||
->addContent(HtmlString::create('<br />'))
|
||||
->addContent($node->getServiceDescription());
|
||||
);
|
||||
} elseif ($node instanceof HostNode) {
|
||||
$link = Link::create(
|
||||
Icon::create('host'),
|
||||
$url
|
||||
)->addContent($node->getHostname());
|
||||
$link = Link::create(
|
||||
$node->getHostname(),
|
||||
$url
|
||||
);
|
||||
} else {
|
||||
$link = Link::create($node->getAlias(), $url);
|
||||
}
|
||||
|
||||
$this->add($link);
|
||||
return $link;
|
||||
}
|
||||
|
||||
protected function addDetailsActions()
|
||||
{
|
||||
$node = $this->node;
|
||||
$url = $this->getMainNodeUrl($node);
|
||||
|
||||
if ($node instanceof BpNode) {
|
||||
$link->addContent($renderer->renderStateBadges($node->getStateSummary()));
|
||||
$this->actions()->add(Link::create(
|
||||
Icon::create('dashboard'),
|
||||
$url->with('mode', 'tile'),
|
||||
null,
|
||||
array('title' => $this->translate('Show tiles for this subtree'))
|
||||
))->add(Link::create(
|
||||
Icon::create('sitemap'),
|
||||
$url->with('mode', 'tree'),
|
||||
null,
|
||||
array(
|
||||
'title' => $this->translate('Show this subtree as a tree'),
|
||||
)
|
||||
));
|
||||
} else {
|
||||
$url = $this->makeMonitoredNodeUrl($node);
|
||||
if ($node instanceof ServiceNode) {
|
||||
$this->actions()->add(Link::create(
|
||||
Icon::create('service'),
|
||||
$url,
|
||||
null,
|
||||
array('data-base-target' => '_next')
|
||||
));
|
||||
|
||||
} elseif ($node instanceof HostNode) {
|
||||
$this->actions()->add(Link::create(
|
||||
Icon::create('host'),
|
||||
$url,
|
||||
null,
|
||||
array('data-base-target' => '_next')
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function addActionLinks()
|
||||
{
|
||||
$node = $this->node;
|
||||
$renderer = $this->renderer;
|
||||
|
||||
if ($node instanceof BpNode) {
|
||||
$this->actions()->add(Link::create(
|
||||
Icon::create('edit'),
|
||||
$renderer->getUrl()->with('action', 'edit'),
|
||||
null,
|
||||
array('title' => $this->translate('Modify this business process node'))
|
||||
));
|
||||
} else {
|
||||
$this->actions()->add(Link::create(
|
||||
Icon::create('magic'),
|
||||
$renderer->getUrl()->with('action', 'simulate')->with('simulationnode', $this->name),
|
||||
null,
|
||||
array('title' => $this->translate('Show the business impact of this node by simulating a specific state'))
|
||||
));
|
||||
}
|
||||
|
||||
$this->actions()->add(Link::create(
|
||||
Icon::create('cancel'),
|
||||
$renderer->getUrl()->with('action', 'delete'),
|
||||
null,
|
||||
array('title' => $this->translate('Delete this node'))
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue