2016-11-27 18:12:07 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Businessprocess\Renderer;
|
|
|
|
|
|
2019-02-21 06:29:35 -05:00
|
|
|
use Icinga\Module\Businessprocess\ImportedNode;
|
2016-11-27 18:12:07 -05:00
|
|
|
use Icinga\Module\Businessprocess\Renderer\TileRenderer\NodeTile;
|
2018-12-17 08:43:40 -05:00
|
|
|
use Icinga\Module\Businessprocess\Web\Form\CsrfToken;
|
2019-01-17 07:21:46 -05:00
|
|
|
use ipl\Html\Html;
|
2016-11-27 18:12:07 -05:00
|
|
|
|
|
|
|
|
class TileRenderer extends Renderer
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
|
|
|
|
public function render()
|
|
|
|
|
{
|
2017-01-11 08:33:35 -05:00
|
|
|
$bp = $this->config;
|
2019-01-17 07:21:46 -05:00
|
|
|
$nodesDiv = Html::tag(
|
|
|
|
|
'div',
|
|
|
|
|
[
|
2018-12-17 08:43:40 -05:00
|
|
|
'class' => ['sortable', 'tiles', $this->howMany()],
|
2020-02-26 03:30:28 -05:00
|
|
|
'data-base-target' => '_self',
|
2019-01-22 05:32:14 -05:00
|
|
|
'data-sortable-disabled' => $this->isLocked() ? 'true' : 'false',
|
2018-12-17 08:43:40 -05:00
|
|
|
'data-sortable-data-id-attr' => 'id',
|
2018-12-20 04:08:58 -05:00
|
|
|
'data-sortable-direction' => 'horizontal', // Otherwise movement is buggy on small lists
|
2019-02-21 06:29:35 -05:00
|
|
|
'data-csrf-token' => CsrfToken::generate()
|
2019-01-17 07:21:46 -05:00
|
|
|
]
|
2016-11-27 18:12:07 -05:00
|
|
|
);
|
2019-02-21 06:29:35 -05:00
|
|
|
|
|
|
|
|
if ($this->wantsRootNodes()) {
|
2019-02-22 03:12:07 -05:00
|
|
|
$nodesDiv->getAttributes()->add(
|
|
|
|
|
'data-action-url',
|
2020-02-25 09:26:50 -05:00
|
|
|
$this->getUrl()->with(['config' => $bp->getName()])->getAbsoluteUrl()
|
2019-02-22 03:12:07 -05:00
|
|
|
);
|
2019-02-21 06:29:35 -05:00
|
|
|
} else {
|
|
|
|
|
$nodeName = $this->parent instanceof ImportedNode
|
|
|
|
|
? $this->parent->getNodeName()
|
|
|
|
|
: $this->parent->getName();
|
|
|
|
|
$nodesDiv->getAttributes()
|
|
|
|
|
->add('data-node-name', $nodeName)
|
|
|
|
|
->add('data-action-url', $this->getUrl()
|
2020-02-25 09:26:50 -05:00
|
|
|
->with([
|
2019-02-21 06:29:35 -05:00
|
|
|
'config' => $this->parent->getBpConfig()->getName(),
|
|
|
|
|
'node' => $nodeName
|
|
|
|
|
])
|
|
|
|
|
->getAbsoluteUrl());
|
2019-01-15 06:41:02 -05:00
|
|
|
}
|
2016-11-27 18:12:07 -05:00
|
|
|
|
2016-12-16 13:39:48 -05:00
|
|
|
$nodes = $this->getChildNodes();
|
2016-11-27 18:12:07 -05:00
|
|
|
|
2016-11-27 20:26:12 -05:00
|
|
|
$path = $this->getCurrentPath();
|
2016-11-27 18:12:07 -05:00
|
|
|
foreach ($nodes as $name => $node) {
|
2019-02-21 05:32:32 -05:00
|
|
|
$this->add(new NodeTile($this, $node, $path));
|
2016-11-27 18:12:07 -05:00
|
|
|
}
|
|
|
|
|
|
2017-01-03 05:30:03 -05:00
|
|
|
if ($this->wantsRootNodes()) {
|
|
|
|
|
$unbound = $this->createUnboundParent($bp);
|
|
|
|
|
if ($unbound->hasChildren()) {
|
2019-02-21 05:32:32 -05:00
|
|
|
$this->add(new NodeTile($this, $unbound));
|
2017-01-03 05:30:03 -05:00
|
|
|
}
|
2016-11-28 18:34:28 -05:00
|
|
|
}
|
|
|
|
|
|
2019-01-17 07:21:46 -05:00
|
|
|
$nodesDiv->add($this->getContent());
|
2016-11-28 10:02:21 -05:00
|
|
|
$this->setContent($nodesDiv);
|
2016-11-27 18:12:07 -05:00
|
|
|
|
|
|
|
|
return parent::render();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A CSS class giving a rough indication of how many nodes we have
|
|
|
|
|
*
|
|
|
|
|
* This is used to show larger tiles when there are few and smaller
|
|
|
|
|
* ones if there are many.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
protected function howMany()
|
|
|
|
|
{
|
2016-12-09 10:59:25 -05:00
|
|
|
$count = $this->countChildNodes();
|
2016-11-27 18:12:07 -05:00
|
|
|
$howMany = 'normal';
|
|
|
|
|
|
2016-12-09 10:59:25 -05:00
|
|
|
if ($count <= 6) {
|
2016-11-27 18:12:07 -05:00
|
|
|
$howMany = 'few';
|
2016-12-09 10:59:25 -05:00
|
|
|
} elseif ($count > 12) {
|
2016-11-27 18:12:07 -05:00
|
|
|
$howMany = 'many';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $howMany;
|
|
|
|
|
}
|
|
|
|
|
}
|