← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2548: use ajax paging for load list of operand in add/update indicator

 

------------------------------------------------------------
revno: 2548
committer: Tri <Tri@Tri-Laptop>
branch nick: dhis2
timestamp: Thu 2011-01-13 11:06:07 +0700
message:
  use ajax paging for load list of operand in add/update indicator
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-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-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java	2011-01-06 13:33:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java	2011-01-13 04:06:07 +0000
@@ -114,7 +114,8 @@
      * 
      * @param key the name of the DataElement to return.
      * @return List of DataElements with a given key, or all dataelements if no match.
-     */
+     */  
+    
     Collection<DataElement> searchDataElementByName( String key );
     /**
      * Returns a DataElement with a given short name.
@@ -181,7 +182,16 @@
      * 
      * @return a collection of all active DataElements, or an empty collection
      *         if there are no active DataElements.
+     */    
+    Collection<DataElement> searchAggregateableDataElementsByName( String key );
+
+    /**
+     * Returns all active DataElements.
+     * 
+     * @return a collection of all active DataElements, or an empty collection
+     *         if there are no active DataElements.
      */
+    
     Collection<DataElement> getAllActiveDataElements();
 
     /**
@@ -463,6 +473,14 @@
      * @return data elements with identifier in the given id.
      */
     Collection<DataElement> getDataElementsByGroupId( int groupId );
+    
+    /**
+     * Returns data elements with identifier in the given id.
+     * 
+     * @param groupId is the id of data element group.
+     * @return data elements with identifier in the given id.
+     */
+    Collection<DataElement> searchDataElementsByGroupAndName( int groupId, String key );
 
     /**
      * Defines the given data elements as zero is significant. All other data elements

=== 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	2011-01-06 13:33:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java	2011-01-13 04:06:07 +0000
@@ -143,6 +143,25 @@
      * @return a collection of all active DataElements, or an empty collection
      *         if there are no active DataElements.
      */
