icingaweb2-module-businessp.../library/Businessprocess/Renderer/TileRenderer.php

114 lines
2.8 KiB
PHP
Raw Normal View History

<?php
namespace Icinga\Module\Businessprocess\Renderer;
use Icinga\Module\Businessprocess\Html\Container;
2016-11-29 09:20:13 -05:00
use Icinga\Module\Businessprocess\Html\Icon;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Renderer\TileRenderer\NodeTile;
class TileRenderer extends Renderer
{
/**
* @inheritdoc
*/
public function render()
{
2017-01-11 08:33:35 -05:00
$bp = $this->config;
$nodesDiv = Container::create(
array(
'class' => array(
'tiles',
$this->howMany()
),
'data-base-target' => '_self',
)
);
$nodes = $this->getChildNodes();
if (! $this->isLocked() && count($nodes) > 8) {
2016-11-29 09:20:13 -05:00
$this->add($this->addNewNode());
}
2016-11-27 20:26:12 -05:00
$path = $this->getCurrentPath();
foreach ($nodes as $name => $node) {
2016-11-27 20:26:12 -05:00
$this->add(new NodeTile($this, $name, $node, $path));
}
if ($this->wantsRootNodes()) {
$unbound = $this->createUnboundParent($bp);
if ($unbound->hasChildren()) {
$name = $unbound->getAlias();
$this->add(new NodeTile($this, $name, $unbound));
}
}
2016-12-16 13:43:00 -05:00
if (! $this->isLocked()) {
$this->add($this->addNewNode());
}
$nodesDiv->addContent($this->getContent());
$this->setContent($nodesDiv);
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()
{
$count = $this->countChildNodes();
$howMany = 'normal';
if ($count <= 6) {
$howMany = 'few';
} elseif ($count > 12) {
$howMany = 'many';
}
return $howMany;
}
2016-11-29 09:20:13 -05:00
protected function addNewNode()
{
$div = Container::create(
2016-11-29 09:20:13 -05:00
array('class' => 'addnew')
);
$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(
2016-11-29 09:20:13 -05:00
Link::create(
Icon::create('plus'),
$this->getUrl()->with('action', 'add'),
null,
array(
'title' => $this->translate('Add a new business process node')
)
)
2016-11-29 09:20:13 -05:00
);
return $div->add($actions)->add($link);
2016-11-29 09:20:13 -05:00
}
}