← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3696: Applied patch from Hieu. Implements paging in databrowser. Good work.

 

------------------------------------------------------------
revno: 3696
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2011-05-22 14:36:53 +0200
message:
  Applied patch from Hieu. Implements paging in databrowser. Good work.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Grid.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/ActionSupport.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/DataBrowserAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataBrowserGrid.vm


--
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/common/Grid.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Grid.java	2011-02-23 23:26:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Grid.java	2011-05-22 12:36:53 +0000
@@ -172,6 +172,14 @@
     Grid limitGrid( int limit );
     
     /**
+     * Limits the grid by the given start and end position.
+     * 
+     * @param startPos the start position.
+     * @param endPos the end position.
+     */
+    Grid limitGrid( int startPos, int endPos );
+    
+    /**
      * Sorts the grid ascending on the column at the given columnIndex.
      * 
      * @param columnIndex the column index, starting on 1.

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java	2011-02-28 19:51:49 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java	2011-05-22 12:36:53 +0000
@@ -326,6 +326,18 @@
         return this;
     }
     
+    public Grid limitGrid( int startPos, int endPos )
+    {
+        if ( startPos < 0 || endPos < startPos || getHeight() < endPos )
+        {
+            throw new IllegalStateException( "Illegal start / end pos: " + startPos + ", " + endPos + ", " + getHeight() );
+        }
+
+        grid = grid.subList( startPos, endPos );
+
+        return this;
+    }
+    
     public Grid sortGrid( int columnIndex, int order )
     {
         columnIndex = columnIndex - 1;

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/ActionSupport.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/ActionSupport.java	2011-03-14 09:16:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/ActionSupport.java	2011-05-22 12:36:53 +0000
@@ -49,17 +49,16 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
+import org.hisp.dhis.paging.ActionPagingSupport;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
 
-import com.opensymphony.xwork2.Action;
-
 /**
  * @author Dang Duy Hieu
  * @version $Id$
  */
 public abstract class ActionSupport
-    implements Action
+    extends ActionPagingSupport<Grid>
 {
     protected static final String KEY_DATABROWSERGRID = "dataBrowserGridResults";
 
@@ -203,7 +202,7 @@
 
     public void setSelectedUnitChanger( String selectedUnitChanger )
     {
-        this.selectedUnitChanger = selectedUnitChanger;
+        this.selectedUnitChanger = selectedUnitChanger.trim();
     }
 
     public void setOrgunitid( String orgunitid )
@@ -379,27 +378,20 @@
         return myList;
     }
 
-    public List<MetaValue> getMetaValues()
+    public List<Object> getMetaValues()
     {
-        List<MetaValue> metaValues = new ArrayList<MetaValue>();
-
-        for ( Object object : grid.getColumn( 0 ) )
-        {
-            metaValues.add( (MetaValue) object );
-        }
-
-        return metaValues;
+        return grid.getColumn( 0 );
     }
 
-    public Map<MetaValue, List<Object>> getMetaValueMaps()
+    public Map<Integer, List<Object>> getMetaValueMaps()
     {
-        Map<MetaValue, List<Object>> maps = new Hashtable<MetaValue, List<Object>>();
+        Map<Integer, List<Object>> maps = new Hashtable<Integer, List<Object>>();
 
         for ( List<Object> row : grid.getRows() )
         {
             if ( !row.isEmpty() && row.size() > 1 )
             {
-                maps.put( (MetaValue) row.get( 0 ), row.subList( 1, row.size() ) );
+                maps.put( ((MetaValue) row.get( 0 )).getId(), row.subList( 1, row.size() ) );
             }
         }
 
@@ -433,6 +425,13 @@
             + toDate + ", " + i18n.getString( "period_type" ) + ": " + i18n.getString( periodTypeId ) );
     }
 