+    
+    Collection<DataElement> searchAggregateableDataElementsByName( String key );
+
+    /**
+     * Returns all active DataElements.
+     * 
+     * @return a collection of all active DataElements, or an empty collection
+     *         if there are no active DataElements.
+     */
+    
+    Collection<DataElement> searchDataElementsByGroupAndName( DataElementGroup dataElementGroup, String key );
+
+    /**
+     * Returns all active DataElements.
+     * 
+     * @return a collection of all active DataElements, or an empty collection
+     *         if there are no active DataElements.
+     */
+    
     Collection<DataElement> getAllActiveDataElements();
 
     /**

=== 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	2011-01-06 13:33:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java	2011-01-13 04:06:07 +0000
@@ -27,7 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-
 import static org.hisp.dhis.i18n.I18nUtils.i18n;
 
 import java.util.ArrayList;
@@ -54,7 +53,6 @@
 import org.hisp.dhis.system.util.UUIdUtils;
 import org.springframework.transaction.annotation.Transactional;
 
-
 /**
  * @author Kristian Nordal
  * @version $Id: DefaultDataElementService.java 5243 2008-05-25 10:18:58Z
@@ -221,6 +219,18 @@
         return i18n( i18nService, dataElementStore.getAggregateableDataElements() );
     }
 
+    public Collection<DataElement> searchAggregateableDataElementsByName( String key )
+    {
+        return i18n( i18nService, dataElementStore.searchAggregateableDataElementsByName( key ) );
+    }
+
+    @Override
+    public Collection<DataElement> searchDataElementsByGroupAndName( int id, String key )
+    {
+        return i18n( i18nService, dataElementStore.searchDataElementsByGroupAndName( dataElementGroupStore.get( id ),
+            key ) );
+    }
+
     public Collection<DataElement> getAllActiveDataElements()
     {
         return i18n( i18nService, dataElementStore.getAllActiveDataElements() );
@@ -230,9 +240,10 @@
     {
         return i18n( i18nService, dataElementStore.getDataElementByName( name ) );
     }
-    
-    public Collection<DataElement> searchDataElementByName( String key ){
-    	return i18n( i18nService, dataElementStore.searchDataElementByName( key ) );
+
+    public Collection<DataElement> searchDataElementByName( String key )
+    {
+        return i18n( i18nService, dataElementStore.searchDataElementByName( key ) );
     }
 
     public DataElement getDataElementByAlternativeName( String alternativeName )
@@ -357,7 +368,7 @@
     {
         return dataElementStore.dataElementCategoryOptionComboExists( id );
     }
-    
+
     public Collection<DataElement> getDataElementsLikeName( String name )
     {
         return dataElementStore.getDataElementsLikeName( name );
@@ -367,7 +378,7 @@
     {
         return dataElementStore.getDataElementsBetween( first, max );
     }
-    
+
     public Collection<DataElement> getDataElementsBetweenByName( String name, int first, int max )
     {
         return dataElementStore.getDataElementsBetweenByName( name, first, max );
@@ -377,12 +388,12 @@
     {
         return dataElementStore.getDataElementCount();
     }
-    
+
     public int getDataElementCountByName( String name )
     {
         return dataElementStore.getDataElementCountByName( name );
     }
-    
+
     // -------------------------------------------------------------------------
     // CalculatedDataElement
     // -------------------------------------------------------------------------
@@ -513,7 +524,7 @@
     {
         return i18n( i18nService, dataElementStore.getDataElementsByDataSets( dataSets ) );
     }
-    
+
     // -------------------------------------------------------------------------
     // DataElementGroup
     // -------------------------------------------------------------------------
@@ -605,7 +616,7 @@
     {
         return dataElementGroupStore.getBetween( first, max );
     }
-    
+
     public Collection<DataElementGroup> getDataElementGroupsBetweenByName( String name, int first, int max )
     {
         return dataElementGroupStore.getBetweenByName( name, first, max );
@@ -615,12 +626,12 @@
     {
         return dataElementGroupStore.getCount();
     }
-    
+
     public int getDataElementGroupCountByName( String name )
     {
         return dataElementGroupStore.getCountByName( name );
     }
-    
+
     // -------------------------------------------------------------------------
     // DataElementGroupSet
     // -------------------------------------------------------------------------
@@ -695,6 +706,7 @@
     {
         return dataElementGroupSetStore.getBetweenByName( name, first, max );
     }
+
     // -------------------------------------------------------------------------
     // DataElementOperand
     // -------------------------------------------------------------------------
@@ -709,5 +721,4 @@
         return dataElementStore.getAllGeneratedOperands( dataElements );
     }
 
-
 }

=== 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	2011-01-06 13:33:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java	2011-01-13 04:06:07 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.i18n.I18nUtils.i18n;
+
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Collection;
@@ -43,6 +45,7 @@
 import org.hisp.dhis.dataelement.CalculatedDataElement;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryCombo;
+import org.hisp.dhis.dataelement.DataElementGroup;
 import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.dataelement.DataElementStore;
 import org.hisp.dhis.dataset.DataSet;
@@ -58,7 +61,8 @@
  *          larshelg $
  */
 public class HibernateDataElementStore
-    extends HibernateGenericStore<DataElement> implements DataElementStore
+    extends HibernateGenericStore<DataElement>
+    implements DataElementStore
 {
     // -------------------------------------------------------------------------
     // Dependencies
@@ -195,6 +199,43 @@
         return criteria.list();
     }
 
