← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2879: Added gui for sort order and limit in report table. Testing appreciated.

 

------------------------------------------------------------
revno: 2879
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2011-02-19 01:09:05 +0100
message:
  Added gui for sort order and limit in report table. Testing appreciated.
modified:
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java
  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/test/java/org/hisp/dhis/system/grid/GridTest.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/SaveTableAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addTableForm.vm
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.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-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java	2011-02-18 19:27:56 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java	2011-02-19 00:09:05 +0000
@@ -522,19 +522,19 @@
         }
 
         // ---------------------------------------------------------------------
-        // Sort and limit
+        // Sort first and then limit
         // ---------------------------------------------------------------------
 
-        if ( reportTable.topLimit() > 0 )
-        {
-            grid = grid.limitGrid( reportTable.topLimit() );
-        }
-        
         if ( reportTable.sortOrder() != ReportTable.NONE )
         {
             grid.sortGrid( grid.getWidth(), reportTable.sortOrder() );
         }
-        
+
+        if ( reportTable.topLimit() > 0 )
+        {
+            grid.limitGrid( reportTable.topLimit() );
+        }
+                
         return grid;
     }
     

=== 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-18 19:27:56 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java	2011-02-19 00:09:05 +0000
@@ -28,6 +28,7 @@
  */
 
 import static org.hisp.dhis.system.util.MathUtils.getRounded;
+import static org.hisp.dhis.system.util.MathUtils.isNumeric;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -315,13 +316,15 @@
     
     public Grid sortGrid( int columnIndex, int order )
     {
-        columnIndex--;
+        columnIndex = columnIndex - 1;
         
         if ( columnIndex < 0 || columnIndex >= getWidth() )
         {
-            return this; // Silently ignore
+            throw new IllegalArgumentException( "Column index out of bounds: " + columnIndex );
         }
         
+        System.out.println( "col index: " + columnIndex + " order " + order );
+        
         Collections.sort( grid, new GridRowComparator( columnIndex, order ) );
         
         return this;
@@ -461,7 +464,7 @@
     // Comparator
     // -------------------------------------------------------------------------
 
-    protected static class GridRowComparator
+    public static class GridRowComparator
         implements Comparator<List<String>>
     {
         private int columnIndex;
@@ -476,13 +479,23 @@
         @Override
         public int compare( List<String> list1, List<String> list2 )
         {
-            if ( order == 0 )
+            if ( order == 0 || list1 == null || list2 == null )
             {
                 return 0;
             }
             
-            return order > 0 ? list2.get( columnIndex ).compareTo( 
-                list1.get( columnIndex ) ) : list1.get( columnIndex ).compareTo( list2.get( columnIndex ) );
+            if ( isNumeric( list1.get( columnIndex ) ) && isNumeric( list2.get( columnIndex ) ) )
+            {
+                final Double value1 = Double.valueOf( list1.get( columnIndex ) );
+                final Double value2 = Double.valueOf( list2.get( columnIndex ) );
+                
+                return order > 0 ? value2.compareTo( value1 ) : value1.compareTo( value2 );
+            }
+            
+            final String value1 = list1.get( columnIndex );
+            final String value2 = list2.get( columnIndex );
+            
+            return order > 0 ? value2.compareTo( value1 ) : value1.compareTo( value2 );
         }
     }
 }

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/grid/GridTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/grid/GridTest.java	2011-02-18 19:27:56 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/grid/GridTest.java	2011-02-19 00:09:05 +0000
@@ -32,6 +32,9 @@
 import static junit.framework.Assert.assertFalse;
 
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 import org.hisp.dhis.common.Grid;
@@ -247,11 +250,11 @@
         
         grid.sortGrid( 2, 1 );
 
-        List<String> rowA = grid.getRow( 0 );
-        assertTrue( rowA.contains( "c" ) );
+        List<String> row1 = grid.getRow( 0 );
+        assertTrue( row1.contains( "c" ) );
 
