From 87f88bf0c7533bf893c7e508fee081093a4274fc Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 2 Jan 2017 10:17:49 +0100 Subject: [PATCH] DirectorObjectForm: allow to hook custom code... ...after fields have been added --- .../tables/IcingaHostServiceSetTable.php | 79 ++++++++++++++----- .../Director/Web/Form/DirectorObjectForm.php | 5 ++ 2 files changed, 64 insertions(+), 20 deletions(-) diff --git a/application/tables/IcingaHostServiceSetTable.php b/application/tables/IcingaHostServiceSetTable.php index 4cdb64bf..2e478dc0 100644 --- a/application/tables/IcingaHostServiceSetTable.php +++ b/application/tables/IcingaHostServiceSetTable.php @@ -3,22 +3,25 @@ namespace Icinga\Module\Director\Tables; use Icinga\Module\Director\Objects\IcingaHost; -use Icinga\Module\Director\Web\Table\IcingaObjectTable; +use Icinga\Module\Director\Web\Table\QuickTable; -class IcingaHostServiceSetTable extends IcingaObjectTable +class IcingaHostServiceSetTable extends QuickTable { protected $title; protected $host; + private $lastSetId; + public function getColumns() { return array( - 'id' => 'sset.id', - 'name' => 'sset.object_name', - 'object_type' => 'sset.object_type', - 'description' => 'sset.description', - 'host_name' => 'h.object_name', + 'id' => 'pset.id', + 'service_set_id' => 'sset.id', + 'service_set_name' => 'sset.object_name', + 'name' => 's.object_name', + 'description' => 'sset.description', + 'host_name' => 'h.object_name', ); } @@ -26,7 +29,7 @@ class IcingaHostServiceSetTable extends IcingaObjectTable { $view = $this->view(); return array( - 'name' => $view->translate('Service set'), + 'name' => $view->translate('Service'), ); } @@ -36,6 +39,34 @@ class IcingaHostServiceSetTable extends IcingaObjectTable return $this; } + protected function beginTableBody() + { + return ''; + } + + protected function renderRow($row) + { + $html = ''; + $view = $this->view(); + if ($row->service_set_id !== $this->lastSetId) { + if ($this->lastSetId === null) { + $html .= "\n"; + } + $html .= parent::renderTitles((object) array( + 'name' => sprintf($view->translate('Service set: %s'), $row->service_set_name) + )); + $html .= "\n"; + $this->lastSetId = $row->service_set_id; + } + + return $html . parent::renderRow($row); + } + + protected function renderTitles($row) + { + return ''; + } + public function setHost(IcingaHost $host) { $this->host = $host; @@ -44,28 +75,36 @@ class IcingaHostServiceSetTable extends IcingaObjectTable protected function getActionUrl($row) { - // TODO: Remove once we got a separate apply table - if ($row->object_type === 'apply') { - $params['id'] = $row->id; - } else { - $params = array('name' => $row->name); - if ($row->host_name) { - $params['host'] = $row->host_name; - } - } + $params = array( + 'name' => $row->host_name, + 'service' => $row->name, + 'serviceSet' => $row->id, + ); - return $this->url('director/serviceset', $params); + return $this->url('director/host/servicesetservice', $params); } protected function getUnfilteredQuery() { return $this->db()->select()->from( - array('sset' => 'icinga_service_set'), + array('pset' => 'icinga_service_set'), array() - )->joinLeft( + )->join( + array('sseti' => 'icinga_service_set_inheritance'), + 'pset.id = sseti.parent_service_set_id', + array() + )->join( + array('sset' => 'icinga_service_set'), + 'sset.id = sseti.service_set_id', + array() + )->join( array('h' => 'icinga_host'), 'h.id = sset.host_id', array() + )->join( + array('s' => 'icinga_service'), + 'pset.id = s.service_set_id', + array() )->where('sset.host_id = ?', $this->host->id)->order('sset.object_name'); } diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php index f812dd0e..2333c2f0 100644 --- a/library/Director/Web/Form/DirectorObjectForm.php +++ b/library/Director/Web/Form/DirectorObjectForm.php @@ -334,9 +334,14 @@ abstract class DirectorObjectForm extends QuickForm { if ($this->fieldLoader) { $this->fieldLoader->addFieldsToForm($this); + $this->onAddedFields(); } } + protected function onAddedFields() + { + } + // TODO: remove, used in sets I guess protected function fieldLoader($object) {