dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08317
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1988: Support paginition on data element group list.
------------------------------------------------------------
revno: 1988
committer: Quang <Quang@Quang-PC>
branch nick: trunk
timestamp: Tue 2010-11-02 20:02:10 +0700
message:
Support paginition on data element group list.
added:
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/dataElementGroupSearch.vm
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/GetDataElementGroupListAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/dataElementGroup.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/dataElementGroup.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/dataelement/DataElementService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2010-09-23 15:16:08 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2010-11-02 13:02:10 +0000
@@ -526,4 +526,11 @@
int countNumberOfSearchDataElementByName( String key );
+ Collection<DataElementGroup> getAllDataElementGroups( int from, int to );
+
+ int getNumberOfDataElementGroups();
+
+ Collection<DataElementGroup> searchDataElementGroupByName( String key, int from, int to );
+
+ int countNumberOfSearchDataElementGroupByName( String key );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java 2010-09-23 15:16:08 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java 2010-11-02 13:02:10 +0000
@@ -298,4 +298,13 @@
Collection<DataElement> searchDataElementByName( String key, int from, int to );
int countNumberOfSearchDataElementByName( String key );
+
+ Collection<DataElementGroup> getAllDataElementGroups( int from, int to );
+
+ int getNumberOfDataElementGroups();
+
+ Collection<DataElementGroup> searchDataElementGroupByName( String key, int from, int to );
+
+ int countNumberOfSearchDataElementGroupByName( String key );
+
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2010-09-23 15:16:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2010-11-02 13:02:10 +0000
@@ -665,4 +665,27 @@
return dataElementStore.countNumberOfSearchDataElementByName( key );
}
+ @Override
+ public Collection<DataElementGroup> getAllDataElementGroups( int from, int to )
+ {
+ return dataElementStore.getAllDataElementGroups( from, to );
+ }
+
+ @Override
+ public int getNumberOfDataElementGroups()
+ {
+ return dataElementStore.getNumberOfDataElementGroups();
+ }
+
+ @Override
+ public Collection<DataElementGroup> searchDataElementGroupByName( String key, int from, int to )
+ {
+ return dataElementStore.searchDataElementGroupByName( key, from, to );
+ }
+
+ @Override
+ public int countNumberOfSearchDataElementGroupByName( String key )
+ {
+ return dataElementStore.countNumberOfSearchDataElementGroupByName( key );
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2010-10-29 12:19:15 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2010-11-02 13:02:10 +0000
@@ -546,4 +546,53 @@
return criteria.list();
}
+
+ @Override
+ public Collection<DataElementGroup> getAllDataElementGroups( int from, int to )
+ {
+ Session session = sessionFactory.getCurrentSession();
+
+ Criteria criteria = session.createCriteria( DataElementGroup.class );
+ criteria.addOrder( Order.asc( "name" ) );
+ criteria.setFirstResult( from );
+ criteria.setMaxResults( to );
+ criteria.setCacheable( true );
+
+ return criteria.list();
+ }
+
+ @Override
+ public int getNumberOfDataElementGroups()
+ {
+ String sql = "select count(*) from DataElementGroup";
+ Query query = sessionFactory.getCurrentSession().createQuery( sql );
+ Number countResult = (Number) query.uniqueResult();
+
+ return countResult.intValue();
+ }
+
+ @Override
+ public Collection<DataElementGroup> searchDataElementGroupByName( String key, int from, int to )
+ {
+ Session session = sessionFactory.getCurrentSession();
+
+ Criteria criteria = session.createCriteria( DataElementGroup.class );
+ criteria.add( Restrictions.ilike( "name", "%" + key + "%" ) );
+ criteria.addOrder( Order.asc( "name" ) );
+ criteria.setFirstResult( from );
+ criteria.setMaxResults( to );
+
+ return criteria.list();
+ }
+
+ @Override
+ public int countNumberOfSearchDataElementGroupByName( String key )
+ {
+ Session session = sessionFactory.getCurrentSession();
+
+ Criteria criteria = session.createCriteria( DataElementGroup.class );
+ criteria.add( Restrictions.ilike( "name", "%" + key + "%" ) );
+
+ return criteria.list().size();
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/GetDataElementGroupListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/GetDataElementGroupListAction.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/GetDataElementGroupListAction.java 2010-11-02 13:02:10 +0000
@@ -28,21 +28,18 @@
*/
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import org.hisp.dhis.dataelement.DataElementGroup;
import org.hisp.dhis.dataelement.DataElementService;
-import org.hisp.dhis.dataelement.comparator.DataElementGroupNameComparator;
-
-import com.opensymphony.xwork2.ActionSupport;
+import org.hisp.dhis.paging.ActionPagingSupport;
/**
* @author Torgeir Lorange Ostby
* @version $Id: GetDataElementGroupListAction.java 2869 2007-02-20 14:26:09Z andegje $
*/
public class GetDataElementGroupListAction
- extends ActionSupport
+ extends ActionPagingSupport<DataElementGroup>
{
// -------------------------------------------------------------------------
// Dependencies
@@ -56,7 +53,7 @@
}
// -------------------------------------------------------------------------
- // Output
+ // Input and Output
// -------------------------------------------------------------------------
private List<DataElementGroup> dataElementGroups;
@@ -65,6 +62,18 @@
{
return dataElementGroups;
}
+
+ private String key;
+
+ public String getKey()
+ {
+ return key;
+ }
+
+ public void setKey( String key )
+ {
+ this.key = key;
+ }
// -------------------------------------------------------------------------
// Action implementation
@@ -72,10 +81,25 @@
public String execute()
{
- dataElementGroups = new ArrayList<DataElementGroup>( dataElementService.getAllDataElementGroups() );
+ this.paging = createPaging( dataElementService.getNumberOfDataElementGroups() );
- Collections.sort( dataElementGroups, new DataElementGroupNameComparator() );
+ dataElementGroups = new ArrayList<DataElementGroup>( dataElementService.getAllDataElementGroups( paging.getStartPos(), paging.getPageSize() ) );
return SUCCESS;
}
+
+ public String searchByName()
+ {
+ if(key != null && !key.trim().equals( "" )) {
+
+ this.paging = createPaging( dataElementService.countNumberOfSearchDataElementGroupByName( key ) );
+
+ dataElementGroups = new ArrayList<DataElementGroup>(dataElementService.searchDataElementGroupByName( key, paging.getStartPos(), paging.getPageSize() ));
+
+ return SUCCESS;
+ }
+ else {
+ return execute();
+ }
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml 2010-10-28 09:17:13 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml 2010-11-02 13:02:10 +0000
@@ -204,6 +204,14 @@
<param name="page">/dhis-web-maintenance-datadictionary/dataElementGroup.vm</param>
<param name="menu">/dhis-web-maintenance-datadictionary/menu.vm</param>
<param name="javascripts">javascript/dataElementGroup.js</param>
+ <param name="stylesheets">../dhis-web-commons/paging/paging.css</param>
+ </action>
+
+ <action name="searchDataElementGroup"
+ class="org.hisp.dhis.dd.action.dataelementgroup.GetDataElementGroupListAction" method="searchByName">
+ <result name="success" type="velocity">
+ /dhis-web-maintenance-datadictionary/dataElementGroupSearch.vm</result>
+
</action>
<action name="getDataElementGroup"
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/dataElementGroup.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/dataElementGroup.vm 2010-09-21 06:16:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/dataElementGroup.vm 2010-11-02 13:02:10 +0000
@@ -6,10 +6,18 @@
<td style="vertical-align:top">
<table width="100%">
<tr>
- <td>$i18n.getString( "filter_by_name" ): <form style="display:inline" action="none" onsubmit="return false"><div style="inline"><input type="text" onkeyup="filterValues( this.value )"/></div></form></td>
+ <td>$i18n.getString( "filter_by_name" ):
+ <form style="display:inline" action="none" onsubmit="return false">
+ <div style="inline">
+ <input type="text" id="key" name="id"/>
+ <input type="button" value="$i18n.getString( 'go' )" id="searchButton" onclick="searchDataElementGroup()" />
+ </div>
+ </form>
+ </td>
<td style="text-align:right"><input type="button" value="$i18n.getString( 'add_new' )" onclick="window.location.href='showAddDataElementGroupForm.action'" style="width:80px"/></td>
</tr>
</table>
+ <div id="content">
<table class="listTable" id="dataElementGroupList">
<col/>
<col width="20"/>
@@ -34,7 +42,11 @@
#end
</tbody>
</table>
-
+ <p></p>
+ <div class="paging-container">
+ #parse( "/dhis-web-commons/paging/paging.vm" )
+ </div>
+ </div>
</td>
<td style="width:20em; padding-left:2em; vertical-align:top">
=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/dataElementGroupSearch.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/dataElementGroupSearch.vm 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/dataElementGroupSearch.vm 2010-11-02 13:02:10 +0000
@@ -0,0 +1,104 @@
+<script type="text/javascript" src="../main.js"></script>
+
+<table class="listTable" id="dataElementGroupList">
+ <col/>
+ <col width="20"/>
+ <col width="20"/>
+ <col width="20"/>
+ <col width="20"/>
+ <thead>
+ <tr>
+ <th>$i18n.getString( "name" )</th>
+ <th colspan="4" class="{sorter: false}">$i18n.getString( "operations" )</th>
+ </tr>
+ </thead>
+ <tbody id="list">
+ #foreach( $dataElementGroup in $dataElementGroups )
+ <tr id="tr${dataElementGroup.id}">
+ <td onclick="showDataElementGroupDetails( $dataElementGroup.id )">$encoder.htmlEncode( $dataElementGroup.name )</td>
+ <td style="text-align:center"><a href="showUpdateDataElementGroupForm.action?id=$dataElementGroup.id" title="$i18n.getString( 'edit' )"><img src="../images/edit.png" alt="$i18n.getString( 'edit' )"/></a></td>
+ <td style="text-align:center"><a href="javascript:translate( 'DataElementGroup', '$dataElementGroup.id' )"><img src="../images/i18n.png" alt="$i18n.getString( 'translation_translate' )"/></a></td>
+ <td style="text-align:center"><a href="javascript:removeDataElementGroup( $dataElementGroup.id, '$encoder.jsEncode( $dataElementGroup.name )' )" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"/></a></td>
+ <td style="text-align:center"><a href="javascript:showDataElementGroupDetails( $dataElementGroup.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">
+ #set ( $baseLink = $paging.baseLink )
+ #set ( $pageSize = $paging.pageSize )
+ #set ( $currentPage = $paging.currentPage )
+ #set ( $startPage = $paging.startPage )
+ #set ( $numberOfPages = $paging.numberOfPages )
+
+ <input type="hidden" id="baseLink" value="$!baseLink"/>
+ <input type="hidden" id="currentPage" value="$!currentPage"/>
+ #if ( $numberOfPages > 0 )
+ <table style="background-color: #ebf0f6;" width='100%'>
+ <tr>
+ <td>
+ <span>$i18n.getString("no_of_pages"):</span> <span id="numberOfPage">$numberOfPages</span>
+ </td>
+ <td>
+ <span >$i18n.getString("size_of_page"):</span>
+
+ <input type="text" id="sizeOfPage" value="$!pageSize" style="width:50px" onchange="changePageSizeSearch();">
+ </td>
+ <td>
+ <span >$i18n.getString("jump_to_page"):</span>
+
+ <input type="text" id="jumpToPage" value="$!currentPage" style="width:50px" onchange="jumpToPageSearch();">
+ </td>
+ <td>
+ <input type="button" id="submitButton" value="$i18n.getString('go')" onclick="jumpToPageSearch();">
+ </td>
+
+ </tr>
+
+ <tr>
+ <td colspan='4' ><hr/></td>
+ </tr>
+
+ <tr>
+ <td colspan='4'>
+ <div class="paging">
+ #if ($currentPage > 1)
+ #set ( $prev = $currentPage - 1 )
+ <a href="#" class="first" title="First" onclick="searchDataElementGroupPaging(1, ${pageSize});">««</a>
+ <a href="#" class="prev" title="Previous" onclick="searchDataElementGroupPaging(${prev}, ${pageSize});">«</a>
+ #else
+ <span class="first" title="First">««</span>
+ <span class="prev" title="Previous">«</span>
+ #end
+
+ #foreach( $i in [0..4] )
+ #set( $p = $startPage + $i )
+ #if ( $p <= $numberOfPages )
+ #if( $i > 0 )
+ <span class="seperator">|</span>
+ #end
+ #if( $p != $currentPage )
+ <a href="#" class="page" title="Page $p" onclick="searchDataElementGroupPaging(${p}, ${pageSize});">$p</a>
+ #else
+ <span class="page" title="Page $p">$p</span>
+ #end
+ #end
+ #end
+
+ #if ( $currentPage < $numberOfPages )
+ #set ( $next = $currentPage + 1 )
+ <a href="#" class="next" title="Next" onclick="searchDataElementGroupPaging(${next}, ${pageSize});">»</a>
+ <a href="#" class="last" title="Last" onclick="searchDataElementGroupPaging(${numberOfPages}, ${pageSize});">»»</a>
+ #else
+ <span class="next" title="Next">» </span>
+ <span class="last" title="Last">»»</span>
+ #end
+ </div>
+
+ </td>
+ </tr>
+ </table>
+ #end
+</div>
+
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/dataElementGroup.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/dataElementGroup.js 2010-09-01 16:55:23 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/dataElementGroup.js 2010-11-02 13:02:10 +0000
@@ -35,4 +35,58 @@
function removeDataElementGroup( dataElementGroupId, dataElementGroupName )
{
removeItem( dataElementGroupId, dataElementGroupName, i18n_confirm_delete, "removeDataElementGroup.action" );
-}
\ No newline at end of file
+}
+
+// -----------------------------------------------------------------------------
+// Search data element group
+// -----------------------------------------------------------------------------
+
+function searchDataElementGroup(){
+
+ var params = 'key=' + getFieldValue( 'key' );
+
+ var url = 'searchDataElementGroup.action?' + params;
+
+ if( getFieldValue( 'key' ) != null && getFieldValue( 'key' ) != '' )
+ {
+ $( '#content' ).load( url, null, unLockScreen );
+ lockScreen();
+ }
+ else
+ {
+ window.location.href='dataElementGroup.action?' + params;
+ }
+}
+
+function searchDataElementGroupPaging(currentPage, pageSize)
+{
+
+ var params = 'key=' + getFieldValue( 'key' );
+ params += '¤tPage=' + currentPage;
+ params += '&pageSize=' + pageSize;
+
+ var url = 'searchDataElementGroup.action?' + params;
+
+ if( getFieldValue( 'key' ) != null && getFieldValue( 'key' ) != '' )
+ {
+ $( '#content' ).load( url, null, unLockScreen );
+ lockScreen();
+ }
+ else
+ {
+ window.location.href='dataElementGroup.action?' + params;
+ }
+}
+
+function changePageSizeSearch()
+{
+ var pageSize = jQuery("#sizeOfPage").val();
+ searchDataElementGroupPaging(1, pageSize);
+}
+
+function jumpToPageSearch()
+{
+ var pageSize = jQuery("#sizeOfPage").val();
+ var currentPage = jQuery("#jumpToPage").val();
+ searchDataElementGroupPaging(currentPage, pageSize);
+}