[icinga-checkins] icinga.org: icinga-web/mfriedrich/fixes: * Prepared generic Doctrine output for groups provider

git at icinga.org git at icinga.org
Mon Jan 10 09:04:59 CET 2011


Module: icinga-web
Branch: mfriedrich/fixes
Commit: 9c8646f91215dd83825192314a773dc4a31243ee
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=9c8646f91215dd83825192314a773dc4a31243ee

Author: Marius Hein <marius.hein at netways.de>
Date:   Mon Dec 20 18:32:50 2010 +0100

* Prepared generic Doctrine output for groups provider
* Added Ext <-> Doctrine mapper class

---

 app/modules/AppKit/config/autoload.xml             |    1 +
 .../lib/json/AppKitExtDataInterface.class.php      |   73 ++++++++++++++++++++
 .../lib/json/AppKitExtJsonDocument.class.php       |   33 +++++++++-
 .../GroupProviderSuccessView.class.php             |   27 ++++++--
 app/modules/Cronks/lib/js/CronkBuilder.js          |   17 ++++-
 5 files changed, 143 insertions(+), 8 deletions(-)

diff --git a/app/modules/AppKit/config/autoload.xml b/app/modules/AppKit/config/autoload.xml
index 588cb86..9468e97 100755
--- a/app/modules/AppKit/config/autoload.xml
+++ b/app/modules/AppKit/config/autoload.xml
@@ -64,6 +64,7 @@
 		<!-- JSON things -->
 		<autoload name="AppKitJsonResponse">%core.module_dir%/AppKit/lib/json/AppKitJsonResponse.class.php</autoload>
 		<autoload name="AppKitExtJsonDocument">%core.module_dir%/AppKit/lib/json/AppKitExtJsonDocument.class.php</autoload>
+		<autoload name="AppKitExtDataInterface">%core.module_dir%/AppKit/lib/json/AppKitExtDataInterface.class.php</autoload>
 
 		<autoload name="AppKitDoctrineLoggerAppender">%core.module_dir%/AppKit/lib/logging/AppKitDoctrineLoggerAppender.class.php</autoload>
 		<autoload name="AppKitApacheLoggerFormat">%core.module_dir%/AppKit/lib/logging/AppKitApacheLoggerFormat.class.php</autoload>
