[icinga-checkins] icinga.org: icinga-web/mhein/extlayout: * Added Pagination for Admin.Users

git at icinga.org git at icinga.org
Tue May 11 19:18:10 CEST 2010


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

Author: jmosshammer <jannis.mosshammer at netways.de>
Date:   Thu Apr 29 12:18:06 2010 +0200

* Added Pagination for Admin.Users

---

 app/modules/AppKit/models/UserAdminModel.class.php |   37 ++++++++++++++++
 .../AppKit/templates/Admin/Users/EditSuccess.php   |    2 +-
 .../AppKit/templates/Admin/Users/IndexSuccess.php  |   46 +++++++++++++++-----
 .../AppKit/validate/DataProvider/UserProvider.xml  |   18 ++++++++
 .../DataProvider/UserProviderSuccessView.class.php |   14 +++++-
 5 files changed, 103 insertions(+), 14 deletions(-)

diff --git a/app/modules/AppKit/models/UserAdminModel.class.php b/app/modules/AppKit/models/UserAdminModel.class.php
index 419ca6f..d815a79 100755
--- a/app/modules/AppKit/models/UserAdminModel.class.php
+++ b/app/modules/AppKit/models/UserAdminModel.class.php
@@ -19,6 +19,43 @@ class AppKit_UserAdminModel extends ICINGAAppKitBaseModel
 	}	
 	
 	/**
+	 * Creates a collection NsmUser objects within the range $start and $limit and optionally
+	 * sorts it by param $sort
+	 * @param boolean $disabled
+	 * @param numeric $start
+	 * @param numeric $limit
+	 * @param string $sort
+	 * @param boolean $asc
+	 * 
+	 * @return Doctrine_Collection
+	 * @author Jannis Mosshammer
+	 */
+	public function getUsersCollectionInRange($disabled=false,$start = 0,$limit=25,$sort= null,$asc = true) {
+		$query = Doctrine_Query::create()
+		->from("NsmUser")
+		->limit($limit)
+		->offset($start);
+		if($sort)
+			$query->orderBy($sort." ".($asc ? 'ASC' : 'DESC'));
+		
+		if ($disabled === false) {
+			$query->andWhere('user_disabled=?', array(0));
+		}
+		return $query->execute();
+	}	
+	
+	public function getUserCount($disabled=false) {
+		$query = Doctrine_Query::create()
+			->select("COUNT(u.user_id) count")
+			->from("NsmUser u");
+		if ($disabled === false) {
+			$query->andWhere('user_disabled=?', array(0));
+		}
+		return $query->execute()->getFirst()->get("count");
+		
+	}
+	
+	/**
 	 * Returns a unexecuted query for users
 	 * @param boolean $disabled
 	 * @return Doctrine_Query
diff --git a/app/modules/AppKit/templates/Admin/Users/EditSuccess.php b/app/modules/AppKit/templates/Admin/Users/EditSuccess.php
index 1d663b3..123179d 100755
--- a/app/modules/AppKit/templates/Admin/Users/EditSuccess.php
+++ b/app/modules/AppKit/templates/Admin/Users/EditSuccess.php
@@ -268,8 +268,8 @@ Ext.onReady(function(){
 					} else
 						arr[newPrefix] = val;
 				}
-
 			},
+			
 			insertPresets: function(id)	{
 				AppKit.principalEditor.instance.clearPrincipals();
 				if(id == 'new')  {
diff --git a/app/modules/AppKit/templates/Admin/Users/IndexSuccess.php b/app/modules/AppKit/templates/Admin/Users/IndexSuccess.php
index 5a1cb79..7d078b3 100755
--- a/app/modules/AppKit/templates/Admin/Users/IndexSuccess.php
+++ b/app/modules/AppKit/templates/Admin/Users/IndexSuccess.php
@@ -4,9 +4,11 @@ Ext.onReady(function() {
 	AppKit.users.userList = new Ext.data.JsonStore({
 		autoDestroy: true,
 		storeId: 'userListStore',
+		totalProperty: 'totalCount',
+		root: 'users',
 		idProperty: 'user_id',
-		autoLoad:true,
 		url: '<? echo $ro->gen("appkit.data.users")?>',
+		remoteSort: true,
 		fields: [
 			{name: 'user_id', type:'int'},
 			'user_name',
@@ -70,7 +72,10 @@ Ext.onReady(function() {
 	
 	wnd_userEditPanel.render("contentArea");
 	var grid =   new Ext.grid.GridPanel({
-		autoHeight: true,
+		title: _('Available users'),
+		height:500,
+		sm: new Ext.grid.RowSelectionModel(),
+		iconCls: 'silk-user',
 		tools: [{
 			id: 'plus',
 			qtip: _('Add new user'),
@@ -105,6 +110,32 @@ Ext.onReady(function() {
 			scope:this
 		}],		 
 		
+		viewConfig : {
+			scrollOffset:30,
+
+		},
+		
+		tbar: new Ext.PagingToolbar({
+			pageSize: 25,
+			store: AppKit.users.userList,
+			displayInfo: true,
+			displayMsg: _('Displaying users')+' {0} - {1} '+_('of')+' {2}',
+			emptyMsg: _('No users to display'),
+			items: [{
+				xtype: 'displayfield',
+				value: _('Hide disabled')
+				
+			},{
+				xtype:'checkbox',
+				id:'hide_disabled',
+				name: 'disabled',
+				handler: function(btn, checked){
+					grid.getStore().setBaseParam('hideDisabled',checked);
+				}
+			}]
+			
+		}), 
+		
 		store : AppKit.users.userList,
 		
 		listeners: {
@@ -146,12 +177,7 @@ Ext.onReady(function() {
 				{header: _('inactive'), dataIndex: 'user_disabled_icon',width:75}
 			]
 		}),
-		autoScroll:true,
-		title: _('Available users'),
-
-		width:800,
-		sm: new Ext.grid.RowSelectionModel(),
-		iconCls: 'silk-user'
+		
 	});
 	
 	/**
@@ -159,14 +185,12 @@ Ext.onReady(function() {
 	 */
 	var container = new Ext.Container({
 		layout: 'fit',
-		width:800,
 		items: new Ext.Panel({
 			layout: 'border',
 			border:false,
 			defaults: {
 				margins: {top: 10, left: 10, right: 10, bottom: 0},
 			},
-			autoScroll:true,
 			items: [{
 				region:'center',
 				xtype:'panel',
@@ -184,7 +208,7 @@ Ext.onReady(function() {
 		
 	container.render("contentArea");
 	container.doLayout();
-	
+	AppKit.users.userList.load({params: {start:0, limit:25}});
 	Ext.EventManager.onWindowResize(function(w,h) {
 		this.setHeight(Ext.lib.Dom.getViewHeight() - 68);
 			
diff --git a/app/modules/AppKit/validate/DataProvider/UserProvider.xml b/app/modules/AppKit/validate/DataProvider/UserProvider.xml
index d3779fb..4a9680a 100644
--- a/app/modules/AppKit/validate/DataProvider/UserProvider.xml
+++ b/app/modules/AppKit/validate/DataProvider/UserProvider.xml
@@ -13,6 +13,24 @@
 					<error>Validation of 'userId' failed</error>
 				</errors>
 			</validator>
+			<validator class="string" name="hideDisabled" required="false">
+				<argument>hideDisabled</argument>
+			</validator>
+			
+			
+			<!--  Paging properties -->
+			<validator class="number" name="start" required="false">
+				<argument>start</argument>
+			</validator>
+			<validator class="number" name="limit" required="false">
+				<argument>limit</argument>
+			</validator>
+			<validator class="string" name="sort" required="false">
+				<argument>sort</argument>
+			</validator>
+			<validator class="string" name="dir" required="false">
+				<argument>dir</argument>
+			</validator>
 		</validators>
 		
 	</ae:configuration>
diff --git a/app/modules/AppKit/views/DataProvider/UserProviderSuccessView.class.php b/app/modules/AppKit/views/DataProvider/UserProviderSuccessView.class.php
index e0ff97d..01c0a6c 100644
--- a/app/modules/AppKit/views/DataProvider/UserProviderSuccessView.class.php
+++ b/app/modules/AppKit/views/DataProvider/UserProviderSuccessView.class.php
@@ -6,6 +6,12 @@ class AppKit_DataProvider_UserProviderSuccessView extends ICINGAAppKitBaseView
 	public function executeJson(AgaviRequestDataHolder $rd) {
 		$useradmin = $this->getContext()->getModel('UserAdmin', 'AppKit');
 		$userId = $rd->getParameter('userId',false);
+		$disabled = $rd->getParameter('hideDisabled',false) == "false";
+		$start = $rd->getParameter('start',false);
+		$limit = $rd->getParameter('limit',false);
+		$sort = $rd->getParameter('sort',false);
+		$asc = ($rd->getParameter('dir','ASC') == 'ASC');
+		
 		$result;
 		// return a single user when an id is provided
 		if($userId) {
@@ -14,13 +20,17 @@ class AppKit_DataProvider_UserProviderSuccessView extends ICINGAAppKitBaseView
 				return "{}";
 			$result = $this->formatUser($user);
 		} else {	//return list of all users if no id is provided
-			$users = $useradmin->getUsersCollection(true);
+			$users;
+			if($start === false || $limit === false)
+				$users = $useradmin->getUsersCollection($disabled);
+			else 
+				$users = $useradmin->getUsersCollectionInRange($disabled,$start,$limit,$sort,$asc);
 			$result = array();
 			foreach($users as $user) {
 				$result[] = $this->formatUser($user);
 			}
 		}
-		return json_encode($result);
+		return json_encode(array("users" => $result, "totalCount" => $useradmin->getUserCount($disabled)));
 	}
 	
 	public function formatUser(NsmUser $user) {





More information about the icinga-checkins mailing list