[icinga-checkins] icinga.org: icinga-web/mhein/default: * Added possibility to give filtergroups via filters_json, allowing or/ and groups

git at icinga.org git at icinga.org
Fri Sep 10 15:22:15 CEST 2010


Module: icinga-web
Branch: mhein/default
Commit: dfe7f47e35c8fc49714f6a42b8a02042965f355d
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=dfe7f47e35c8fc49714f6a42b8a02042965f355d

Author: jmosshammer <jmosshammer at ws-jmosshammer.(none)>
Date:   Mon Aug 30 16:11:44 2010 +0200

* Added possibility to give filtergroups via filters_json, allowing or/and groups

---

 .../Web/actions/Icinga/ApiSearchAction.class.php   |   34 +++++++++++++++++---
 app/modules/Web/validate/Icinga/ApiSearch.xml      |   21 +++++++++++-
 .../views/Icinga/ApiSearchSuccessView.class.php    |   13 ++++++-
 3 files changed, 59 insertions(+), 9 deletions(-)

diff --git a/app/modules/Web/actions/Icinga/ApiSearchAction.class.php b/app/modules/Web/actions/Icinga/ApiSearchAction.class.php
index 17b348e..cb5d2c9 100755
--- a/app/modules/Web/actions/Icinga/ApiSearchAction.class.php
+++ b/app/modules/Web/actions/Icinga/ApiSearchAction.class.php
@@ -96,7 +96,17 @@ class Web_Icinga_ApiSearchAction extends IcingaWebBaseAction
 		IcingaPrincipalTargetTool::applyApiSecurityPrincipals($search);
 
 		$res = $search->fetch()->getAll();
-
+		//Setup count
+		if($rd->getParameter("countColumn")) {
+			$search = @$API->createSearch()->setSearchTarget($target);
+			$search->setSearchType(IcingaApiSearch::SEARCH_TYPE_COUNT);
+			$this->addFilters($search,$rd);
+			$this->setColumns($search,$rd);
+			$search->setResultType(IcingaApiSearch::RESULT_ARRAY);
+			
+			IcingaPrincipalTargetTool::applyApiSecurityPrincipals($search);
+			$rd->setParameter("searchCount",$search->fetch()->getAll());
+		}
 		$rd->setParameter("searchResult", $res);
 		return $this->getDefaultViewName();
 	}
