mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-30 01:04:12 +02:00
Activity log: add tabs, reorganize output
This commit is contained in:
parent
2706af6976
commit
2fb0e7c9c5
@ -9,6 +9,125 @@ use Icinga\Module\Director\Objects\IcingaObject;
|
|||||||
|
|
||||||
class ShowController extends ActionController
|
class ShowController extends ActionController
|
||||||
{
|
{
|
||||||
|
protected $defaultTab;
|
||||||
|
|
||||||
|
protected function activityTabs($entry)
|
||||||
|
{
|
||||||
|
$tabs = $this->getTabs();
|
||||||
|
if ($entry->action_name === 'modify') {
|
||||||
|
$tabs->add('diff', array(
|
||||||
|
'label' => $this->translate('Diff'),
|
||||||
|
'url' => 'director/show/activitylog',
|
||||||
|
'urlParams' => array('id' => $entry->id)
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->defaultTab = 'diff';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($entry->action_name, array('create', 'modify'))) {
|
||||||
|
$tabs->add('new', array(
|
||||||
|
'label' => $this->translate('New object'),
|
||||||
|
'url' => 'director/show/activitylog',
|
||||||
|
'urlParams' => array('id' => $entry->id, 'show' => 'new')
|
||||||
|
));
|
||||||
|
|
||||||
|
if ($this->defaultTab === null) {
|
||||||
|
$this->defaultTab = 'diff';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($entry->action_name, array('create', 'modify'))) {
|
||||||
|
$tabs->add('old', array(
|
||||||
|
'label' => $this->translate('Former object'),
|
||||||
|
'url' => 'director/show/activitylog',
|
||||||
|
'urlParams' => array('id' => $entry->id, 'show' => 'old')
|
||||||
|
));
|
||||||
|
|
||||||
|
if ($this->defaultTab === null) {
|
||||||
|
$this->defaultTab = 'diff';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tabs;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function showDiff($entry)
|
||||||
|
{
|
||||||
|
$this->view->title = sprintf('%s config diff', $entry->object_name);
|
||||||
|
$this->getTabs()->activate('diff');
|
||||||
|
$d = ConfigDiff::create(
|
||||||
|
$this->oldObject($entry),
|
||||||
|
$this->newObject($entry)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->view->output = $d->renderHtml();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function showOld($entry)
|
||||||
|
{
|
||||||
|
$this->view->title = sprintf('%s former config', $entry->object_name);
|
||||||
|
$this->getTabs()->activate('old');
|
||||||
|
$this->showObject($this->oldObject($entry));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function showNew($entry)
|
||||||
|
{
|
||||||
|
$this->view->title = sprintf('%s new config', $entry->object_name);
|
||||||
|
$this->getTabs()->activate('new');
|
||||||
|
$this->showObject($this->newObject($entry));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function oldObject($entry)
|
||||||
|
{
|
||||||
|
return $this->createObject($entry->object_type, $entry->old_properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function newObject($entry)
|
||||||
|
{
|
||||||
|
return $this->createObject(
|
||||||
|
$entry->object_type,
|
||||||
|
$entry->old_properties
|
||||||
|
)->setProperties((array) json_decode($entry->new_properties));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function showObject($object)
|
||||||
|
{
|
||||||
|
$this->view->output = '<pre>' . $this->view->escape(
|
||||||
|
(string) $object
|
||||||
|
) . '</pre>';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function showInfo($entry)
|
||||||
|
{
|
||||||
|
$typeName = $this->translate(
|
||||||
|
ucfirst(preg_replace('/^icinga_/', '', $entry->object_type)) // really?
|
||||||
|
);
|
||||||
|
|
||||||
|
switch ($entry->action_name) {
|
||||||
|
case 'create':
|
||||||
|
$this->view->title = sprintf(
|
||||||
|
$this->translate('%s "%s" has been created'),
|
||||||
|
$typeName,
|
||||||
|
$entry->object_name
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 'delete':
|
||||||
|
$this->view->title = sprintf(
|
||||||
|
$this->translate('%s "%s" has been deleted'),
|
||||||
|
$typeName,
|
||||||
|
$entry->object_name
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 'modify':
|
||||||
|
$this->view->title = sprintf(
|
||||||
|
$this->translate('%s "%s" has been modified'),
|
||||||
|
$typeName,
|
||||||
|
$entry->object_name
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function activitylogAction()
|
public function activitylogAction()
|
||||||
{
|
{
|
||||||
if ($id = $this->params->get('id')) {
|
if ($id = $this->params->get('id')) {
|
||||||
@ -18,32 +137,10 @@ class ShowController extends ActionController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$entry = $this->view->entry;
|
$entry = $this->view->entry;
|
||||||
|
$this->activityTabs($entry);
|
||||||
if ($entry->old_properties) {
|
$this->showInfo($entry);
|
||||||
$old = $this->createObject($entry->object_type, $entry->old_properties);
|
$func = 'show' . ucfirst($this->params->get('show', $this->defaultTab));
|
||||||
if ($entry->new_properties) {
|
$this->$func($entry);
|
||||||
$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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($old && $new) {
|
|
||||||
$d = ConfigDiff::create($old, $new);
|
|
||||||
$this->view->diff = strtr(
|
|
||||||
$d->renderHtml(),
|
|
||||||
array('\\n' => "\\n\n")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->view->entry = $entry;
|
|
||||||
$this->view->newObject = $new;
|
|
||||||
$this->view->oldObject = $old;
|
|
||||||
$this->view->title = $this->translate('Activity');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createObject($type, $props)
|
protected function createObject($type, $props)
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
<h2><?= sprintf(
|
|
||||||
'%s "%s" has been created',
|
|
||||||
ucfirst(preg_replace('/^icinga_/', '', $entry->object_type)),
|
|
||||||
$entry->object_name
|
|
||||||
) ?></h2>
|
|
||||||
|
|
||||||
<pre><?= $this->escape((string) $this->newObject) ?></pre>
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
|||||||
<h3><?= sprintf(
|
|
||||||
'%s "%s" has been deleted',
|
|
||||||
ucfirst(preg_replace('/^icinga_/', '', $entry->object_type)),
|
|
||||||
$entry->object_name
|
|
||||||
) ?></h3>
|
|
||||||
<pre>
|
|
||||||
<?= (string) $this->oldObject ?>
|
|
||||||
</pre>
|
|
@ -1,16 +0,0 @@
|
|||||||
<h2><?= sprintf(
|
|
||||||
'%s "%s" has been modified',
|
|
||||||
ucfirst(preg_replace('/^icinga_/', '', $entry->object_type)),
|
|
||||||
$entry->object_name
|
|
||||||
) ?></h2>
|
|
||||||
|
|
||||||
<table class="log-properties">
|
|
||||||
<tr><td style="vertical-align: top; width: 50%">
|
|
||||||
<h3><?= $this->translate('Former state') ?></h3>
|
|
||||||
<span class="diff old"><?= $this->diff ?></pre>
|
|
||||||
</td><td style="vertical-align: top; width: 50%">
|
|
||||||
<h3><?= $this->translate('New object') ?></h3>
|
|
||||||
<span class="diff new"><?= $this->diff ?></pre>
|
|
||||||
</td></tr>
|
|
||||||
</table>
|
|
||||||
|
|
@ -1,23 +1,8 @@
|
|||||||
<div class="controls">
|
<div class="controls">
|
||||||
<?= $this->tabs ?>
|
<?= $this->tabs ?>
|
||||||
|
<h1><?= $this->escape($this->title) ?></h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<?php
|
<?= $this->output ?>
|
||||||
|
|
||||||
switch ($entry->action_name) {
|
|
||||||
case 'create':
|
|
||||||
echo $this->render('show/activitylog-create.phtml');
|
|
||||||
break;
|
|
||||||
case 'modify':
|
|
||||||
echo $this->render('show/activitylog-modify.phtml');
|
|
||||||
break;
|
|
||||||
case 'delete':
|
|
||||||
echo $this->render('show/activitylog-delete.phtml');
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
echo 'Invalid action';
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user