dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08287
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1975: Improve Paging function into Maintenance > Users > User.
------------------------------------------------------------
revno: 1975
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2010-10-30 15:20:17 +0700
message:
Improve Paging function into Maintenance > Users > User.
added:
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/searchUser.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-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-10-28 09:17:13 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java 2010-10-30 08:20:17 +0000
@@ -102,6 +102,16 @@
* @param user the User to delete.
*/
void deleteUser( User user );
+
+ 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 );
+
+ int countAllUsers();
// -------------------------------------------------------------------------
// UserCredentials
@@ -244,11 +254,4 @@
*/
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-10-29 12:19:15 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2010-10-30 08:20:17 +0000
@@ -36,6 +36,7 @@
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.system.util.AuditLogLevel;
@@ -188,6 +189,16 @@
user.getName()) );
}
+ public int countAllUsers()
+ {
+ Session session = sessionFactory.getCurrentSession();
+
+ Query query = session.createQuery( "select count(*) from User" );
+
+ Number rs = (Number) query.uniqueResult();
+
+ return rs != null ? rs.intValue() : 0;
+ }
// -------------------------------------------------------------------------
// UserCredentials
// -------------------------------------------------------------------------
@@ -371,7 +382,18 @@
return criteria.list();
}
- public int countNumberOfSearchUsersByName( String key ){
- return searchUsersByName( key ).size();
+ public int countNumberOfSearchUsersByName( String key )
+ {
+ Session session = sessionFactory.getCurrentSession();
+
+ Criteria criteria = session.createCriteria( UserCredentials.class );
+
+ criteria.add( Restrictions.ilike( "username", "%" + key + "%" ) );
+
+ criteria.setProjection( Projections.rowCount() ).uniqueResult();
+
+ Number rs = (Number) criteria.uniqueResult();
+
+ return rs != null ? rs.intValue() : 0;
}
}
=== 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-10-29 12:19:15 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java 2010-10-30 08:20:17 +0000
@@ -101,7 +101,7 @@
public String execute()
throws Exception
{
- this.paging = createPaging( userStore.getAllUsers().size() );
+ this.paging = createPaging( userStore.countAllUsers() );
Collection<User> users = userStore.getAllUsers( paging.getStartPos(), paging.getPageSize() );
@@ -133,7 +133,7 @@
this.paging = createPaging( userStore.countNumberOfSearchUsersByName(key) );
- userCredentialsList = new ArrayList<UserCredentials>(userStore.searchUsersByName( key, paging.getStartPos(), paging.getPageSize() ));
+ userCredentialsList = new ArrayList<UserCredentials>(userStore.searchUsersByName( key, paging.getStartPos(), paging.getPageSize() ));
Collections.sort( userCredentialsList, new UsernameComparator() );
User currentUser = userStore.getUser( currentUserService.getCurrentUser().getId() );
=== 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-10-05 11:04:35 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/struts.xml 2010-10-30 08:20:17 +0000
@@ -37,11 +37,13 @@
<action name="searchUser"
class="org.hisp.dhis.user.action.GetUserListAction" method="searchUserByName">
- <result name="success" type="velocity-xml">
+ <!--<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>
+ <param name="onExceptionReturn">plainTextError</param> -->
+ <result name="success" type="velocity">
+ /dhis-web-maintenance-user/searchUser.vm</result>
</action>
<action name="getUser" class="org.hisp.dhis.user.action.GetUserAction">
=== 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-10-05 11:04:35 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm 2010-10-30 08:20:17 +0000
@@ -1,98 +1,8 @@
<h3>$i18n.getString( "user_management" )</h3>
-<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%'>
- <tr>
- <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="userList" width='100%'>
- <col/>
- <col/>
- <col/>
- <col width="20"/>
- <thead>
- <tr>
- <th>$i18n.getString( "username" )</th>
- <th>$i18n.getString( "name" )</th>
- <th colspan="3" class="{sorter: false}">$i18n.getString( "operations" )</th>
- </tr>
- </thead>
- <tbody id="list">
- #foreach( $userCredentials in $userCredentialsList )
- <tr id="tr${userCredentials.id}">
- <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>
-
- #if($currentUserName != $userCredentials.username)
- <td style="text-align:center">
- <a href="javascript:removeUser( $userCredentials.id, '$encoder.jsEncode( $userCredentials.username )' )" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"/></a>
- </td>
- #else
- <td style="text-align:center">
- </td>
- #end
- <td style="text-align:center"><a href="javascript:showUserDetails( $userCredentials.id )" title="$i18n.getString( 'show_details' )"><img src="../images/information.png" alt="$i18n.getString( 'show_details' )"/></a></td>
- </tr>
- #end
- </tbody>
- </table>
- <p></p>
- <div class="paging-container">
- #parse( "/dhis-web-commons/paging/paging.vm" )
- </div>
- </td>
- <td style="width:20em; padding-left:2em; vertical-align:top">
-
- <div id="detailsArea" style="display:none">
- <div style="float:right">
- <a href="javascript:hideDetails()" title="$i18n.getString( 'hide_details' )"><img src="../images/close.png" alt="$i18n.getString( 'hide_details' )"/></a>
- </div>
- <p><label>$i18n.getString( "username" ):</label><br/><span id="usernameField"></span></p>
- <p><label>$i18n.getString( "surname" ):</label><br/><span id="surnameField"></span></p>
- <p><label>$i18n.getString( "firstName" ):</label><br/><span id="firstNameField"></span></p>
- <p><label>$i18n.getString( "email" ):</label><br/><span id="emailField"></span></p>
- <p><label>$i18n.getString( "phone_number" ):</label><br/><span id="phoneNumberField"></span></p>
- <p><label>$i18n.getString( "number_of_orgunit" ):</label><br/><span id="numberOrgunitField"></span></p>
- </div>
-
- <div id="warningArea" style="position:fixed;right:10px;top:200px;display:none">
- <div style="float:right">
- <a href="javascript:hideWarning()" title="$i18n.getString( 'hide_warning' )"><img src="../images/close.png" alt="$i18n.getString( 'hide_warning' )"/></a>
- </div>
- <p><span id="warningField"></span></p>
- </div>
-
- </td>
- </tr>
-</table>
+<div id="content">
+#parse( "/dhis-web-maintenance-user/searchUser.vm" )
+</div>
<script type="text/javascript">
var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "confirm_delete_user" ) , "'")';
=== 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-10-05 11:04:35 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js 2010-10-30 08:20:17 +0000
@@ -1,117 +1,21 @@
// -----------------------------------------------------------------------------
// 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;
+function searchUserName()
+{
+ var params = 'key=' + getFieldValue( 'key' );
+
+ var url = 'searchUser.action?' + params;
+
+ if( getFieldValue( 'key' ) != null && getFieldValue( 'key' ) != '' )
+ {
+ $( '#content' ).load( url, null, unLockScreen );
+ lockScreen();
+ }
+ else
+ {
+ window.location.href='alluser.action?' + params;
+ }
}
// -----------------------------------------------------------------------------
=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/searchUser.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/searchUser.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/searchUser.vm 2010-10-30 08:20:17 +0000
@@ -0,0 +1,101 @@
+<script type="text/javascript" src="/dhis-web-maintenance-user/javascript/jquery.bpopup-0.4.1.min.js"></script>
+
+<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%'>
+ <tr>
+ <td>$i18n.getString( "filter_by_username" ):
+ <form style="display:inline" action="none" onsubmit="return false">
+ <div style="inline">
+ <input type="text" id='key' value="$!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="userList" width='100%'>
+ <col/>
+ <col/>
+ <col/>
+ <col width="20"/>
+ <thead>
+ <tr>
+ <th>$i18n.getString( "username" )</th>
+ <th>$i18n.getString( "name" )</th>
+ <th colspan="3" class="{sorter: false}">$i18n.getString( "operations" )</th>
+ </tr>
+ </thead>
+ <tbody id="list">
+ #set( $mark = false )
+ #foreach( $userCredentials in $userCredentialsList )
+ <tr id="tr${userCredentials.id}" #alternate( $mark )>
+ <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>
+
+ #if($currentUserName != $userCredentials.username)
+ <td style="text-align:center">
+ <a href="javascript:removeUser( $userCredentials.id, '$encoder.jsEncode( $userCredentials.username )' )" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"/></a>
+ </td>
+ #else
+ <td style="text-align:center">
+ </td>
+ #end
+ <td style="text-align:center"><a href="javascript:showUserDetails( $userCredentials.id )" title="$i18n.getString( 'show_details' )"><img src="../images/information.png" alt="$i18n.getString( 'show_details' )"/></a></td>
+ </tr>
+ #if( $mark )
+ #set( $mark = false )
+ #else
+ #set( $mark = true )
+ #end
+ #end
+ </tbody>
+ </table>
+ <p></p>
+ <div class="paging-container">
+ #parse( "/dhis-web-commons/paging/paging.vm" )
+ </div>
+ </td>
+ <td style="width:20em; padding-left:2em; vertical-align:top">
+
+ <div id="detailsArea" style="display:none">
+ <div style="float:right">
+ <a href="javascript:hideDetails()" title="$i18n.getString( 'hide_details' )"><img src="../images/close.png" alt="$i18n.getString( 'hide_details' )"/></a>
+ </div>
+ <p><label>$i18n.getString( "username" ):</label><br/><span id="usernameField"></span></p>
+ <p><label>$i18n.getString( "surname" ):</label><br/><span id="surnameField"></span></p>
+ <p><label>$i18n.getString( "firstName" ):</label><br/><span id="firstNameField"></span></p>
+ <p><label>$i18n.getString( "email" ):</label><br/><span id="emailField"></span></p>
+ <p><label>$i18n.getString( "phone_number" ):</label><br/><span id="phoneNumberField"></span></p>
+ <p><label>$i18n.getString( "number_of_orgunit" ):</label><br/><span id="numberOrgunitField"></span></p>
+ </div>
+
+ <div id="warningArea" style="position:fixed;right:10px;top:200px;display:none">
+ <div style="float:right">
+ <a href="javascript:hideWarning()" title="$i18n.getString( 'hide_warning' )"><img src="../images/close.png" alt="$i18n.getString( 'hide_warning' )"/></a>
+ </div>
+ <p><span id="warningField"></span></p>
+ </div>
+
+ </td>
+ </tr>
+</table>
\ No newline at end of file