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
|
|
|
|
|
{
|
2022-07-19 08:58:16 -04:00
|
|
|
public function assemble()
|
2016-11-27 18:12:07 -05:00
|
|
|
{
|
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',
|
2023-07-26 11:15:26 -04:00
|
|
|
'data-sortable-disabled' => $this->isLocked() || $this->appliesCustomSorting()
|
|
|
|
|
? '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-11-27 20:26:12 -05:00
|
|
|
$path = $this->getCurrentPath();
|
2023-07-26 11:15:26 -04:00
|
|
|
foreach ($this->sort($this->getChildNodes()) 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
|
|
|
}
|
|
|
|
|
|
2022-07-19 08:58:16 -04:00
|
|
|
$nodesDiv->addHtml(...$this->getContent());
|
|
|
|
|
$this->setHtmlContent($nodesDiv);
|
2016-11-27 18:12:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
}
|
|
|
|
|
}
|