[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaHostTable: no more imports, show address...

git at icinga.org git at icinga.org
Wed Nov 16 16:20:07 CET 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Mon Oct 24 21:43:52 2016 +0000

IcingaHostTable: no more imports, show address...

...and related actions for templates

---

 application/tables/IcingaHostTable.php         |   68 +++++++-------------
 application/tables/IcingaHostTemplateTable.php |   80 ++++++++++++++++++++++++
 2 files changed, 102 insertions(+), 46 deletions(-)

diff --git a/application/tables/IcingaHostTable.php b/application/tables/IcingaHostTable.php
index e010e89..53c9ca7 100644
--- a/application/tables/IcingaHostTable.php
+++ b/application/tables/IcingaHostTable.php
@@ -2,34 +2,29 @@
 
 namespace Icinga\Module\Director\Tables;
 
-use Icinga\Data\Limitable;
-use Icinga\Module\Director\Web\Table\IcingaObjectTable;
+use Icinga\Module\Director\Web\Table\QuickTable;
 
-class IcingaHostTable extends IcingaObjectTable
+class IcingaHostTable extends QuickTable
 {
     protected $searchColumns = array(
         'host',
+        'address',
+        'display_name'
     );
 
     public function getColumns()
     {
-        if ($this->connection()->isPgsql()) {
-            $parents = "ARRAY_TO_STRING(ARRAY_AGG(ih.object_name ORDER BY hi.weight), ', ')";
-        } else {
-            $parents = "GROUP_CONCAT(ih.object_name ORDER BY hi.weight SEPARATOR ', ')";
-        }
-
         return array(
-            'id'          => 'h.id',
-            'host'        => 'h.object_name',
-            'object_type' => 'h.object_type',
-            'address'     => 'h.address',
-            'zone'        => 'z.object_name',
-            'parents'     => $parents,
+            'id'           => 'h.id',
+            'host'         => 'h.object_name',
+            'object_type'  => 'h.object_type',
+            'address'      => 'h.address',
+            'disabled'     => 'h.disabled',
+            'display_name' => 'h.address',
         );
     }
 
-    protected function getActionUrl($row)
+        protected function getActionUrl($row)
     {
         return $this->url('director/host', array('name' => $row->host));
     }
@@ -43,12 +38,21 @@ class IcingaHostTable extends IcingaObjectTable
         );
     }
 
+    protected function getRowClasses($row)
+    {
+        if ($row->disabled === 'y') {
+            return 'disabled';
+        } else {
+            return null;
+        }
+    }
+
     public function getTitles()
     {
         $view = $this->view();
         return array(
             'host'    => $view->translate('Hostname'),
-            'parents' => $view->translate('Imports'),
+            'address' => $view->translate('Address'),
         );
     }
 
@@ -57,35 +61,7 @@ class IcingaHostTable extends IcingaObjectTable
         return $this->db()->select()->from(
             array('h' => 'icinga_host'),
             array()
-        )->joinLeft(
-            array('z' => 'icinga_zone'),
-            'h.zone_id = z.id',
-            array()
-        )->joinLeft(
-            array('hi' => 'icinga_host_inheritance'),
-            'hi.host_id = h.id',
-            array()
-        )->joinLeft(
-            array('ih' => 'icinga_host'),
-            'hi.parent_host_id = ih.id',
-            array()
-        )->group('h.id')
-         ->group('z.id')
-         ->order('h.object_name');
-    }
-
-    public function count()
-    {
-        $db = $this->db();
-        $sub = clone($this->getBaseQuery());
-        $sub->columns($this->getColumns());
-        $this->applyFiltersToQuery($sub);
-        $query = $db->select()->from(
-            array('sub' => $sub),
-            'COUNT(*)'
-        );
-
-        return $db->fetchOne($query);
+        )->order('h.object_name');
     }
 
     public function getBaseQuery()
diff --git a/application/tables/IcingaHostTemplateTable.php b/application/tables/IcingaHostTemplateTable.php
index 191eda5..d35a126 100644
--- a/application/tables/IcingaHostTemplateTable.php
+++ b/application/tables/IcingaHostTemplateTable.php
@@ -4,8 +4,88 @@ namespace Icinga\Module\Director\Tables;
 
 use Icinga\Module\Director\Tables\IcingaHostTable;
 
+require_once __DIR__ . '/IcingaHostTable.php';
 class IcingaHostTemplateTable extends IcingaHostTable
 {
+    protected $searchColumns = array(
+        'host',
+        'display_name'
+    );
+
+    public function getTitles()
+    {
+        $view = $this->view();
+        return array(
+            'host'    => $view->translate('Template name'),
+        );
+    }
+
+    protected function renderAdditionalActions($row)
+    {
+        $htm = '';
+        $view = $this->view();
+
+        if ($row->object_type === 'template') {
+            $htm .= $view->qlink(
+                '',
+                'director/host/add?type=object',
+                array('imports' => $row->host),
+                array(
+                    'class' => 'icon-plus',
+                    'title' => $view->translate(
+                        'Create a new host based on this template'
+                    )
+                )
+            );
+            if ($cnt = $row->cnt_child_templates) {
+                if ((int) $cnt === 1) {
+                    $title = $view->translate('Show one host template using this template');
+                } else {
+                    $title = sprintf(
+                        $view->translate('Show %d host templates using this template'),
+                        $cnt
+                    );
+                }
+
+                $htm .= $view->qlink(
+                    '',
+                    'director/hosts/bytemplate',
+                    array('name' => $row->host),
+                    array(
+                        'class' => 'icon-sitemap',
+                        'title' => $title
+                    )
+                );
+
+            }
+
+            if ($cnt = $row->cnt_child_hosts) {
+                if ((int) $cnt === 1) {
+                    $title = $view->translate('Show one host using this template');
+                } else {
+                    $title = sprintf(
+                        $view->translate('Show %d hosts using this template'),
+                        $cnt
+                    );
+                }
+
+                $htm .= $view->qlink(
+                    '',
+                    'director/hosts/bytemplate',
+                    array('name' => $row->host),
+                    array(
+                        'class' => 'icon-host',
+                        'title' => $title
+                    )
+                );
+
+            }
+
+        }
+
+        return $htm;
+    }
+
     public function getBaseQuery()
     {
         return $this->getUnfilteredQuery()->where('h.object_type = ?', 'template');



More information about the icinga-checkins mailing list