-        List<String> rowB = grid.getRow( 1 );
-        assertTrue( rowB.contains( "b" ) );        
+        List<String> row2 = grid.getRow( 1 );
+        assertTrue( row2.contains( "b" ) );        
     }
 
     @Test
@@ -265,11 +268,63 @@
         
         grid.sortGrid( 1, -1 );
 
-        List<String> rowA = grid.getRow( 0 );
-        assertTrue( rowA.contains( "1" ) );
-
-        List<String> rowB = grid.getRow( 1 );
-        assertTrue( rowB.contains( "2" ) );        
+        List<String> row1 = grid.getRow( 0 );
+        assertTrue( row1.contains( "1" ) );
+
+        List<String> row2 = grid.getRow( 1 );
+        assertTrue( row2.contains( "2" ) );        
+    }
+    
+    @Test
+    public void testSortC()
+    {
+        Grid grid = new ListGrid();
+        
+        grid.addRow().addValue( "a" ).addValue( "a" ).addValue( "5.2" );
+        grid.addRow().addValue( "b" ).addValue( "b" ).addValue( "0.0" );
+        grid.addRow().addValue( "c" ).addValue( "c" ).addValue( "108.1" );
+        grid.addRow().addValue( "d" ).addValue( "d" ).addValue( "45.0" );
+        grid.addRow().addValue( "e" ).addValue( "e" ).addValue( "4043.9" );
+        grid.addRow().addValue( "f" ).addValue( "f" ).addValue( "0.1" );
+        
+        grid = grid.sortGrid( 3, 1 );
+        
+        List<String> row1 = grid.getRow( 0 );
+        assertTrue( row1.contains( "4043.9" ) );
+
+        List<String> row2 = grid.getRow( 1 );
+        assertTrue( row2.contains( "108.1" ) );
+        
+        List<String> row3 = grid.getRow( 2 );
+        assertTrue( row3.contains( "45.0" ) );
+
+        List<String> row4 = grid.getRow( 3 );
+        assertTrue( row4.contains( "5.2" ) );
+
+        List<String> row5 = grid.getRow( 4 );
+        assertTrue( row5.contains( "0.1" ) );
+
+        List<String> row6 = grid.getRow( 5 );
+        assertTrue( row6.contains( "0.0" ) );    
+    }
+
+    @Test
+    public void testGridRowComparator()
+    {
+        List<List<String>> lists = new ArrayList<List<String>>();
+        List<String> l1 = Arrays.asList( "b", "b", "50" );
+        List<String> l2 = Arrays.asList( "c", "c", "400" );
+        List<String> l3 = Arrays.asList( "a", "a", "6" );
+        lists.add( l1 );
+        lists.add( l2 );
+        lists.add( l3 );
+        
+        Comparator<List<String>> comparator = new ListGrid.GridRowComparator( 2, -1 );
+        Collections.sort( lists, comparator );
+                
+        assertEquals( l3, lists.get( 0 ) );
+        assertEquals( l1, lists.get( 1 ) );
+        assertEquals( l2, lists.get( 2 ) );
     }
     
     @Test

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/SaveTableAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/SaveTableAction.java	2011-02-17 17:14:00 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/SaveTableAction.java	2011-02-19 00:09:05 +0000
@@ -130,6 +130,20 @@
         this.tableName = tableName;
     }
         
+    private Integer sortOrder;
+    
+    public void setSortOrder( Integer sortOrder )
+    {
+        this.sortOrder = sortOrder;
+    }
+    
+    private Integer topLimit;
+
+    public void setTopLimit( Integer topLimit )
+    {
+        this.topLimit = topLimit;
+    }
+
     private boolean regression;
 
     public void setRegression( boolean regression )
@@ -336,12 +350,16 @@
                 dataElements, indicators, dataSets, periods, null, units, null,
                 categoryCombo, doIndicators, doPeriods, doOrganisationUnits, relatives, reportParams, 
                 null, null );