@@ -104,9 +114,13 @@ class Web_Icinga_ApiSearchAction extends IcingaWebBaseAction
 	protected function addFilters(IcingaApiSearchIdo $search,AgaviRequestDataHolder $rd) {
 		// URL filter definitions
 		$field = $rd->getParameter("filter",null);
-		if(!empty($field))
-			$this->buildFiltersFromArray($search,$field);
-			
+	
+		if(empty($field)) {
+			$field = json_decode($rd->getParameter("filters_json"),true);
+		}
+		if(!empty($field)) {
+			$search->setSearchFilter($this->buildFiltersFromArray($search,$field));
+		}
 		// POST filter definitions
 		$advFilter = $rd->getParameter("filters",array());
 
@@ -118,15 +132,21 @@ class Web_Icinga_ApiSearchAction extends IcingaWebBaseAction
 
 	public function buildFiltersFromArray(IcingaApiSearchIdo $search, array $filterdef) {
 		$searchField = $filterdef;
+
 		if(isset($filterdef["type"]))
 			$searchField = $filterdef["field"];
+		$filterGroup = $search->createFilterGroup($filterdef["type"]);
 		foreach($searchField as $element) {
 			if($element["type"] == "atom")
-				$search->setSearchFilter($element["field"][0],$element["value"][0],$element["method"][0]);
+				$filterGroup->addFilter($search->createFilter($element["field"][0],$element["value"][0],$element["method"][0]));
+			else
+				$filterGroup->addFilter($this->buildFiltersFromArray($search,$element));
 		}
 
+		return $filterGroup;
 	}
 
+
 	public function setGrouping(IcingaApiSearchIdo $search,AgaviRequestDataHolder $rd) {
 		$groups = $rd->getParameter("groups",array());
 		if(!is_array($groups))
@@ -149,6 +169,10 @@ class Web_Icinga_ApiSearchAction extends IcingaWebBaseAction
 	}
 
 	public function setColumns(IcingaApiSearchIdo $search,AgaviRequestDataHolder $rd) {
+		if($search->getSearchType() == IcingaApiSearch::SEARCH_TYPE_COUNT) {
+			$search->setResultColumns($rd->getParameter("countColumn"));
+			return true;
+		}
 		$columns = $rd->getParameter("columns",null);
 		if(!is_null($columns))
 			$search->setResultColumns($columns);
diff --git a/app/modules/Web/validate/Icinga/ApiSearch.xml b/app/modules/Web/validate/Icinga/ApiSearch.xml
index 7517b70..1c82c56 100755
--- a/app/modules/Web/validate/Icinga/ApiSearch.xml
+++ b/app/modules/Web/validate/Icinga/ApiSearch.xml
@@ -46,7 +46,14 @@
 					<error for="general_syntax">Syntax error</error>
 				</errors>
 			</validator>
-		
+
+			<validator name="filters_json" class="string" required="false">
+				<argument>filters_json</argument>
+				<errors>
+					<error>JSON filter doesn't fit</error>
+				</errors>
+			</validator>
+
 			<validator name="groups"  class="AppKitSplitValidator" required="false">
 				<argument>groups</argument>
 				<ae:parameters>
@@ -54,6 +61,10 @@
 					<ae:parameter name="export">groups</ae:parameter>
 				</ae:parameters>
 			</validator>
+
+			<validator name="countColumn" class="string" required="false">
+				<argument>countColumn</argument>
+			</validator>
 			
 			<validator name="order_col" class="string" required="false">
 				<argument>order_col</argument>
@@ -114,7 +125,10 @@
 		</validators>
 		
 		<validators method="write">
-			
+			<!--
+				@deprecated and only left for compatibility reasons. Doesn't support real filter
+				groups
+			-->
 			<validator name="filters" class="string" required="false">
 				<arguments base="filters[]">
 					<argument>column</argument>
@@ -144,9 +158,12 @@
 						<ae:parameter>=</ae:parameter>
 						<ae:parameter>!=</ae:parameter>
 						<ae:parameter>like</ae:parameter>
+						<ae:parameter>not like</ae:parameter>
 					</ae:parameter>
 				</ae:parameters>
 			</validator>
+
+
 			<validator name="group" class="string" required="false">
 				<arguments base="groups[]" />
 			</validator>
diff --git a/app/modules/Web/views/Icinga/ApiSearchSuccessView.class.php b/app/modules/Web/views/Icinga/ApiSearchSuccessView.class.php
index d2aa5fb..7015bee 100755
--- a/app/modules/Web/views/Icinga/ApiSearchSuccessView.class.php
+++ b/app/modules/Web/views/Icinga/ApiSearchSuccessView.class.php
@@ -17,8 +17,12 @@ class Web_Icinga_ApiSearchSuccessView extends IcingaWebBaseView
 		// provide meta data for ExtJs stores
 		$searchResult = $rd->getParameter("searchResult");
 		$meta = $this->getMetaDataArray($rd); 
-		
-		$result = array("metaData" => $meta,"result"=>$searchResult);
+		$count = $rd->getParameter("searchCount");
+		$result = array("metaData" => $meta,"result"=>$searchResult,"success"=>"true");
+		if($count) {
+			$count = array_values($count[0]);
+			$result["total"] = $count[0];
+		}
 		return json_encode($result);
 	}
 
@@ -36,6 +40,11 @@ class Web_Icinga_ApiSearchSuccessView extends IcingaWebBaseView
 					$columns[] = array("name"=>"idField","mapping"=>$column);
 			}
 		}
+		$metaData["paramNames"] = array(
+			'start' => 'limit_start',
+			'limit' => 'limit'
+		);
+		$metaData["totalProperty"] = "total";
 		$metaData["root"] = "result";
 		$metaData["fields"] =$columns;
 		return $metaData;





More information about the icinga-checkins mailing list