diff --git a/app/modules/AppKit/lib/json/AppKitExtDataInterface.class.php b/app/modules/AppKit/lib/json/AppKitExtDataInterface.class.php
new file mode 100644
index 0000000..2e9d05e
--- /dev/null
+++ b/app/modules/AppKit/lib/json/AppKitExtDataInterface.class.php
@@ -0,0 +1,73 @@
+<?php
+
+class AppKitExtDataInterface {
+	
+	/*
+	 * Ext data types
+	 */
+	const EXT_TYPE_AUTO		= 'types.AUTO';
+	const EXT_TYPE_BOOL		= 'types.BOOL';
+	const EXT_TYPE_BOOLEAN	= 'types.BOOLEAN';
+	const EXT_TYPE_DATE		= 'types.DATE';
+	const EXT_TYPE_FLOAT	= 'types.FLOAT';
+	const EXT_TYPE_INT		= 'types.INT';
+	const EXT_TYPE_INTEGER	= 'types.INTEGER';
+	const EXT_TYPE_NUMBER	= 'types.NUMBER';
+	const EXT_TYPE_STRING 	= 'types.STRING';
+	
+	/*
+	 * Ext sort types
+	 */
+	const EXT_SORT_DATE		= 'asDate';
+	const EXT_SORT_FLOAT	= 'asFloat';
+	const EXT_SORT_INT		= 'asInt';
+	const EXT_SORT_TEXT		= 'asText';
+	const EXT_SORT_UCSTRING	= 'asUCString';
+	const EXT_SORT_UCTEXT	= 'asUSText';
+	
+	/*
+	 * Doctrine data types
+	 */
+	const DOCTRINE_TYPE_INTEGER		= 'integer';
+	const DOCTRINE_TYPE_DECIMAL		= 'decimal';
+	const DOCTRINE_TYPE_STRING		= 'string';
+	const DOCTRINE_TYPE_CLOB		= 'clob';
+	const DOCTRINE_TYPE_FLOAT		= 'float';
+	const DOCTRINE_TYPE_ARRAY		= 'array';
+	const DOCTRINE_TYPE_BLOB		= 'blob';
+	const DOCTRINE_TYPE_GZIP		= 'gzip';
+	const DOCTRINE_TYPE_BOOLEAN		= 'boolean';
+	const DOCTRINE_TYPE_DATE		= 'date';
+	const DOCTRINE_TYPE_TIME		= 'time';
+	const DOCTRINE_TYPE_TIMESTAMP	= 'timestamp';
+	const DOCTRINE_TYPE_ENUM		= 'enum';
+	
+	/*
+	 * Doctrine 2 extjs sort type
+	 */
+	protected static $doctrineToExtSortType = array (
+		self::DOCTRINE_TYPE_INTEGER		=> self::EXT_SORT_INT,
+		self::DOCTRINE_TYPE_DECIMAL		=> self::EXT_SORT_FLOAT,
+		self::DOCTRINE_TYPE_STRING		=> self::EXT_SORT_TEXT,
+		self::DOCTRINE_TYPE_CLOB		=> null,
+		self::DOCTRINE_TYPE_FLOAT		=> self::EXT_SORT_FLOAT,
+		self::DOCTRINE_TYPE_ARRAY		=> null,
+		self::DOCTRINE_TYPE_BLOB		=> null,
+		self::DOCTRINE_TYPE_GZIP		=> null,
+		self::DOCTRINE_TYPE_BOOLEAN		=> self::EXT_SORT_INT,
+		self::DOCTRINE_TYPE_DATE		=> self::EXT_SORT_DATE,
+		self::DOCTRINE_TYPE_TIME		=> self::EXT_SORT_DATE,
+		self::DOCTRINE_TYPE_TIMESTAMP	=> self::EXT_SORT_DATE,
+		self::DOCTRINE_TYPE_ENUM		=> null,
+	);
+	
+	public static function doctrineColumn2ExtSortType($doctrine_column_type, $default=self::DOCTRINE_TYPE_STRING) {
+		if (isset(self::$doctrineToExtSortType[$doctrine_column_type])) {
+			return self::$doctrineToExtSortType[$doctrine_column_type];
+		}
+		
+		return $default;
+	}
+}
+
+?>
\ No newline at end of file
diff --git a/app/modules/AppKit/lib/json/AppKitExtJsonDocument.class.php b/app/modules/AppKit/lib/json/AppKitExtJsonDocument.class.php
index dc099c7..61bdfea 100644
--- a/app/modules/AppKit/lib/json/AppKitExtJsonDocument.class.php
+++ b/app/modules/AppKit/lib/json/AppKitExtJsonDocument.class.php
@@ -11,7 +11,8 @@ class AppKitExtJsonDocument extends AppKitArrayContainer {
 	const PROPERTY_SORTINFO			= 'sortInfo';
 	const PROPERTY_START			= 'start';
 	const PROPERTY_LIMIT			= 'limit';
-
+	const PROPERTY_NOMETA			= 'no-metadata';
+	
 	protected $meta		= array ();
 	protected $rows		= array ();
 	protected $fields	= array ();
@@ -59,6 +60,28 @@ class AppKitExtJsonDocument extends AppKitArrayContainer {
 		$this->fields[$name] = $options;
 		return true;
 	}
+	
+	public function applyFieldsFromDoctrineRelation(Doctrine_Table $table) {
+		
+		foreach ($table->getColumns() as $column=>$meta) {
+			$options = array (
+				'sortType' => AppKitExtDataInterface::doctrineColumn2ExtSortType($meta['type'])
+			);
+
+			if (isset($meta['primary']) && $meta['primary'] == true) {
+				$this->setMeta(self::PROPERTY_ID, $column);
+			}
+			
+			$this->hasField($column, $options);
+		}
+		
+	}
+	
+	public function addDataCollection(Doctrine_Collection $collection) {
+		foreach ($collection as $record) {
+			$this->offsetSet(null, $record->toArray());
+		}
+	}
 
 	public function offsetSet($offset, $value) {
 
@@ -123,6 +146,12 @@ class AppKitExtJsonDocument extends AppKitArrayContainer {
 
 	protected function buildDoc() {
 		$doc =& $this->doc;
+		
+		if (isset($this->meta[self::PROPERTY_NOMETA]) && $this->meta[self::PROPERTY_NOMETA] == true) {
+			
+		}
+		else {
+		
 		$doc[self::PROPERTY_META] = array ();
 
 		$meta =& $doc[self::PROPERTY_META];
@@ -145,6 +174,8 @@ class AppKitExtJsonDocument extends AppKitArrayContainer {
 				$doc[$k] = $v;
 			}
 		}
+		
+		}
 
 		$doc[$this->meta[self::PROPERTY_ROOT]] = $this->rows;
 	}
diff --git a/app/modules/AppKit/views/DataProvider/GroupProviderSuccessView.class.php b/app/modules/AppKit/views/DataProvider/GroupProviderSuccessView.class.php
index b981892..d1f886a 100755
--- a/app/modules/AppKit/views/DataProvider/GroupProviderSuccessView.class.php
+++ b/app/modules/AppKit/views/DataProvider/GroupProviderSuccessView.class.php
@@ -17,9 +17,7 @@ class AppKit_DataProvider_GroupProviderSuccessView extends AppKitBaseView
 		$user = $this->getContext()->getUser();
 		
 		if ($user->hasCredential('appkit.admin') == false && $user->hasCredential('appkit.admin.groups') == false) {
-			$result = $roleadmin->getRoleCollectionInRange($disabled,$start,$limit,$sort,$asc, true)->toArray();
-			
-			var_dump($result);
+			$result = $roleadmin->getRoleCollectionInRange($disabled,$start,$limit,$sort,$asc, true);
 		}
 		else {
 			// return a single user when an id is provided
@@ -37,18 +35,35 @@ class AppKit_DataProvider_GroupProviderSuccessView extends AppKitBaseView
 				
 				$result = $group->toArray();
 				$result["users"] = $role_users;
+				
+				return json_encode(array("roles" => $result, "totalCount" => count($result), 'success' => true));
+				
 			} else {	//return list of all users if no id is provided
 	
 				if($start === false || $limit === false)
-					$groups = $roleadmin->getRoleCollection($disabled)->toArray();
+					$groups = $roleadmin->getRoleCollection($disabled);
 				else 
-					$groups = $roleadmin->getRoleCollectionInRange($disabled,$start,$limit,$sort,$asc)->toArray();
+					$groups = $roleadmin->getRoleCollectionInRange($disabled,$start,$limit,$sort,$asc);
 				$result = array();	
 				$result = $groups;
 			}
 		}
 		
-		return json_encode(array("roles" => $result, "totalCount" => count($result), 'success' => true));
+		$doc = new AppKitExtJsonDocument();
+		
+		// Disable metadata
+		$doc->setMeta(AppKitExtJsonDocument::PROPERTY_NOMETA, true);
+		
+		$doc->setMeta(AppKitExtJsonDocument::PROPERTY_ROOT, 'roles');
+		$doc->setMeta(AppKitExtJsonDocument::PROPERTY_TOTAL, 'totalCount');
+		
+		$doc->applyFieldsFromDoctrineRelation(Doctrine::getTable('NsmRole'));
+		
+		$doc->addDataCollection($result);
+		
+		$doc->setSuccess(true);
+		
+		return $doc->getJson();
 	}
 	
 	public function executeHtml(AgaviRequestDataHolder $rd)
