From 3d03baff3844275a104f8b4fa5aa1b8039cf1048 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 3 May 2016 09:07:28 +0200 Subject: [PATCH] Object/HostController: delegate preview rendering --- application/controllers/HostController.php | 42 ------------------- application/views/scripts/object/show.phtml | 12 ++++-- .../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 c8196a24..fb193551 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 fd717243..bc20c9f4 100644 --- a/application/views/scripts/object/show.phtml +++ b/application/views/scripts/object/show.phtml @@ -10,7 +10,7 @@ disabled === 'y'): ?>

translate('This object will not be deployed as it has been disabled') ?>

-isExternal()): ?> +isExternal): ?>

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' ) ?>

-disabled === 'y'): ?> class="disabled">escape($object) ?>extraObjects): ?> -extraObjects) ?> - +config->getFiles() as $filename => $file): ?> +isExternal): ?>

escape($filename) ?>

+isDisabled): ?> class="disabled"isExternal): ?> class="logfile"> +escape($file->getContent()) ?> + + + diff --git a/library/Director/Web/Controller/ObjectController.php b/library/Director/Web/Controller/ObjectController.php index 47922514..b38525b7 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