Core: give empty list on 404, remove obsolete...

...view scripts
This commit is contained in:
Thomas Gelf 2017-07-13 08:03:16 +02:00
parent e27bb05fb1
commit 8216daa3af
5 changed files with 17 additions and 98 deletions

View File

@ -1,9 +0,0 @@
<div class="controls">
<?= $this->tabs ?>
</div>
<div class="content">
<pre>
<?= $this->escape($this->renderPlainObject($this->object)) ?>
</pre>
</div>

View File

@ -1,31 +0,0 @@
<div class="controls">
<?= $this->tabs ?>
<h1><?= $this->escape($this->title) ?></h1>
</div>
<div class="content">
<?php if ($this->objects): ?>
<p><?= sprintf($this->translate('%d objects found'), count($this->objects)) ?></p>
<table class="common-table table-row-selectable" data-base-target="_next">
<thead><tr><th><?= $this->translate('Object name') ?></th></tr></thead>
<tbody>
<?php foreach ($this->objects as $object): ?>
<tr><td><?= $this->qlink(
str_replace('!', ': ', $object),
'director/inspect/object',
array(
'endpoint' => $this->endpoint,
'type' => $this->type->name,
'plural' => $this->type->plural_name,
'name' => $object
)
) ?></td></tr>
<?php endforeach ?>
</tbody>
</table>
<?php else: ?>
<p><?= $this->translate('No object found') ?></p>
<?php endif ?>
<h2>Type attributes</h2>
<pre><?= $this->renderPlainObject($this->type) ?></pre>
</div>

View File

@ -1,51 +0,0 @@
<?php
function dumpTree($tree, $self, $showLinks = false, $level = 0)
{
$html = '';
foreach ($tree as $name => $node) {
$html .= '<li>';
if ($showLinks || $name === 'ConfigObject') {
$link = $self->qlink(
$name,
'director/inspect/type',
array('endpoint' => $self->endpoint, 'name' => $name),
array('class' => $node->abstract ? 'abstract' : 'object')
);
} else {
$link = sprintf(
'<a class="%s" href="#">%s</a>',
$node->abstract ? 'abstract' : 'object',
$name
);
}
if (property_exists($node, 'children')) {
$html .= '<span class="handle"> </span>';
$html .= $link;
$html .= '<ul>' . dumpTree(
$node->children,
$self,
$showLinks || $name === 'ConfigObject',
$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>

View File

@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Core;
use Exception; use Exception;
use Icinga\Exception\IcingaException; use Icinga\Exception\IcingaException;
use Icinga\Exception\NotFoundError;
use Icinga\Module\Director\Db; use Icinga\Module\Director\Db;
use Icinga\Module\Director\IcingaConfig\IcingaConfig; use Icinga\Module\Director\IcingaConfig\IcingaConfig;
use Icinga\Module\Director\Objects\IcingaObject; use Icinga\Module\Director\Objects\IcingaObject;
@ -322,12 +323,16 @@ constants
{ {
// TODO: more abstraction needed // TODO: more abstraction needed
// TODO: autofetch and cache pluraltypes // TODO: autofetch and cache pluraltypes
$result = $this->client->get( try {
'objects/' . $pluralType, $result = $this->client->get(
array( 'objects/' . $pluralType,
'attrs' => array('__name') array(
) 'attrs' => array('__name')
)->getResult('name'); )
)->getResult('name');
} catch (NotFoundError $e) {
$result = [];
}
return array_keys($result); return array_keys($result);
} }

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Director\Core; namespace Icinga\Module\Director\Core;
use Icinga\Exception\IcingaException; use Icinga\Exception\IcingaException;
use Icinga\Exception\NotFoundError;
class RestApiResponse class RestApiResponse
{ {
@ -89,7 +90,11 @@ class RestApiResponse
} }
if (property_exists($result, 'error')) { if (property_exists($result, 'error')) {
if (property_exists($result, 'status')) { if (property_exists($result, 'status')) {
throw new IcingaException('API request failed: ' . $result->status); if ((int) $result->error === 404) {
throw new NotFoundError($result->status);
} else {
throw new IcingaException('API request failed: ' . $result->status);
}
} else { } else {
throw new IcingaException('API request failed: ' . var_export($result, 1)); throw new IcingaException('API request failed: ' . var_export($result, 1));
} }