[icinga-checkins] icinga.org: icingaweb2-module-director/master: DirectorObjectForm: allow to hook custom code...

git at icinga.org git at icinga.org
Mon Jan 2 10:52:28 CET 2017


Module: icingaweb2-module-director
Branch: master
Commit: 87f88bf0c7533bf893c7e508fee081093a4274fc
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=87f88bf0c7533bf893c7e508fee081093a4274fc

Author: Thomas Gelf <thomas at gelf.net>
Date:   Mon Jan  2 10:17:49 2017 +0100

DirectorObjectForm: allow to hook custom code...

...after fields have been added

---

 application/tables/IcingaHostServiceSetTable.php |   77 ++++++++++++++++------
 library/Director/Web/Form/DirectorObjectForm.php |    5 ++
 2 files changed, 63 insertions(+), 19 deletions(-)

diff --git a/application/tables/IcingaHostServiceSetTable.php b/application/tables/IcingaHostServiceSetTable.php
index 4cdb64b..2e478dc 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 .= "</tbody>\n";
+            }
+            $html .= parent::renderTitles((object) array(
+                'name' => sprintf($view->translate('Service set: %s'), $row->service_set_name)
+            ));
+            $html .= "<tbody>\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('pset' => 'icinga_service_set'),
+            array()
+        )->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()
-        )->joinLeft(
+        )->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 f812dd0..2333c2f 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)
     {



More information about the icinga-checkins mailing list