+            reportTable.setSortOrder( sortOrder );
+            reportTable.setTopLimit( topLimit );
         }
         else
         {
             reportTable = reportTableService.getReportTable( tableId );
             
             reportTable.setName( tableName );
+            reportTable.setSortOrder( sortOrder );
+            reportTable.setTopLimit( topLimit );
             reportTable.setRegression( regression );
             reportTable.setDataElements( dataElements );
             reportTable.setIndicators( indicators );

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2011-02-18 21:50:37 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2011-02-19 00:09:05 +0000
@@ -318,4 +318,9 @@
 scheduling_is = Scheduling is
 start = Start
 stop = Stop
-refresh = Refresh
\ No newline at end of file
+refresh = Refresh
+sort_order = Sort order
+none = None
+ascending = Low to high
+descending = High to low
+top_limit = Top limit

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addTableForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addTableForm.vm	2011-02-18 21:50:37 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addTableForm.vm	2011-02-19 00:09:05 +0000
@@ -22,22 +22,43 @@
 	</tr>
 	<tr>
 		<td><label for="tableName">$i18n.getString( "name" )</label></td>
-		<td><input type="text" id="tableName" name="tableName" style="width:270px" value="$!reportTable.name"></td>
+		<td><input type="text" id="tableName" name="tableName" style="width:260px" value="$!reportTable.name"></td>
 		<td><label for="doIndicators">$i18n.getString( "indicators_data_elements_data_sets" )</label></td>
 		<td><input type="checkbox" id="doIndicators" name="doIndicators" value="true"#if( $reportTable.doIndicators ) checked#end></td>
 	</tr>
 	<tr>
-		<td><label for="regression">$i18n.getString( "include_regression" )</label></td>
-        <td><input type="checkbox" onclick="toggleRegression()" id="regression" name="regression" value="true"#if( $reportTable.isRegression() ) checked#end></td>
+		<td><label for="sortOrder">$i18n.getString( "sort_order" )</label></td>
+		<td>
+			<select id="sortOrder" name="sortOrder" style="width:260px">
+			<option value="0"#if( $reportTable.sortOrder() == 0 ) selected#end>$i18n.getString( "none" )</option>
+			<option value="-1"#if( $reportTable.sortOrder() == -1 ) selected#end>$i18n.getString( "ascending" )</option>
+			<option value="1"#if( $reportTable.sortOrder() == 1 ) selected#end>$i18n.getString( "descending" )</option>
+    		</select>
+    	</td>
         <td><label for="doOrganisationUnits">$i18n.getString( "organisation_units" )</label></td>
 		<td><input type="checkbox" id="doOrganisationUnits" name="doOrganisationUnits" value="true"#if( $reportTable.doUnits ) checked#end></td>
 	</tr>
 	<tr>
-		<td></td>
-		<td></td>
+		<td><label for="topLimit">$i18n.getString( "top_limit" )</label></td>
+		<td>
+			<select id="topLimit" name="topLimit" style="width:260px">
+			<option value="0"#if( $reportTable.topLimit() == 0 ) selected#end>$i18n.getString( "none" )</option>
+			<option value="5"#if( $reportTable.topLimit() == 5 ) selected#end>5</option>
+			<option value="10"#if( $reportTable.topLimit() == 10 ) selected#end>10</option>
+			<option value="20"#if( $reportTable.topLimit() == 20 ) selected#end>20</option>
+			<option value="50"#if( $reportTable.topLimit() == 50 ) selected#end>50</option>
+			<option value="100"#if( $reportTable.topLimit() == 100 ) selected#end>100</option>
+    		</select>
+    	</td>
 		<td><label for="doPeriods">$i18n.getString( "periods" )</label></td>
 		<td><input type="checkbox" id="doPeriods" name="doPeriods" value="true"#if( $reportTable.doPeriods ) checked#end></td>
 	</tr>
+	<tr>
+		<td><label for="regression">$i18n.getString( "include_regression" )</label></td>
+        <td><input type="checkbox" onclick="toggleRegression()" id="regression" name="regression" value="true"#if( $reportTable.isRegression() ) checked#end></td>
+		<td></td>
+		<td></td>
+	</tr>
 	
 	<tr>
 		<td colspan="4" style="height:15px"></td>
@@ -49,9 +70,12 @@
 		
     #if( $dimension )
     
-    <!-- Dimensional -->
+    <!-- Dimensional Data Elements-->
     
     <tr>
+        <th>$i18n.getString( "available_dataelements" )</th>      
+    </tr>
+    <tr>
         <td>
             <select id="categoryComboId" name="categoryComboId" style="min-width:640px" onchange="getCategoryComboDataElements()">
                 <option value="-1">[ $i18n.getString( "select_category_combo" ) ]</option>
@@ -60,6 +84,38 @@
                 #end
             </select>
         </td>
+    </tr>    
+    <tr>
+        <td>
+            <select multiple size="6" id="availableDataElements" name="availableDataElements" style="min-width:640px" ondblclick="moveSelectedById( 'availableDataElements', 'selectedDataElements' )">             
+                #foreach ( $element in $dataElements )
+                    <option value="$element.id">$encoder.htmlEncode( $element.name )</option>
+                #end
+            </select>
+        </td>
+    </tr>
+    <tr>
+        <td>
+            <input type="button" value="$i18n.getString( 'add_selected' )" title="$i18n.getString( 'add_selected' )" style="width:120px" onclick="moveSelectedById( 'availableDataElements', 'selectedDataElements' )"><input 
+                type="button" value="$i18n.getString( 'add_all' )" title="$i18n.getString( 'add_all' )" style="width:120px" onclick="moveAllById( 'availableDataElements', 'selectedDataElements' )"><input 
+                type="button" value="$i18n.getString( 'remove_selected' )" title="$i18n.getString( 'remove_selected' )" style="width:120px" onclick="moveSelectedById( 'selectedDataElements', 'availableDataElements' )"><input 
+                type="button" value="$i18n.getString( 'remove_all' )" title="$i18n.getString( 'remove_all' )" style="width:120px" onclick="moveAllById( 'selectedDataElements', 'availableDataElements' )">
+        </td>
+    </tr>
+    <tr>
+        <th>$i18n.getString( "selected_dataelements" )</th>
+    </tr>
+    <tr>
+        <td>
+            <select multiple size="6" id="selectedDataElements" name="selectedDataElements" style="min-width:640px" ondblclick="moveSelectedById( 'selectedDataElements', 'availableDataElements' )">
+                #foreach( $element in $selectedDataElements )
+                    <option value="$element.id">$encoder.htmlEncode( $element.name )</option>
+                #end
+            </select>
+        </td>
+    </tr>
+    <tr>
+        <td style="height:15px"></td>
     </tr>
     
     #else
@@ -116,8 +172,7 @@
     
     <tr>
         <th>$i18n.getString( "available_dataelements" )</th>      
-    </tr>
-    
+    </tr>        
     <tr>
         <td>
             <select id="dataElementGroupId" name="dataElementGroupId" style="min-width:640px" onchange="getDataElements()">
@@ -127,8 +182,7 @@
                 #end
             </select>
         </td>
-    </tr>	    
-    
+    </tr>        
     <tr>
         <td>
             <select multiple size="6" id="availableDataElements" name="availableDataElements" style="min-width:640px" ondblclick="moveSelectedById( 'availableDataElements', 'selectedDataElements' )">             

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.js	2011-02-18 21:50:37 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.js	2011-02-19 00:09:05 +0000
@@ -37,9 +37,18 @@
 
 function selectTableForm()
 {
-    selectAllById( "selectedDataElements" );
-    selectAllById( "selectedIndicators" );
-    selectAllById( "selectedDataSets" );
+	selectAllById( "selectedDataElements" );
+	
+	if ( isNotNull( "selectedIndicators" ) )
+	{
+		selectAllById( "selectedIndicators" );
+	}
+    
+    if ( isNotNull( "selectedDataSets" ) )
+    {
+    	selectAllById( "selectedDataSets" );
+    }
+    
     selectAllById( "selectedPeriods" );
     selectAllById( "selectedOrganisationUnits" );   
 }