+    protected void doPaging()
+    {
+        this.paging = this.createPaging( grid.getHeight() );
+
+        grid.limitGrid( paging.getStartPos(), paging.getEndPos() );
+    }
+
     private String mappingMode( String mode )
     {
         if ( mode.equals( "DS" ) )

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/DataBrowserAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/DataBrowserAction.java	2011-03-14 05:00:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/DataBrowserAction.java	2011-05-22 12:36:53 +0000
@@ -29,6 +29,7 @@
 
 import static org.hisp.dhis.system.util.TextUtils.nullIfEmpty;
 
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.system.util.DateUtils;
 import org.hisp.dhis.util.SessionUtils;
@@ -46,33 +47,35 @@
     // Action implementation
     // -------------------------------------------------------------------------
 
+    @Override
     public String execute()
     {
         isZeroAdded = (showZeroCheckBox != null) && showZeroCheckBox.equals( TRUE );
 
+        // Check if the second selected date is later than the first selected
+        // date
+        if ( nullIfEmpty( fromDate ) == null && nullIfEmpty( toDate ) == null )
+        {
+            if ( DateUtils.checkDates( fromDate, toDate ) )
+            {
+                return ERROR;
+            }
+        }
+
         // If set, change the current selected unit
         if ( selectedUnitChanger != null )
         {
-            selectionManager.setSelectedOrganisationUnit( this.organisationUnitService.getOrganisationUnit( Integer
-                .parseInt( selectedUnitChanger.trim() ) ) );
+            selectionManager.setSelectedOrganisationUnit( organisationUnitService.getOrganisationUnit( Integer
+                .parseInt( selectedUnitChanger ) ) );
         }
 
+        OrganisationUnit selectedUnit = selectionManager.getSelectedOrganisationUnit();
+
         // Checks if the selected unit is a leaf node of tree then
         // We must add parent as the same parameter value
-        if ( parent == null && mode.equals( "OU" ) && selectionManager.getSelectedOrganisationUnit() != null
-            && selectionManager.getSelectedOrganisationUnit().getChildren().size() == 0 )
-        {
-            parent = selectionManager.getSelectedOrganisationUnit().getId() + EMPTY;
-        }
-
-        // Check if the second selected date is later than the first selected
-        // date
-        if ( nullIfEmpty( fromDate ) == null && nullIfEmpty( toDate ) == null )
-        {
-            if ( DateUtils.checkDates( fromDate, toDate ) )
-            {
-                return ERROR;
-            }
+        if ( parent == null && mode.equals( "OU" ) && selectedUnit != null && selectedUnit.getChildren().size() == 0 )
+        {
+            parent = selectedUnit.getId() + EMPTY;
         }
 
         PeriodType periodType = periodService.getPeriodTypeByName( periodTypeId );
@@ -170,11 +173,15 @@
             return ERROR;
         }
 
+        // Set title to grid
         setGridTitle();
 
         // Convert column date names
         convertColumnNames( grid );
 
+        // Do paging
+        doPaging();
+
         // Set DataBrowserTable variable for PDF export
         SessionUtils.setSessionVar( KEY_DATABROWSERGRID, grid );
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataBrowserGrid.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataBrowserGrid.vm	2011-03-17 14:42:52 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataBrowserGrid.vm	2011-05-22 12:36:53 +0000
@@ -10,6 +10,7 @@
 <br/><br/>$i18n.getString( "no_data_found" )
 #else
 
+<div id="content">
 <table id="drillDownGrid" class="listTable" border="1">
 	<thead>
 		<tr>
@@ -21,7 +22,7 @@
 
 	<tbody>	
 		#foreach( $meta in $!MetaValues )
-		#set( $list = $!MetaValueMaps.get( $meta ) )
+		#set( $list = $!MetaValueMaps.get( $meta.id ) )
 		<tr>
 			#if ( $mode=="OU" && !$parent && $meta.id )
 			#set ( $URL = "?mode=OU&periodTypeId=$periodTypeId&fromDate=$fromDate&toDate=$toDate&showZeroCheckBox=$!showZeroCheckBox&selectedUnitChanger=$meta.id" )
@@ -44,7 +45,10 @@
 		#end
 	</tbody>
 </table>
-	
+<p></p>
+#parse( "/dhis-web-commons/paging/paging.vm" )
+</div>
+
 <!-- Drill-down menu -->
 
 <div id="drillDownMenu" class="menuDropDownArea" onmouseover="cancelHideDropDownTimeout()" onmouseout="hideDropDownTimeout()">