show/activitylog: show object syntax, not props

This commit is contained in:
Thomas Gelf 2015-08-28 23:45:16 +02:00
parent 7b1fda25bd
commit 632873595b
3 changed files with 34 additions and 52 deletions

View File

@ -1,6 +1,7 @@
<?php
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
use Icinga\Module\Director\Objects\IcingaObject;
use Icinga\Module\Director\Util;
use Icinga\Module\Director\Web\Controller\ActionController;
@ -14,6 +15,30 @@ class Director_ShowController extends ActionController
$this->view->entry = $this->db()->fetchActivityLogEntry(Util::hex2binary($checksum));
}
$entry = $this->view->entry;
if ($entry->old_properties) {
$old = $this->createObject($entry->object_type, $entry->old_properties);
if ($entry->new_properties) {
$new = $this->createObject($entry->object_type, $entry->old_properties);
$new->setProperties((array) json_decode($entry->new_properties));
} else {
$new = null;
}
} else {
$old = null;
$new = $this->createObject($entry->object_type, $entry->new_properties);
}
$this->view->entry = $entry;
$this->view->newObject = $new;
$this->view->oldObject = $old;
$this->view->title = $this->translate('Activity');
}
protected function createObject($type, $props)
{
$props = json_decode($props);
return IcingaObject::createByType($type, (array) $props, $this->db());
}
}

View File

@ -4,24 +4,5 @@
$entry->object_name
) ?></h2>
<h3><?= $this->translate('Properties') ?></h3>
<table class="log-properties">
<?php
$new = json_decode($entry->new_properties);
foreach ($new as $key => $value) {
if ($key === 'id') continue;
if ($value === null) continue;
if (is_array($value)) $value = implode(', ', $value);
if (is_object($value)) $value = json_encode($value);
echo ' <tr><th>' . $this->escape($key) . '</th><td>';
echo $this->escape($value);
echo "</td></tr>\n";
}
?>
</table>
<pre><?= $this->escape((string) $this->newObject) ?></pre>

View File

@ -4,38 +4,14 @@
$entry->object_name
) ?></h2>
<h3><?= $this->translate('Properties') ?></h3>
<table class="log-properties">
<?php
$old = json_decode($entry->old_properties);
$new = json_decode($entry->new_properties);
foreach ($old as $key => $value) {
if ($key === 'id') continue;
$modified = array_key_exists($key, $new);
if ($value === null && ! $modified) continue;
if (is_array($value)) $value = implode(', ', $value);
if (is_object($value)) $value = json_encode($value);
echo ' <tr><th>' . $this->escape($key) . '</th><td>';
if ($modified) {
$newval = $new->$key;
if (is_array($newval)) $newval = implode(', ', $newval);
if (is_object($newval)) $newval = json_encode($newval);
printf(
'<span class="old">%s</span> <span class="new">%s</span>',
$this->escape($value),
$this->escape($newval)
);
} else {
echo $this->escape($value);
}
echo "</td></tr>\n";
}
?>
<!-- TODO: diff, old/new class -->
<tr><td style="vertical-align: top; width: 50%">
<h3><?= $this->translate('Former state') ?></h3>
<pre><?= $this->escape((string) $this->oldObject) ?></pre>
</td><td style="vertical-align: top; width: 50%">
<h3><?= $this->translate('New object') ?></h3>
<pre><?= $this->escape((string) $this->newObject) ?></pre>
</td></tr>
</table>