Objects: add template tree

This commit is contained in:
Thomas Gelf 2015-07-30 09:49:01 +02:00
parent ceb22f830d
commit b97cb14e05
2 changed files with 78 additions and 4 deletions

View File

@ -0,0 +1,65 @@
<?php
use Icinga\Web\Url;
function dumpTree($tree, $self, $level = 0)
{
$hasChildren = ! empty($tree->children);
if ($level === 0) {
$class = 'root';
} else {
$class = 'host';
}
if ($hasChildren) {
$collapsed = '';
} else {
$collapsed = ' class="collapsed"';
}
$html = '<li' . $collapsed . '>';
if ($hasChildren) {
ksort($tree->children);
$html .= '<span class="handle"> </span>';
}
if ($level === 0) {
$html .= '<a name="Templates" class="root">' . $self->escape($tree->name) . '</a>';
} else {
$html .= $self->qlink(
$tree->name,
'director/host',
array('name' => $tree->name),
array('class' => $class)
);
}
if ($hasChildren) {
$html .= '<ul>';
foreach ($tree->children as $child) {
$html .= dumpTree($child, $self, $level + 1);
}
$html .= '</ul>';
}
$html .= "</li>\n";
return $html;
}
?>
<div class="controls">
<?= $this->tabs ?>
<h1><?= $this->translate('Host template tree') ?></h1>
</div>
<div class="content">
<ul class="tree" data-base-target="_next">
<?= dumpTree(
(object) array(
'name' => 'Templates',
'children' => $this->tree
),
$this
) ?>
</ul>
</div>

View File

@ -16,14 +16,12 @@ abstract class ObjectsController extends ActionController
public function init()
{
$tabs = $this->getTabs();
$type = $this->getType();
$ltype = strtolower($type);
$object = $this->dummyObject();
if (in_array(ucfirst($type), $this->globalTypes)) {
$ltype = strtolower($type);
$tabs = $this->getTabs();
foreach ($this->globalTypes as $tabType) {
$ltabType = strtolower($tabType);
$tabs->add($ltabType, array(
@ -60,6 +58,11 @@ abstract class ObjectsController extends ActionController
}
}
$tabs->add('tree', array(
'url' => sprintf('director/%stemplates/tree', $type),
'label' => $this->translate('Tree'),
));
}
public function indexAction()
@ -103,6 +106,12 @@ abstract class ObjectsController extends ActionController
$this->render('objects/table', null, true);
}
public function treeAction()
{
$this->getTabs()->activate('tree');
$this->view->tree = $this->db()->fetchTemplateTree(strtolower($this->getType()));
}
protected function dummyObject()
{
if ($this->dummy === null) {