[icinga-checkins] icinga.org: icingaweb2-module-director/feature/nested-apply-rules-12033: IcingaServiceTable: Update apply rule rendering

git at icinga.org git at icinga.org
Mon Oct 24 14:44:08 CEST 2016


Module: icingaweb2-module-director
Branch: feature/nested-apply-rules-12033
Commit: b3eb5ea102185fc1eed19cf1b96ea1429172d1ef
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=b3eb5ea102185fc1eed19cf1b96ea1429172d1ef

Author: Markus Frosch <markus.frosch at icinga.com>
Date:   Mon Oct 24 14:43:38 2016 +0200

IcingaServiceTable: Update apply rule rendering

For new storage format, and change to table.

refs #12033

---

 application/tables/IcingaServiceTable.php |   61 +++++++++++++++++------------
 public/css/module.less                    |   30 +++++++-------
 2 files changed, 51 insertions(+), 40 deletions(-)

diff --git a/application/tables/IcingaServiceTable.php b/application/tables/IcingaServiceTable.php
index 00736ea..30a8b4b 100644
--- a/application/tables/IcingaServiceTable.php
+++ b/application/tables/IcingaServiceTable.php
@@ -2,6 +2,9 @@
 
 namespace Icinga\Module\Director\Tables;
 
+use Icinga\Data\Filter\Filter;
+use Icinga\Exception\IcingaException;
+use Icinga\Module\Director\IcingaConfig\AssignRenderer;
 use Icinga\Module\Director\Web\Table\QuickTable;
 
 class IcingaServiceTable extends QuickTable
@@ -13,9 +16,9 @@ class IcingaServiceTable extends QuickTable
     public function getColumns()
     {
         return array(
-            'id'               => 's.id',
-            'service'          => 's.object_name',
-            'object_type'      => 's.object_type',
+            'id' => 's.id',
+            'service' => 's.object_name',
+            'object_type' => 's.object_type',
             'check_command_id' => 's.check_command_id',
         );
     }
@@ -47,21 +50,34 @@ class IcingaServiceTable extends QuickTable
         if (empty($extra)) {
             if ($row->check_command_id) {
                 $htm .= ' ' . $v->qlink(
-                    'Create apply-rule',
-                    'director/service/add',
-                    array('apply' => $row->service),
-                    array('class'    => 'icon-plus')
-                );
+                        'Create apply-rule',
+                        'director/service/add',
+                        array('apply' => $row->service),
+                        array('class' => 'icon-plus')
+                    );
             }
 
         } else {
-            $htm .= '. Related apply rules: <ul class="apply-rules">';
-            foreach ($extra as $id => $service) {
-                $htm .= '<li>'
-                    . $v->qlink($service, 'director/service', array('id' => $id))
-                    . '</li>';
+            $htm .= '. Related apply rules: <table class="apply-rules">';
+            foreach ($extra as $service) {
+                $href = $v->url('director/service', array('id' => $service->id));
+                $htm .= "<tr href=\"$href\">";
+
+                try {
+                    $prettyFilter = AssignRenderer::forFilter(
+                        Filter::fromQueryString($service->assign_filter)
+                    )->renderAssign();
+                }
+                catch (IcingaException $e) {
+                    // ignore errors in filter rendering
+                    $prettyFilter = 'Error in Filter rendering: ' . $e->getMessage();
+                }
+
+                $htm .= "<td><a href=\"$href\">" . $service->object_name . '</a></td>';
+                $htm .= '<td>' . $prettyFilter . '</td>';
+                $htm .= '<tr>';
             }
-            $htm .= '</ul>';
+            $htm .= '</table>';
             $htm .= $v->qlink(
                 'Add more',
                 'director/service/add',
@@ -109,23 +125,18 @@ class IcingaServiceTable extends QuickTable
         $query = $db->select()->from(
             array('s' => 'icinga_service'),
             array(
-                'id'         => 's.id',
-                'objectname' => $nameCol,
+                'id'          => 's.id',
+                'object_name' => 's.object_name',
+                'assign_filter' => 's.assign_filter',
             )
         )->join(
             array('i' => 'icinga_service_inheritance'),
             'i.service_id = s.id',
             array()
         )->where('i.parent_service_id = ?', $id)
-         ->where('s.object_type = ?', 'apply');
+        ->where('s.object_type = ?', 'apply');
 
-        $query->joinLeft(
-            array('a' => 'icinga_service_assignment'),
-            'a.service_id = s.id',
-            array()
-        )->group('s.id');
-
-        return $db->fetchPairs($query);
+        return $db->fetchAll($query);
     }
 
     public function getBaseQuery()
@@ -134,6 +145,6 @@ class IcingaServiceTable extends QuickTable
             's.object_type IN (?)',
             array('template')
         )->order('CASE WHEN s.check_command_id IS NULL THEN 1 ELSE 0 END')
-         ->order('s.object_name');
+            ->order('s.object_name');
     }
 }
diff --git a/public/css/module.less b/public/css/module.less
index c53b268..eb132dc 100644
--- a/public/css/module.less
+++ b/public/css/module.less
@@ -887,25 +887,25 @@ table.icinga-objects {
 }
 
 table.assignment-table {
-    ul.apply-rules {
+    table.apply-rules {
         margin: 1em 0 1em 0;
         padding: 0;
-        border: 1px solid @gray-lighter;
+        width: 100%;
 
-        li {
-            display: block;
+        tr {
+            border-bottom: 1px solid @gray-lighter;
+            border-left: 5px solid transparent;
+
+            td {
+                padding: 0.5em 1em;
+            }
+
+            &:hover, &:active, &.active {
+                border-left: 5px solid @icinga-blue;
+            }
 
-            a {
-                display: block;
-                float: none;
-                font-weight: normal;
-                background-color: white;
-                padding: 0.3em 1.5em;
-                &:hover {
-                    background-color: @icinga-blue;
-                    color: white;
-                    text-decoration: none;
-                }
+            &:hover {
+                background: white;
             }
         }
     }



More information about the icinga-checkins mailing list