← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2557: Impl paging in indicator numerator/denominator screen using existing methods

 

------------------------------------------------------------
revno: 2557
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-01-13 13:12:41 +0100
message:
  Impl paging in indicator numerator/denominator screen using existing methods
modified:
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.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-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java	2011-01-13 10:50:02 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java	2011-01-13 12:12:41 +0000
@@ -31,14 +31,17 @@
 import java.util.Collections;
 import java.util.List;
 
+import org.apache.commons.lang.StringUtils;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.dataelement.comparator.DataElementOperandNameComparator;
-import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.paging.ActionPagingSupport;
+import org.hisp.dhis.system.filter.AggregatableDataElementFilter;
+import org.hisp.dhis.system.util.Filter;
+import org.hisp.dhis.system.util.FilterUtils;
 
 /**
  * @author Lars Helge Overland
@@ -46,6 +49,8 @@
 public class GetOperandsAction
     extends ActionPagingSupport<DataElementOperand>
 {
+    private static Filter<DataElement> AGGREGATABLE_FILTER = new AggregatableDataElementFilter();
+    
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -81,6 +86,13 @@
     {
         this.id = id;
     }
+    
+    private String key;
+
+    public void setKey( String key )
+    {
+        this.key = key;
+    }
 
     private Integer dataSetId;
 
@@ -118,39 +130,37 @@
     {
         List<DataElement> dataElements = new ArrayList<DataElement>();
 
-        if ( id == null )
-        {
-            dataElements = new ArrayList<DataElement>( dataElementService.getAggregateableDataElements() );
+        if ( id != null )
+        {
+            dataElements = new ArrayList<DataElement>( dataElementService.getDataElementGroup( id ).getMembers() );
+        }
+        else if ( !StringUtils.isEmpty( key ) )
+        {
+            dataElements = new ArrayList<DataElement>( dataElementService.getDataElementsLikeName( key ) );
+        }
+        else if ( dataSetId != null )
+        {
+            dataElements = new ArrayList<DataElement>( dataSetService.getDataSet( dataSetId ).getDataElements() );
         }
         else
         {
-            dataElements = new ArrayList<DataElement>( dataElementService.getDataElementsByGroupId( id ) );
-        }
-
-        if ( dataSetId != null )
-        {
-            DataSet dataSet = dataSetService.getDataSet( dataSetId );
-
-            dataElements.retainAll( dataSet.getDataElements() );
+            dataElements = new ArrayList<DataElement>( dataElementService.getAllDataElements() );
         }
 
         if ( aggregationOperator != null )
         {
-            dataElements.retainAll( dataElementService.getDataElementsByAggregationOperator( aggregationOperator ) );
+            FilterUtils.filter( dataElements, AGGREGATABLE_FILTER );
         }
 
-        operands = new ArrayList<DataElementOperand>( dataElementCategoryService.getOperands( dataElements,
-            includeTotals ) );
+        operands = new ArrayList<DataElementOperand>( dataElementCategoryService.getOperands( dataElements, includeTotals ) );
 
         Collections.sort( operands, new DataElementOperandNameComparator() );
 
         if ( this.usepaging )
         {
-
             this.paging = createPaging( operands.size() );
 
             operands = operands.subList( paging.getStartPos(), paging.getEndPos() );
-
         }
 
         return SUCCESS;

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm	2011-01-13 10:50:02 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm	2011-01-13 12:12:41 +0000
@@ -1,10 +1,10 @@
 <div id="indicator-expression-container">
 <form id="indicator-expression-form">
-<table width="750" style="text-align:left">
+<table width="800" style="text-align:left">
 	<colgroup>
 		<col width="250"/>
 		<col width="50"/>
-		<col width="450"/>
+		<col width="500"/>
 	</colgroup>
 	<tr>
 		<th colspan="2">$i18n.getString( "description" )</th>
@@ -16,9 +16,9 @@
 		</td>
 		<td></td>
 		<td>
-			<input type="radio" name="aggregationOperator" checked="true" value="sum" onclick="getOperandsByDataElementGroup()"/>	
+			<input type="radio" name="aggregationOperator" checked="true" value="sum" onclick="getOperandsPage()"/>	
 			$i18n.getString( "sum" )<br/>
-			<input type="radio" name="aggregationOperator" value="average" onclick="getOperandsByDataElementGroup()"/>
+			<input type="radio" name="aggregationOperator" value="average" onclick="getOperandsPage()"/>
 			$i18n.getString( "average" )
 		</td>
 	</tr>
@@ -42,12 +42,10 @@
 		<td></td>
 		<td valign="top">
 			<label>$encoder.htmlEncode( $i18n.getString( "filter_by_name" ) )</label><br/>
-			<input type="text" id="filter" name="filter" style="width:450px" onkeyup="filterList( this.value, 'dataElementId' )"/><br/>
-
-			<select id="dataElementGroupId" name="dataElementGroupId" style="width:450px" onchange="getOperandsByDataElementGroup(this.value)">
-			</select><br/>
-
-			<select id="dataElementId" name="dataElementId" size="10" style="min-width:450px" ondblclick="insertText( 'expression', this.value, 'aggregationOperator' )">
+			<input type="text" id="filter" name="filter" style="width:380px">
+			<input type="button" value="$i18n.getString( 'filter' )" onclick="getOperandsPage()" style="width:60px"><br/>
+
+			<select id="dataElementId" name="dataElementId" size="7" style="min-width:450px" ondblclick="insertText( 'expression', this.value, 'aggregationOperator' )">
 			</select>
 		</td>
 	</tr>
@@ -55,7 +53,7 @@
 		<th colspan="3">$i18n.getString( "description" )</th>		
 	</tr>
 	<tr>
-		<td colspan="3"><div id="formulaText" style="width:740px;height:70px;overflow:auto"></div></td>
+		<td colspan="3"><div id="formulaText" style="width:740px;height:100px;overflow:auto"></div></td>
 	</tr>
 	<tr>
 		<td colspan="3"></td>
@@ -79,21 +77,19 @@
 		dialog = jQuery("#indicator-expression-container").dialog({
 			modal: true,
 			autoOpen:false,
-			minWidth: 770,
+			minWidth: 820,
 			minHeight: 500,
-			width:770,
+			width:820,
 			height:500
 		});
 		
-		getOperandsByDataElementGroup();
+		getOperandsPage();
 	});
 
 	function indicatorNumeratorForm()
 	{
 		numerator = true;
 		
-		dataDictionary.loadDataElementGroups( "#indicator-expression-container select[id=dataElementGroupId]" );	
-		
 		validator.resetForm();
 		
 		var expression = getFieldValue( 'numerator' );
@@ -113,8 +109,6 @@
 	{
 		numerator = false;
 		
-		dataDictionary.loadDataElementGroups( "#indicator-expression-container select[id=dataElementGroupId]" );	
-		
 		validator.resetForm();
 		
 		var expression = getFieldValue( 'denominator' );
@@ -131,13 +125,15 @@
 		dialog.dialog( "open");
 	}
 	
-	function getOperandsByDataElementGroup()
+	function getOperandsPage()
 	{
 		var aggregationOperator = getRadioValue( 'aggregationOperator' );
 		
 		var id = getFieldValue( "indicator-expression-container select[id=dataElementGroupId]");	
 
-		dataDictionary.loadOperands( "#indicator-expression-container select[id=dataElementId]", {id: id, aggregationOperator: aggregationOperator} , usepaging:true );	
+		var key = getFieldValue( "indicator-expression-container input[id=filter]");
+
+		dataDictionary.loadOperands( "#indicator-expression-container select[id=dataElementId]", {id: id, aggregationOperator: aggregationOperator, usepaging: true, key: key } );	
 
 		checkAggregationOperator();
 	}