[icinga-checkins] icinga.org: icingaweb2-module-director/feature/service-sets-12891: IcingaServiceSet*: Improve Table and view

git at icinga.org git at icinga.org
Wed Nov 9 11:37:07 CET 2016


Module: icingaweb2-module-director
Branch: feature/service-sets-12891
Commit: fde36b721acbc9a6d7e044cd236698d092731c1f
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=fde36b721acbc9a6d7e044cd236698d092731c1f

Author: Markus Frosch <markus.frosch at icinga.com>
Date:   Wed Nov  9 11:31:10 2016 +0100

IcingaServiceSet*: Improve Table and view

Add filter and pagination, and some nice display features.

refs #12891

---

 application/tables/IcingaServiceSetTable.php       |   56 ++++++++++++++++----
 .../Director/Web/Controller/ObjectsController.php  |    7 +--
 2 files changed, 51 insertions(+), 12 deletions(-)

diff --git a/application/tables/IcingaServiceSetTable.php b/application/tables/IcingaServiceSetTable.php
index a28ef48..64dccd5 100644
--- a/application/tables/IcingaServiceSetTable.php
+++ b/application/tables/IcingaServiceSetTable.php
@@ -6,35 +6,50 @@ use Icinga\Module\Director\Web\Table\IcingaObjectTable;
 
 class IcingaServiceSetTable extends IcingaObjectTable
 {
+    protected $searchColumns = array(
+        'name',
+    );
+
     public function getColumns()
     {
         return array(
             'id'          => 'sset.id',
             'name'        => 'sset.object_name',
             'object_type' => 'sset.object_type',
+            'assign_filter' => 'sset.assign_filter',
             'description' => 'sset.description',
-            'host_name'   => 'h.object_name',
+            'count_hosts' => 'count(ssetobj.id)',
+            'count_services' => 'count(s.id)',
         );
     }
 
+    protected function getRowClasses($row)
+    {
+        $class = parent::getRowClasses($row);
+
+        if ($row->object_type === 'template' && $row->assign_filter !== null) {
+            $class = 'icinga-apply';
+        }
+
+        return $class;
+    }
+
     public function getTitles()
     {
         $view = $this->view();
         return array(
-            'name'    => $view->translate('Service set'),
+            'name' => $view->translate('Service set'),
+            'count_services' => $view->translate('# Services'),
+            'count_hosts' => $view->translate('# Hosts'),
         );
     }
 
     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;
-            }
         }
 
         return $this->url('director/serviceset', $params);
@@ -46,10 +61,33 @@ class IcingaServiceSetTable extends IcingaObjectTable
             array('sset' => 'icinga_service_set'),
             array()
         )->joinLeft(
-            array('h' => 'icinga_host'),
-            'h.id = sset.host_id',
+            array('ssih' => 'icinga_service_set_inheritance'),
+            'ssih.parent_service_set_id = sset.id',
+            array()
+        )->joinLeft(
+            array('ssetobj' => 'icinga_service_set'),
+            'ssetobj.id = ssih.service_set_id',
+            array()
+        )->joinLeft(
+            array('s' => 'icinga_service'),
+            's.service_set_id = sset.id',
             array()
-        )->where('sset.object_type = ?', 'template')->order('sset.object_name');
+        )->group('sset.id')
+        ->where('sset.object_type = ?', 'template')->order('sset.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);
     }
 
     public function getBaseQuery()
diff --git a/library/Director/Web/Controller/ObjectsController.php b/library/Director/Web/Controller/ObjectsController.php
index 2feb738..550f318 100644
--- a/library/Director/Web/Controller/ObjectsController.php
+++ b/library/Director/Web/Controller/ObjectsController.php
@@ -8,6 +8,8 @@ use Icinga\Exception\NotFoundError;
 use Icinga\Data\Filter\Filter;
 use Icinga\Module\Director\Objects\IcingaObject;
 use Icinga\Module\Director\Web\Table\IcingaObjectTable;
+use Icinga\Module\Director\Web\Table\QuickTable;
+use Icinga\Web\Widget\FilterEditor;
 
 abstract class ObjectsController extends ActionController
 {
@@ -218,9 +220,7 @@ abstract class ObjectsController extends ActionController
         }
 
         $this->view->title = $this->translate('Icinga ' . $Type . ' Sets');
-        $this->view->table = $this
-            ->loadTable('Icinga' . $Type . 'Set')
-            ->setConnection($this->db());
+        $table = $this->loadTable('Icinga' . $Type . 'Set')->setConnection($this->db());
 
         $this->view->addLink = $this->view->qlink(
             $this->translate('Add'),
@@ -232,6 +232,7 @@ abstract class ObjectsController extends ActionController
             )
         );
 
+        $this->provideFilterEditorForTable($table);
         $this->getTabs()->activate('sets');
         $this->setViewScript('objects/table');
     }



More information about the icinga-checkins mailing list