+    @Override
+    public Collection<DataElement> searchAggregateableDataElementsByName( String key )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Set<String> types = new HashSet<String>();
+
+        types.add( DataElement.VALUE_TYPE_INT );
+        types.add( DataElement.VALUE_TYPE_BOOL );
+
+        Criteria criteria = session.createCriteria( DataElement.class );
+
+        criteria.add( Restrictions.in( "type", types ) );
+        criteria.add( Restrictions.ilike( "name", "%" + key + "%" ) );
+
+        return criteria.list();
+    }
+
+    public Collection<DataElement> searchDataElementsByGroupAndName( DataElementGroup group, String key )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Set<Integer> ids = new HashSet<Integer>();
+
+        for ( DataElement dataElement : group.getMembers() )
+        {
+            ids.add( dataElement.getId() );
+        }
+
+        Criteria criteria = session.createCriteria( DataElement.class );
+
+        criteria.add( Restrictions.in( "id", ids ) );
+        criteria.add( Restrictions.ilike( "name", "%" + key + "%" ) );
+
+        return criteria.list();
+    }
+
     @SuppressWarnings( "unchecked" )
     public Collection<DataElement> getAllActiveDataElements()
     {
@@ -382,7 +423,7 @@
     {
         return getLikeName( name );
     }
-    
+
     public Collection<DataElement> getDataElementsBetween( int first, int max )
     {
         return getBetween( first, max );
@@ -402,7 +443,7 @@
     {
         return getCountByName( name );
     }
-    
+
     // -------------------------------------------------------------------------
     // DataElementOperand
     // -------------------------------------------------------------------------
@@ -454,4 +495,5 @@
             throw new RuntimeException( "Failed to get all operands", ex );
         }
     }
+
 }

=== 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-12 11:07:48 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java	2011-01-13 04:06:07 +0000
@@ -110,6 +110,13 @@
         return operands;
     }
 
+    private String key;
+
+    public void setKey( String key )
+    {
+        this.key = key;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -120,11 +127,13 @@
 
         if ( id == null )
         {
-            dataElements = new ArrayList<DataElement>( dataElementService.getAggregateableDataElements() );
+            dataElements = new ArrayList<DataElement>( dataElementService
+                .searchAggregateableDataElementsByName( key != null ? key : "" ) );
         }
         else
         {
-            dataElements = new ArrayList<DataElement>( dataElementService.getDataElementsByGroupId( id ) );
+            dataElements = new ArrayList<DataElement>( dataElementService.searchDataElementsByGroupAndName( id,
+                key != null ? key : "" ) );
         }
 
         if ( dataSetId != null )
@@ -149,7 +158,7 @@
 
             this.paging = createPaging( operands.size() );
 
-            operands = operands.subList( paging.getStartPos(), paging.getEndPos() );
+            operands = operands.subList( paging.getStartPos(), paging.getEndPos() + 1 );
 
         }
 

=== 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-12 11:07:48 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm	2011-01-13 04:06:07 +0000
@@ -42,7 +42,9 @@
 		<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/>
+			<input type="text" id="filter" name="filter" style="width:400px"/>
+			<a href="javascript:void()" onclick="getOperandsByDataElementGroup()"><img src="../images/search.png"/></a>
+			<br/>
 
 			<select id="dataElementGroupId" name="dataElementGroupId" style="width:450px" onchange="getOperandsByDataElementGroup(this.value)">
 			</select><br/>
@@ -92,7 +94,7 @@
 	{
 		numerator = true;
 		
-		dataDictionary.loadDataElementGroups( "#indicator-expression-container select[id=dataElementGroupId]" );	
+		dataDictionary.loadDataElementGroups( "#indicator-expression-container select[id=dataElementGroupId]");	
 		
 		validator.resetForm();
 		
@@ -135,9 +137,11 @@
 	{
 		var aggregationOperator = getRadioValue( 'aggregationOperator' );
 		
-		var id = getFieldValue( "indicator-expression-container select[id=dataElementGroupId]");	
+		var id = getFieldValue( "indicator-expression-container select[id=dataElementGroupId]");
+		
+		var key = getFieldValue( "indicator-expression-container input[id=filter]");
 
-		dataDictionary.loadOperands( "#indicator-expression-container select[id=dataElementId]", {id: id, aggregationOperator: aggregationOperator} , usepaging:true );	
+		dataDictionary.loadOperands( "#indicator-expression-container select[id=dataElementId]", {id: id, aggregationOperator: aggregationOperator, usepaging:true, key:key } );	
 
 		checkAggregationOperator();
 	}