[icinga-checkins] icinga.org: icinga-web/next: Add filterpresets allowing json filters to be defined in templates

git at icinga.org git at icinga.org
Tue Jul 30 15:23:51 CEST 2013


Module: icinga-web
Branch: next
Commit: 69c420d2e4c3002ae315a790d81e7fdd61d996e1
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=69c420d2e4c3002ae315a790d81e7fdd61d996e1

Author: Jannis Mosshammer <jannis.mosshammer at netways.de>
Date:   Tue Jul 30 15:21:43 2013 +0200

Add filterpresets allowing json filters to be defined in templates

the <parameter name="datasource"> element in tgrid templates now
can contain a filterPresets child which applies the containing json filter
to the grid. Example:
 	<parameter name="filterPresets">
        <![CDATA[
            {"AND":[{"field":"host_name","label":"Host","operator":"contain","value":"localhost10"}]}
        ]]>
	</parameter>

fixes #4483

---

 .../DQLCronkTemplateWorker.class.php               |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/app/modules/Cronks/lib/template/TemplateWorker/DQLCronkTemplateWorker.class.php b/app/modules/Cronks/lib/template/TemplateWorker/DQLCronkTemplateWorker.class.php
index a1b546f..b582897 100644
--- a/app/modules/Cronks/lib/template/TemplateWorker/DQLCronkTemplateWorker.class.php
+++ b/app/modules/Cronks/lib/template/TemplateWorker/DQLCronkTemplateWorker.class.php
@@ -62,7 +62,17 @@ class DQLCronkTemplateWorker extends CronkGridTemplateWorker {
          * @var IcingaDoctrine_Query
          */
         $this->query = $this->parser->getQuery();
-
+        // Allow setting filterPresets
+        if (isset($source["filterPresets"])) {
+            try {
+                $filter = json_decode($source["filterPresets"], true);
+                $filterObj = new IcingaDQLViewFilter();
+                $query = $filterObj->getDQLFromFilterArray($filter, $this);
+                $this->query->addWhere($query[0], $query[1]);
+            } catch (Exception $e) {
+                AppKitLogger::warn("Ignoring filterpreset : %s", $source["filterPresets"]);
+            }
+        }
     }
     
 
@@ -228,6 +238,7 @@ class DQLCronkTemplateWorker extends CronkGridTemplateWorker {
     }
     
     public function getDQLQueryObject() {
+        
         return $this->parser->getQuery();    
     }
     





More information about the icinga-checkins mailing list