diff --git a/app/modules/Cronks/lib/js/CronkBuilder.js b/app/modules/Cronks/lib/js/CronkBuilder.js
index c23f9f6..7462b07 100644
--- a/app/modules/Cronks/lib/js/CronkBuilder.js
+++ b/app/modules/Cronks/lib/js/CronkBuilder.js
@@ -136,6 +136,8 @@ Ext.extend(Cronk.util.CronkBuilder, Ext.Window, {
 			})
 		});
 		
+		this.groups.load();
+		
 		return new Ext.form.FormPanel({
 			layout: 'border',
 			height: 400,
@@ -184,7 +186,7 @@ Ext.extend(Cronk.util.CronkBuilder, Ext.Window, {
 		        	items: [{
 		        		xtype: 'multiselect',
 		        		name: 'categories',
-		        		fieldLabel: _('Available'),
+		        		fieldLabel: _('All categories available'),
 		        		width: 200,
 		        		store: this.categories,
 		        		valueField: 'title',
@@ -211,6 +213,19 @@ Ext.extend(Cronk.util.CronkBuilder, Ext.Window, {
 		        			scope: this
 		        		}]
 		        	}]
+		        }, {
+		        	xtype: 'fieldset',
+		        	title: _('Share your Cronk'),
+		        	items: [{
+		        		xtype: 'checkbox',
+		        		name: 'share',
+		        		fieldLabel: 'Make your cronk available for others'
+		        	}, {
+		        		xtype: 'multiselect',
+		        		name: 'principal',
+		        		fieldLabel: _('Principals'),
+		        		
+		        	}]
 		        }]
 		    }, {
 		    	region: 'east',





More information about the icinga-checkins mailing list