[icinga-checkins] icinga.org: icingaweb2-module-director/fiddle/mfrosch: WIP: Add templates tab for hosts (and later other types)

git at icinga.org git at icinga.org
Thu May 19 11:01:23 CEST 2016


Module: icingaweb2-module-director
Branch: fiddle/mfrosch
Commit: 6874cf77c1732f45695c6756d4f85492493a5496
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=6874cf77c1732f45695c6756d4f85492493a5496

Author: Markus Frosch <lazyfrosch at icinga.org>
Date:   Thu May 19 11:01:13 2016 +0200

WIP: Add templates tab for hosts (and later other types)

---

 .../controllers/HosttemplatesController.php        |    9 ++++++
 .../Director/Web/Controller/ObjectsController.php  |   30 +++++++++++++++++---
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/application/controllers/HosttemplatesController.php b/application/controllers/HosttemplatesController.php
new file mode 100644
index 0000000..4c350b9
--- /dev/null
+++ b/application/controllers/HosttemplatesController.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace Icinga\Module\Director\Controllers;
+
+use Icinga\Module\Director\Web\Controller\ObjectsController;
+
+class HosttemplatesController extends ObjectsController
+{
+}
diff --git a/library/Director/Web/Controller/ObjectsController.php b/library/Director/Web/Controller/ObjectsController.php
index a097e25..c93826b 100644
--- a/library/Director/Web/Controller/ObjectsController.php
+++ b/library/Director/Web/Controller/ObjectsController.php
@@ -2,6 +2,10 @@
 
 namespace Icinga\Module\Director\Web\Controller;
 
+use Icinga\Data\Filter\Filter;
+use Icinga\Module\Director\Objects\IcingaObject;
+use Icinga\Module\Director\Web\Table\IcingaObjectTable;
+
 abstract class ObjectsController extends ActionController
 {
     protected $dummy;
@@ -37,15 +41,22 @@ abstract class ObjectsController extends ActionController
             return;
         }
 
+        /** @var IcingaObject $object */
         $object = $this->dummyObject();
         if ($object->isGroup()) {
             $type = substr($type, 0, -5);
         }
 
-        $tabs = $this->getTabs()->add('objects', array(
+        $tabs->add('objects', array(
             'url'   => sprintf('director/%ss', strtolower($type)),
             'label' => $this->translate(ucfirst($type) . 's'),
         ));
+        if ($object->supportsImports() && $type === 'host') { // TODO: just for fiddling
+            $tabs->add('templates', array(
+                'url'   => sprintf('director/%stemplates', strtolower($type)),
+                'label' => $this->translate('Templates'),
+            ));
+        }
         if ($object->supportsGroups() || $object->isGroup()) {
             $tabs->add('objectgroups', array(
                 'url'   => sprintf('director/%sgroups', $type),
@@ -68,6 +79,7 @@ abstract class ObjectsController extends ActionController
         $type = $this->getType();
         $ltype = strtolower($type);
         $this->assertPermission('director/' . $type . 's/read');
+        /** @var IcingaObject $dummy */
         $dummy = $this->dummyObject();
 
         if (! in_array(ucfirst($type), $this->globalTypes)) {
@@ -82,14 +94,26 @@ abstract class ObjectsController extends ActionController
             $table = 'icinga' . ucfirst($type);
         }
 
+        /** @var IcingaObjectTable $table */
+        $table = $this->loadTable($table)->setConnection($this->db());
+
         if ($dummy->isTemplate()) {
             $addParams = array('type' => 'template');
+            $this->getTabs()->activate('templates');
+            $title = $this->translate('Icinga ' . ucfirst($ltype) . ' Templates');
             $addTitle = $this->translate('Add %s template');
+            $table->enforceFilter(Filter::expression('object_type', '=', 'template'));
         } else {
-            $addParams = array();
+            $addParams = array('type' => 'object');
+            $title = $this->translate('Icinga ' . ucfirst($ltype) . 's');
             $addTitle = $this->translate('Add %s');
+            if ($dummy->supportsImports() && $type === 'host') { # TODO: only fiddling
+                $table->enforceFilter(Filter::expression('object_type', '!=', 'template'));
+            }
         }
 
+        $this->view->title = $title;
+
         $this->view->addLink = $this->view->qlink(
             sprintf($addTitle, $this->translate(ucfirst($ltype))),
             'director/' . $ltype .'/add',
@@ -97,8 +121,6 @@ abstract class ObjectsController extends ActionController
             array('class' => 'icon-plus')
         );
 
-        $this->view->title = $this->translate('Icinga ' . ucfirst($ltype) . 's');
-        $table = $this->loadTable($table)->setConnection($this->db());
         $filterEditor = $table->getFilterEditor($this->getRequest());
         $filter = $filterEditor->getFilter();
 



More information about the icinga-checkins mailing list