[icinga-checkins] icinga.org: icingaweb2-module-director/feature/job-scheduling-11627: Object/HostController: delegate preview rendering

git at icinga.org git at icinga.org
Tue May 3 10:04:59 CEST 2016


Module: icingaweb2-module-director
Branch: feature/job-scheduling-11627
Commit: 3d03baff3844275a104f8b4fa5aa1b8039cf1048
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=3d03baff3844275a104f8b4fa5aa1b8039cf1048

Author: Thomas Gelf <thomas at gelf.net>
Date:   Tue May  3 09:07:28 2016 +0200

Object/HostController: delegate preview rendering

---

 application/controllers/HostController.php         |   42 --------------------
 application/views/scripts/object/show.phtml        |   12 ++++--
 .../Director/Web/Controller/ObjectController.php   |   32 ++++++++++-----
 3 files changed, 30 insertions(+), 56 deletions(-)

diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php
index c8196a2..fb19355 100644
--- a/application/controllers/HostController.php
+++ b/application/controllers/HostController.php
@@ -120,46 +120,4 @@ class HostController extends ObjectController
             )
         );
     }
-
-    public function renderAction()
-    {
-        $this->renderAgentExtras();
-        return parent::renderAction();
-    }
-
-    protected function renderAgentExtras()
-    {
-        $host = $this->object;
-        $db = $this->db();
-        if ($host->object_type !== 'object') {
-            return;
-        }
-
-        if ($host->getResolvedProperty('has_agent') !== 'y') {
-            return;
-        }
-
-        $name = $host->object_name;
-        if (IcingaEndpoint::exists($name, $db)) {
-            return;
-        }
-
-        $props = array(
-            'object_name'  => $name,
-            'object_type'  => 'object',
-            'log_duration' => 0
-        );
-        if ($host->getResolvedProperty('master_should_connect') === 'y') {
-            $props['host'] = $host->getResolvedProperty('address');
-            $props['zone_id'] = $host->getResolvedProperty('zone_id');
-        }
-
-        $this->view->extraObjects = array(
-            IcingaEndpoint::create($props),
-            IcingaZone::create(array(
-                'object_name' => $name,
-                'parent'      => $db->getMasterZoneName()
-            ), $db)->setEndpointList(array($name))
-        );
-    }
 }
diff --git a/application/views/scripts/object/show.phtml b/application/views/scripts/object/show.phtml
index fd71724..bc20c9f 100644
--- a/application/views/scripts/object/show.phtml
+++ b/application/views/scripts/object/show.phtml
@@ -10,7 +10,7 @@
 <?php if ($object->disabled === 'y'): ?>
 <p class="error"><?= $this->translate('This object will not be deployed as it has been disabled') ?></p>
 <?php endif ?>
-<?php if ($object->isExternal()): ?>
+<?php if ($this->isExternal): ?>
 <p><?= $this->translate(
     'This is an external object. It has been imported from Icinga 2 throught the'
     . ' Core API and cannot be managed with the Icinga Director. It is however'
@@ -19,7 +19,11 @@
     . ' object more enjoyable'
 ) ?></p>
 <?php endif ?>
-<pre<?php if ($object->disabled === 'y'): ?> class="disabled"<?php endif ?>><?= $this->escape($object) ?><?php if ($this->extraObjects): ?>
-<?= implode('', $this->extraObjects) ?>
-<?php endif ?></pre>
+<?php foreach ($this->config->getFiles() as $filename => $file): ?>
+<?php if (! $this->isExternal): ?><h2><?= $this->escape($filename) ?></h2><?php endif ?>
+<pre<?php if ($this->isDisabled): ?> class="disabled"<?php elseif ($this->isExternal): ?> class="logfile"<?php endif ?>>
+<?= $this->escape($file->getContent()) ?>
+</pre>
+<?php endforeach ?>
+
 </div>
diff --git a/library/Director/Web/Controller/ObjectController.php b/library/Director/Web/Controller/ObjectController.php
index 4792251..b38525b 100644
--- a/library/Director/Web/Controller/ObjectController.php
+++ b/library/Director/Web/Controller/ObjectController.php
@@ -6,6 +6,7 @@ use Exception;
 use Icinga\Exception\IcingaException;
 use Icinga\Exception\InvalidPropertyException;
 use Icinga\Exception\NotFoundError;
+use Icinga\Module\Director\IcingaConfig\IcingaConfig;
 use Icinga\Module\Director\Objects\IcingaObject;
 use Icinga\Web\Url;
 
@@ -103,23 +104,22 @@ abstract class ObjectController extends ActionController
         $type = $this->getType();
         $this->getTabs()->activate('render');
         $object = $this->object;
+        $this->view->isDisabled = $object->disabled === 'y';
+        $this->view->isExternal = $object->isExternal();
 
         if ($this->params->shift('resolved')) {
-            $this->view->object = $object::fromPlainObject(
+            $object = $object::fromPlainObject(
                 $object->toPlainObject(true),
                 $object->getConnection()
             );
 
-            if ($object->imports()->count() > 0) {
-                $this->view->actionLinks = $this->view->qlink(
-                    $this->translate('Show normal'),
-                    $this->getRequest()->getUrl()->without('resolved'),
-                    null,
-                    array('class' => 'icon-resize-small state-warning')
-                );
-            }
+            $this->view->actionLinks = $this->view->qlink(
+                $this->translate('Show normal'),
+                $this->getRequest()->getUrl()->without('resolved'),
+                null,
+                array('class' => 'icon-resize-small state-warning')
+            );
         } else {
-            $this->view->object = $object;
 
             if ($object->supportsImports() && $object->imports()->count() > 0) {
                 $this->view->actionLinks = $this->view->qlink(
@@ -131,6 +131,18 @@ abstract class ObjectController extends ActionController
             }
         }
 
+        if ($this->view->isExternal) {
+            $object->object_type = 'object';
+        }
+
+        if ($this->view->isDisabledd) {
+            $object->disabled = 'n';
+        }
+
+        $this->view->object = $object;
+        $this->view->config = new IcingaConfig($this->db());
+        $object->renderToConfig($this->view->config);
+
         $this->view->title = sprintf(
             $this->translate('Config preview: %s'),
             $object->object_name



More information about the icinga-checkins mailing list