inspect: studio-like tree
This commit is contained in:
parent
190b783709
commit
416cf848ab
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||||
|
use Icinga\Module\Director\Core\RestApiClient;
|
||||||
|
use Icinga\Module\Director\Core\CoreApi;
|
||||||
|
|
||||||
|
class Director_InspectController extends ActionController
|
||||||
|
{
|
||||||
|
public function typesAction()
|
||||||
|
{
|
||||||
|
$this->view->title = $this->translate('Icinga2 object types');
|
||||||
|
$api = $this->api();
|
||||||
|
$types = $api->getTypes();
|
||||||
|
$rootNodes = array();
|
||||||
|
foreach ($types as $name => $type) {
|
||||||
|
if (property_exists($type, 'base')) {
|
||||||
|
$base = $type->base;
|
||||||
|
if (! property_exists($types[$base], 'children')) {
|
||||||
|
$types[$base]->children = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$types[$base]->children[$name] = $type;
|
||||||
|
} else {
|
||||||
|
$rootNodes[$name] = $type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->view->types = $rootNodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function typeAction()
|
||||||
|
{
|
||||||
|
print_r($this->api()->getType($this->params->get('name')));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function api()
|
||||||
|
{
|
||||||
|
$apiconfig = $this->Config()->getSection('api');
|
||||||
|
$client = new RestApiClient($apiconfig->get('address'), $apiconfig->get('port'));
|
||||||
|
$client->setCredentials($apiconfig->get('username'), $apiconfig->get('password'));
|
||||||
|
$api = new CoreApi($client);
|
||||||
|
return $api;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
function dumpTree($tree, $self, $level = 0)
|
||||||
|
{
|
||||||
|
$html = '';
|
||||||
|
foreach ($tree as $name => $node) {
|
||||||
|
$html .= '<li>';
|
||||||
|
$link = $self->qlink(
|
||||||
|
$name,
|
||||||
|
'director/inspect/type',
|
||||||
|
array('name' => $name),
|
||||||
|
array('class' => $node->abstract ? 'abstract' : 'object')
|
||||||
|
);
|
||||||
|
if (property_exists($node, 'children')) {
|
||||||
|
$html .= '<span class="handle"> </span>';
|
||||||
|
$html .= $link;
|
||||||
|
$html .= '<ul>' . dumpTree($node->children, $self, $level + 1) . '</ul>';
|
||||||
|
} else {
|
||||||
|
$html .= $link;
|
||||||
|
}
|
||||||
|
$html .= '</li>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
<div class="controls">
|
||||||
|
<?= $this->tabs ?>
|
||||||
|
<h1><?= $this->escape($this->title) ?></h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="content">
|
||||||
|
<ul class="tree" style="margin-left: 2em;" data-base-target="_next">
|
||||||
|
<?= dumpTree($this->types, $this) ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
|
@ -15,6 +15,28 @@ class CoreApi
|
||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTypes()
|
||||||
|
{
|
||||||
|
return $this->client->get('types')->getResult('name');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType($type)
|
||||||
|
{
|
||||||
|
$res = $this->client->get('types', array('name' => $type))->getResult('name');
|
||||||
|
return $res[$type]; // TODO: error checking
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listObjects($type, $pluralType)
|
||||||
|
{
|
||||||
|
// TODO: more abstraction needed
|
||||||
|
return $this->client->get(
|
||||||
|
'objects/' . $pluralType,
|
||||||
|
array(
|
||||||
|
'attrs' => array($type . '.__name', $type . '.name'),
|
||||||
|
)
|
||||||
|
)->getResult('__name');
|
||||||
|
}
|
||||||
|
|
||||||
public function getModules()
|
public function getModules()
|
||||||
{
|
{
|
||||||
return $this->client->get('config/packages')->getResult('name');
|
return $this->client->get('config/packages')->getResult('name');
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 945 B |
Binary file not shown.
After Width: | Height: | Size: 524 B |
Loading…
Reference in New Issue