dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #07854
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2319: Add paging function for allUser function into Maintenance/User module.
------------------------------------------------------------
revno: 2319
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Tue 2010-10-05 18:04:35 +0700
message:
Add paging function for allUser function into Maintenance/User module.
added:
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/responseUsers.vm
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/paging/paging.css
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/paging/paging.vm
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/struts.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java 2010-09-27 07:12:46 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java 2010-10-05 11:04:35 +0000
@@ -29,6 +29,7 @@
import java.util.Collection;
+import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.organisationunit.OrganisationUnit;
/**
@@ -245,4 +246,10 @@
void deleteUserSetting( UserSetting userSetting );
Collection<User> getAllUsers( int from, int to );
+
+ Collection<UserCredentials> searchUsersByName( String key );
+
+ Collection<UserCredentials> searchUsersByName( String key, int from, int to );
+
+ int countNumberOfSearchUsersByName( String key );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2010-09-27 07:12:46 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2010-10-05 11:04:35 +0000
@@ -37,7 +37,6 @@
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
-import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.system.util.AuditLogLevel;
import org.hisp.dhis.system.util.AuditLogUtil;
@@ -340,4 +339,36 @@
session.delete( userSetting );
}
+
+ @SuppressWarnings( "unchecked" )
+ public Collection<UserCredentials> searchUsersByName( String key ){
+
+ Session session = sessionFactory.getCurrentSession();
+
+ Criteria criteria = session.createCriteria( UserCredentials.class );
+
+ criteria.add( Restrictions.ilike( "username", "%" + key + "%" ) );
+ criteria.addOrder( Order.asc( "username" ) );
+
+ return criteria.list();
+ }
+
+ @SuppressWarnings( "unchecked" )
+ public Collection<UserCredentials> searchUsersByName( String key, int from, int to ){
+
+ Session session = sessionFactory.getCurrentSession();
+
+ Criteria criteria = session.createCriteria( UserCredentials.class );
+
+ criteria.add( Restrictions.ilike( "username", "%" + key + "%" ) );
+ criteria.addOrder( Order.asc( "username" ) );
+ criteria.setFirstResult( from );
+ criteria.setMaxResults( to );
+
+ return criteria.list();
+ }
+
+ public int countNumberOfSearchUsersByName( String key ){
+ return searchUsersByName( key ).size();
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/paging/paging.css'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/paging/paging.css 2010-07-06 16:01:15 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/paging/paging.css 2010-10-05 11:04:35 +0000
@@ -1,10 +1,10 @@
.paging-container {text-align: right; }
-div.paging {width:400px;float:right; margin-right:22em; text-align: right; height:16px; }
+div.paging {width:300px;float:right; margin-right:5em; text-align: center; height:16px; }
div.paging span, div.paging a {padding: 0 5px;font-weight: bold; font-size: 11px;}
div.paging a {text-decoration: none; color: #FF9900;}
div.paging a:hover {color: #000;}
div.paging span.page {color:#000;}
div.paging span.seperator {display:none;}
-ul.pageSizeSelection {list-style:none; float:left; width: 160px; margin: 0; padding: 0;}
+ul.pageSizeSelection {list-style:none; float:left; width: 300px; margin: 0; padding: 0;}
ul.pageSizeSelection span {width: 100px; display: block; float :left;}
ul.pageSizeSelection input {text-align: right}
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/paging/paging.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/paging/paging.vm 2010-07-11 06:33:07 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/paging/paging.vm 2010-10-05 11:04:35 +0000
@@ -8,22 +8,33 @@
<input type="hidden" id="baseLink" value="$!baseLink"/>
<input type="hidden" id="currentPage" value="$!currentPage"/>
#if ( $numberOfPages > 0 )
- <ul class="pageSizeSelection">
- <li>
- <span>$i18n.getString("no_of_pages"):</span> $numberOfPages</li>
- <li>
- <span >$i18n.getString("size_of_page"):</span>
- <input type="text" id="sizeOfPage" value="$!pageSize" style="width:50px" onchange="changePageSize('$baseLink');">
- </li>
- <li>
- <span >$i18n.getString("jump_to_page"):</span>
- <input type="text" id="jumpToPage" value="$!currentPage" style="width:50px" onchange="jumpToPage('$baseLink');">
- </li>
- <li>
- <span></span>
- <input type="button" id="submitButton" value="$i18n.getString('go')" onclick="jumpToPage('$baseLink');">
- </li>
- </ul>
+ <table style="background-color: #ebf0f6;" width='100%'>
+ <tr>
+ <td>
+ <span>$i18n.getString("no_of_pages"):</span> $numberOfPages
+ </td>
+ <td>
+ <span >$i18n.getString("size_of_page"):</span>
+
+ <input type="text" id="sizeOfPage" value="$!pageSize" style="width:50px" onchange="changePageSize('$baseLink');">
+ </td>
+ <td>
+ <span >$i18n.getString("jump_to_page"):</span>
+
+ <input type="text" id="jumpToPage" value="$!currentPage" style="width:50px" onchange="jumpToPage('$baseLink');">
+ </td>
+ <td>
+ <input type="button" id="submitButton" value="$i18n.getString('go')" onclick="jumpToPage('$baseLink');">
+ </td>
+
+ </tr>
+
+ <tr>
+ <td colspan='4' ><hr/></td>
+ </tr>
+
+ <tr>
+ <td colspan='4'>
<div class="paging">
#if ($currentPage > 1)
#set ( $prev = $currentPage - 1 )
@@ -57,4 +68,8 @@
<span class="last" title="Last">»»</span>
#end
</div>
+
+ </td>
+ </tr>
+ </table>
#end
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java 2010-09-23 16:02:44 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java 2010-10-05 11:04:35 +0000
@@ -3,8 +3,8 @@
import java.util.List;
import org.apache.struts2.ServletActionContext;
-import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.system.paging.Paging;
+
import com.opensymphony.xwork2.ActionSupport;
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java 2010-09-23 16:02:44 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java 2010-10-05 11:04:35 +0000
@@ -32,15 +32,19 @@
import java.util.Collections;
import java.util.List;
+import org.apache.commons.collections.CollectionUtils;
+import org.hisp.dhis.datadictionary.DataDictionary;
+import org.hisp.dhis.datadictionary.comparator.DataDictionaryNameComparator;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementGroup;
+import org.hisp.dhis.dataelement.comparator.DataElementGroupNameComparator;
import org.hisp.dhis.paging.ActionPagingSupport;
+import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserCredentials;
import org.hisp.dhis.user.UserStore;
import org.hisp.dhis.user.comparator.UsernameComparator;
-import com.opensymphony.xwork2.Action;
-import org.hisp.dhis.user.CurrentUserService;
-
/**
* @author Torgeir Lorange Ostby
* @version $Id: GetUserListAction.java 2869 2007-02-20 14:26:09Z andegje $
@@ -65,6 +69,7 @@
{
this.currentUserService = currentUserService;
}
+
// -------------------------------------------------------------------------
// Output
// -------------------------------------------------------------------------
@@ -83,7 +88,18 @@
return currentUserName;
}
-
+ private String key;
+
+ public void setKey( String key )
+ {
+ this.key = key;
+ }
+
+ public String getKey()
+ {
+ return key;
+ }
+
// -------------------------------------------------------------------------
// Action implemantation
// -------------------------------------------------------------------------
@@ -94,7 +110,7 @@
this.paging = createPaging( userStore.getAllUsers().size() );
Collection<User> users = userStore.getAllUsers( paging.getStartPos(), paging.getPageSize() );
-
+
userCredentialsList = new ArrayList<UserCredentials>();
for ( User user : users )
@@ -113,4 +129,25 @@
currentUserName = userCredentials.getUsername();
return SUCCESS;
}
+
+ public String searchUserByName()
+ {
+ if ( key.isEmpty() )
+ {
+ return INPUT;
+ }
+
+ this.paging = createPaging( userStore.countNumberOfSearchUsersByName(key) );
+
+ userCredentialsList = new ArrayList<UserCredentials>(userStore.searchUsersByName( key, paging.getStartPos(), paging.getPageSize() ));
+
+ Collections.sort( userCredentialsList, new UsernameComparator() );
+ User currentUser = userStore.getUser( currentUserService.getCurrentUser().getId() );
+ UserCredentials userCredentials = userStore.getUserCredentials( currentUser );
+
+ currentUserName = userCredentials.getUsername();
+
+ return SUCCESS;
+ }
+
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/struts.xml 2010-09-23 16:02:44 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/struts.xml 2010-10-05 11:04:35 +0000
@@ -35,6 +35,15 @@
<interceptor-ref name="organisationUnitTreeStack"/>
</action>
+ <action name="searchUser"
+ class="org.hisp.dhis.user.action.GetUserListAction" method="searchUserByName">
+ <result name="success" type="velocity-xml">
+ /dhis-web-maintenance-user/responseUsers.vm</result>
+ <result name="input" type="velocity-xml">
+ /dhis-web-maintenance-user/responseInput.vm</result>
+ <param name="onExceptionReturn">plainTextError</param>
+ </action>
+
<action name="getUser" class="org.hisp.dhis.user.action.GetUserAction">
<result name="success" type="velocity-xml">/dhis-web-maintenance-user/responseUser.vm</result>
<param name="onExceptionReturn">plainTextError</param>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm 2010-09-23 16:02:44 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm 2010-10-05 11:04:35 +0000
@@ -2,16 +2,36 @@
<table style="width:100%">
<tr>
+ <td>
+ <table width='100%'>
+ <tr>
+ <td colspan='5'>
+ <div class="paging-container">
+ #parse( "/dhis-web-commons/paging/paging.vm" )
+ </div>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
<td style="vertical-align:top">
- <table width="100%">
+ <table width='100%'>
<tr>
- <td>$i18n.getString( "filter_by_username" ): <form style="display:inline" action="none" onsubmit="return false"><input type="text" onkeyup="filterValues( this.value )"/></form></td>
+ <td>$i18n.getString( "filter_by_username" ):
+ <form style="display:inline" action="none" onsubmit="return false">
+ <div style="inline">
+ <input type="text" id='key'>
+ <input type="button" value="$i18n.getString( "go" )" onclick="searchUserName();" />
+ </div>
+ </form>
+ </td>
<td></td>
<td></td>
<td colspan="3" style="text-align:right"><input type="button" value="$i18n.getString( 'add_new' )" onclick="window.location.href='showAddUserForm.action'"/></td>
</tr>
</table>
- <table class="listTable" id="listTable">
+ <table class="listTable" id="userList" width='100%'>
<col/>
<col/>
<col/>
@@ -26,8 +46,8 @@
<tbody id="list">
#foreach( $userCredentials in $userCredentialsList )
<tr id="tr${userCredentials.id}">
- <td onclick="showUserDetails( $userCredentials.id )">$encoder.htmlEncode( $userCredentials.username )</td>
- <td onclick="showUserDetails( $userCredentials.id )">$encoder.htmlEncode( $userCredentials.user.surname ), $encoder.htmlEncode( $userCredentials.user.firstName )</td>
+ <td>$encoder.htmlEncode( $userCredentials.username )</td>
+ <td>$encoder.htmlEncode( $userCredentials.user.surname ), $encoder.htmlEncode( $userCredentials.user.firstName )</td>
<td style="text-align:center">
<a href="showUpdateUserForm.action?id=$userCredentials.id" title="$i18n.getString( 'edit' )"><img src="../images/edit.png" alt="$i18n.getString( 'edit' )"/></a></td>
@@ -77,7 +97,18 @@
<script type="text/javascript">
var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "confirm_delete_user" ) , "'")';
var i18n_none = '$encoder.jsEscape( $i18n.getString( "none" ) , "'")';
+
+ var i18n_edit = '$encoder.jsEscape( $i18n.getString( "edit" ) , "'")';
+ var i18n_remove = '$encoder.jsEscape( $i18n.getString( "remove" ) , "'")';
+ var i18n_show_details = '$encoder.jsEscape( $i18n.getString( "show_details" ) , "'")';
+ var i18n_username = '$encoder.jsEscape( $i18n.getString( "username" ) , "'")';
+ var i18n_name = '$encoder.jsEscape( $i18n.getString( "name" ) , "'")';
+ var i18n_operations = '$encoder.jsEscape( $i18n.getString( "operations" ) , "'")';
+ var currentUserName = '$currentUserName';
+
jQuery(document).ready(function(){
tableSorter( 'listTable' );
+
+
});
</script>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js 2010-09-23 09:52:41 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js 2010-10-05 11:04:35 +0000
@@ -1,3 +1,118 @@
+// -----------------------------------------------------------------------------
+// Search users
+// -----------------------------------------------------------------------------
+
+function searchUserName(){
+
+ var params = 'key=' + getFieldValue('key');
+ var request = new Request();
+ request.setResponseTypeXML( 'xmlObject' );
+ request.setCallbackSuccess( searchUserNameReceived );
+ request.sendAsPost(params);
+ request.send( 'searchUser.action' );
+}
+
+function searchUserNameReceived(xmlObject){
+
+ var type = xmlObject.getAttribute( 'type' );
+ if ( type != null && type == 'input' ){
+ window.location.href = 'alluser.action';
+ return;
+ }
+
+ currentUserName = getElementValue( xmlObject, 'currentUserName' );
+ // get user list
+ var users = xmlObject.getElementsByTagName( "user" );
+ // get tbody to add dataelements
+ var myTable = byId( 'userList');
+ var tBody = myTable.getElementsByTagName('tbody')[0];
+ // delete row into tbody
+ for(var k = tBody.rows.length; k >= 0;k--)
+ {
+ myTable.deleteRow(k - 1);
+ }
+
+ // add header for table
+ var newTR = document.createElement('tr');
+ // add 1st column username
+ var newTD1 = document.createElement('th');
+ newTD1.innerHTML = i18n_username;
+ // add 2nd column name
+ var newTD2 = document.createElement('th');
+ newTD2.innerHTML = i18n_name;
+ // add 3rd column operators
+ var newTD3 = document.createElement('th');
+ newTD3.innerHTML = i18n_operations;
+ newTD3.setAttribute('colspan', 3);
+ newTD3.setAttribute('class', '{sorter: false}');
+
+ newTR.appendChild ( newTD1 );
+ newTR.appendChild ( newTD2 );
+ newTR.appendChild ( newTD3 );
+
+ tBody.appendChild(newTR);
+
+ for ( var i = 0 ; i < users.length ; i++ )
+ {
+
+ // get dataelement
+ var user = users.item(i);
+ var id = user.getElementsByTagName("id")[0].firstChild.nodeValue;
+ var username = user.getElementsByTagName("username")[0].firstChild.nodeValue;
+ var name = user.getElementsByTagName("surname")[0].firstChild.nodeValue + ", "
+ + user.getElementsByTagName("firstName")[0].firstChild.nodeValue;
+
+ // add new row
+ var newTR = document.createElement('tr');
+ newTR.setAttribute('id', "tr" + id + "");
+ if( i%2 == 0){
+ newTR.setAttribute( "class", "listRow" );
+ }else{
+ newTR.setAttribute( "class", "listAlternateRow" );
+ }
+ // add new column - username column
+ var newTD1 = document.createElement('td');
+ newTD1.innerHTML = username;
+ // add new column - name column
+ var newTD2 = document.createElement('td');
+ newTD2.innerHTML = name;
+ // insert column into row
+ newTR.appendChild ( newTD1 );
+ newTR.appendChild ( newTD2 );
+ // add new column
+ newTR = addOperatorColumns( newTR, id, username );
+
+ tBody.appendChild(newTR);
+ }
+}
+
+function addOperatorColumns(rowObject, id, username) {
+ // add new column - edit button
+ var newTD1 = document.createElement('td');
+ newTD1.innerHTML = '<a href="showUpdateUserForm.action?id='+ id
+ + '" title=' + i18n_edit + '>'
+ + '<img src=../images/edit.png alt=' + i18n_edit + '></a>';
+ rowObject.appendChild(newTD1);
+
+ // add new column - remove button
+ var newTD2 = document.createElement('td');
+ if(currentUserName != username){
+ newTD2.innerHTML = "<a href=\"javascript:removeUser("
+ + id + ",'" + username + "' )\" title="
+ + i18n_remove + '>' + '<img src="../images/delete.png" alt="'
+ + i18n_remove + '"></a>';
+ }
+ rowObject.appendChild(newTD2);
+
+ // add new column - show details button
+ var newTD3 = document.createElement('td');
+ newTD3.innerHTML = '<a href="javascript:showUserDetails( ' + id + ' )" '
+ + 'title="' + i18n_show_details + '">'
+ + '<img src="../images/information.png" alt="' + i18n_show_details + '"></a>';
+ rowObject.appendChild(newTD3);
+
+ return rowObject;
+}
// -----------------------------------------------------------------------------
// View details
=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/responseUsers.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/responseUsers.vm 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/responseUsers.vm 2010-10-05 11:04:35 +0000
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<users>
+ #foreach($userCredentials in $userCredentialsList)
+ <user>
+ <id>$userCredentials.id</id>
+ <username>$encoder.xmlEncode( $userCredentials.username )</username>
+ <surname>$encoder.xmlEncode( $userCredentials.user.surname )</surname>
+ <firstName>$encoder.xmlEncode( $userCredentials.user.firstName )</firstName>
+ <email>$!encoder.xmlEncode( $userCredentials.user.email )</email>
+ <phoneNumber>$!encoder.xmlEncode( $userCredentials.user.phoneNumber )</phoneNumber>
+ <numberOrgunit>$userCredentials.user.organisationUnits.size()</numberOrgunit>
+ </user>
+ #end
+ <currentUserName>$currentUserName</currentUserName>
+</users>