← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16295: Add paging functionality for Aggregation query builder.

 

------------------------------------------------------------
revno: 16295
committer: Tran Chau<tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-08-03 23:27:47 +0700
message:
  Add paging functionality for Aggregation query builder.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStore.java
  dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java
  dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/caseaggregation/GetAllCaseAggregationConditionAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/attribute.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/attributeGroup.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/caseAggregation.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/caseaggregation.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programList.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/relationshipType.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/trackedEntity.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/caseaggregation/CaseAggregationConditionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java	2014-08-03 16:27:47 +0000
@@ -92,7 +92,7 @@
      *         match.
      */
     CaseAggregationCondition getCaseAggregationCondition( String name );
-
+    
     /**
      * Returns all {@link CaseAggregationCondition}
      * 
@@ -127,10 +127,13 @@
      * {@link DataElement}
      * 
      * @param dataElements DataElement collection
+     * @param key The name of CaseAggregationCondition
+     * @param first
+     * @param max
      * 
      * @return A collection of CaseAggregationCondition
      */
-    Collection<CaseAggregationCondition> getCaseAggregationCondition( Collection<DataElement> dataElements );
+    Collection<CaseAggregationCondition> getCaseAggregationConditions( Collection<DataElement> dataElements, String key, Integer first, Integer max  );
 
     /**
      * Retrieve a collection of {@link DataElement} by a
@@ -266,4 +269,10 @@
      * @return List of TrackedEntityInstance ids
      */
     List<Integer> executeSQL( String sql );
+   
+    /**
+     * @param dataElements
+     * @return
+     */
+    int countCaseAggregationCondition( Collection<DataElement> dataElements, String key );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStore.java	2014-06-25 15:13:15 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStore.java	2014-08-03 16:27:47 +0000
@@ -64,15 +64,15 @@
     CaseAggregationCondition get( DataElement dataElement, DataElementCategoryOptionCombo optionCombo );
 
     /**
-     * Retrieve a {@link CaseAggregationCondition} by a {@link DataElement} and
-     * {@link DataElementCategoryOptionCombo}
+     * Retrieve a collection of {@link CaseAggregationCondition} by a collection of {@link DataElement} 
      * 
-     * @param dataElement DataElement
-     * @param optionCombo DataElementCategoryOptionCombo
+     * @param dataElements DataElement collection
+     * @param first
+     * @param max
      * 
      * @return A CaseAggregationCondition
      */
-    Collection<CaseAggregationCondition> get( Collection<DataElement> dataElements );
+    Collection<CaseAggregationCondition> get( Collection<DataElement> dataElements, String key, Integer first, Integer max  );
 
     /**
      * Generate period list based on period Type and taskStrategy option
@@ -175,4 +175,12 @@
      * @return List of tracked entity instance ids
      */
     List<Integer> executeSQL( String sql );
+
+    /**
+     * Get the numbers of {@link CaseAggregationCondition} by {@link DataElement} list
+     * @param dataElements
+     * @param ket The name of CaseAggregationCondition
+     * @return
+     */
+    int count( Collection<DataElement> dataElements, String key );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2014-06-25 15:13:15 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2014-08-03 16:27:47 +0000
@@ -173,7 +173,7 @@
     {
         return i18n( i18nService, aggregationConditionStore.getByName( name ) );
     }
-
+    
     @Override
     public void updateCaseAggregationCondition( CaseAggregationCondition caseAggregationCondition )
     {
@@ -396,11 +396,17 @@
         return attributes;
     }
 
-    public Collection<CaseAggregationCondition> getCaseAggregationCondition( Collection<DataElement> dataElements )
+    public Collection<CaseAggregationCondition> getCaseAggregationConditions( Collection<DataElement> dataElements, String key,Integer first, Integer max )
     {
-        return i18n( i18nService, aggregationConditionStore.get( dataElements ) );
+        return i18n( i18nService, aggregationConditionStore.get( dataElements, key, first, max ) );
     }
 
+    @Override
+    public int countCaseAggregationCondition( Collection<DataElement> dataElements, String key )
+    {
+        return aggregationConditionStore.count( dataElements, key );
+    }
+    
     public void aggregate( List<CaseAggregateSchedule> caseAggregateSchedules, String taskStrategy )
     {       
         ConcurrentLinkedQueue<CaseAggregateSchedule> datasetQ = new ConcurrentLinkedQueue<CaseAggregateSchedule>(
@@ -479,7 +485,7 @@
     {
         return aggregationConditionStore.executeSQL( sql );
     }
-
+    
     // -------------------------------------------------------------------------
     // Support Methods
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java	2014-07-07 10:38:51 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java	2014-08-03 16:27:47 +0000
@@ -55,6 +55,9 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.hibernate.Criteria;
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Projections;
 import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.caseaggregation.CaseAggregateSchedule;
 import org.hisp.dhis.caseaggregation.CaseAggregationCondition;
@@ -137,6 +140,24 @@
     }
 
     @Override
+    public int count( Collection<DataElement> dataElements, String key )
+    {
+        Criteria criteria = getCriteria();
+        
+        if( dataElements!= null )
+        {
+            criteria.add(  Restrictions.in( "aggregationDataElement", dataElements ) );
+        }
+        if( key != null )
+        {
+            criteria.add(  Restrictions.ilike( "name", "%" + key + "%" ) );
+        }
+        
+        Number rs = ( Number ) criteria.setProjection(Projections.rowCount()).uniqueResult();
+        return rs != null ? rs.intValue() : 0;
+    }
+    
+    @Override
     public CaseAggregationCondition get( DataElement dataElement, DataElementCategoryOptionCombo optionCombo )
     {
         return (CaseAggregationCondition) getCriteria( Restrictions.eq( "aggregationDataElement", dataElement ),
@@ -145,9 +166,28 @@
 
     @SuppressWarnings( "unchecked" )
     @Override
-    public Collection<CaseAggregationCondition> get( Collection<DataElement> dataElements )
+    public Collection<CaseAggregationCondition> get( Collection<DataElement> dataElements, String key, Integer first, Integer max )
     {
-        return getCriteria( Restrictions.in( "aggregationDataElement", dataElements ) ).list();
+        Criteria criteria = getCriteria();
+        
+        if( dataElements!= null )
+        {
+            criteria.add(  Restrictions.in( "aggregationDataElement", dataElements ) );
+        }
+        if( key != null )
+        {
+            criteria.add(  Restrictions.ilike( "name", "%" + key + "%" ) );
+        }
+        
+        if( first != null && max != null )
+        {
+            criteria.setFirstResult( first );
+            criteria.setMaxResults( max );
+        }
+        
+        criteria.addOrder(Order.desc("name"));
+        
+        return criteria.list();
     }
 
     public Grid getAggregateValue( CaseAggregationCondition caseAggregationCondition, Collection<Integer> orgunitIds,

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/caseaggregation/GetAllCaseAggregationConditionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/caseaggregation/GetAllCaseAggregationConditionAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/caseaggregation/GetAllCaseAggregationConditionAction.java	2014-08-03 16:27:47 +0000
@@ -40,8 +40,7 @@
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSetService;
-
-import com.opensymphony.xwork2.Action;
+import org.hisp.dhis.paging.ActionPagingSupport;
 
 /**
  * @author Chau Thu Tran
@@ -49,7 +48,7 @@
  * @version GetAllCaseAggregationConditionAction.java Nov 18, 2010 10:42:01 AM
  */
 public class GetAllCaseAggregationConditionAction
-    implements Action
+    extends ActionPagingSupport<CaseAggregationCondition>
 {
     // -------------------------------------------------------------------------
     // Dependency
@@ -85,6 +84,13 @@
         return dataSetId;
     }
 
+    private String key;
+
+    public void setKey( String key )
+    {
+        this.key = key;
+    }
+
     private Collection<CaseAggregationCondition> aggregationConditions;
 
     public Collection<CaseAggregationCondition> getAggregationConditions()
@@ -120,12 +126,10 @@
         dataSets = new ArrayList<DataSet>( _datasets );
         Collections.sort( dataSets, IdentifiableObjectNameComparator.INSTANCE );
 
-        if ( dataSetId != null )
-        {
-            DataSet dataSet = dataSetService.getDataSet( dataSetId );
-
-            aggregationConditions = aggregationConditionService.getCaseAggregationCondition( dataSet.getDataElements() );
-        }
+        Collection<DataElement> dataElements = ( dataSetId == null ) ? null : dataSetService.getDataSet( dataSetId ).getDataElements();
+        this.paging = createPaging( aggregationConditionService.countCaseAggregationCondition( dataElements, key ) );
+        aggregationConditions = aggregationConditionService.getCaseAggregationConditions( dataElements, key,
+            paging.getStartPos(), paging.getPageSize() );
         
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/attribute.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/attribute.vm	2014-07-02 12:11:16 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/attribute.vm	2014-08-03 16:27:47 +0000
@@ -43,8 +43,10 @@
                 <td>$encoder.htmlEncode( $!attribute.displayName )</td>
             </tr>
           #end
+		 
       </tbody>
       </table>
+		<p></p>
 		#parse( "/dhis-web-commons/paging/paging.vm" )
 		</td>
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/attributeGroup.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/attributeGroup.vm	2014-06-13 10:58:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/attributeGroup.vm	2014-08-03 16:27:47 +0000
@@ -41,6 +41,7 @@
         #end
       </tbody>
       </table>
+		<p></p>
 		#parse( "/dhis-web-commons/paging/paging.vm" )
     </td>
 		<td id="detailsData">

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/caseAggregation.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/caseAggregation.vm	2014-06-13 10:58:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/caseAggregation.vm	2014-08-03 16:27:47 +0000
@@ -37,7 +37,10 @@
 		<tr>
       <td>$i18n.getString( "filter_by_name" )</td>
       <td>
-				<input type="text" onkeyup="filterValues( this.value , 1)" />
+				<input type="text" id="key" name="key" placeholder="$i18n.getString('filter_by_name')" onchange="getCaseAggConditionByDataset();" style="width:205px;" />
+				<input type="button" value="$i18n.getString('filter')" onclick="getCaseAggConditionByDataset();" class="nornal-button" />
+				<input type="button" value="$i18n.getString('clear')" onclick="setFieldValue('key','');getCaseAggConditionByDataset();" class="nornal-button" />
+				
 			</td>
 			<td colspan="3" style="text-align:right">
 				<input type="button" value="$i18n.getString( 'add_new' )" onclick="showAddCaseAggregationForm();" >
@@ -55,7 +58,9 @@
 			<tbody id="list">
 				#parse( "/dhis-web-maintenance-program/caseAggregationList.vm" )
 			</tbody>
-      </table>
+		</table>
+		<p></p>
+		#parse( "/dhis-web-commons/paging/paging.vm" )
     </td>
 
 		<td id="detailsData">

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/caseaggregation.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/caseaggregation.js	2014-06-13 10:58:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/caseaggregation.js	2014-08-03 16:27:47 +0000
@@ -369,11 +369,12 @@
 function getCaseAggConditionByDataset() {
   $.get('getCaseAggConditionByDataset.action',
     {
-      dataSetId: getFieldValue('dataSetId')
+      dataSetId: getFieldValue('dataSetId'),
+	  key: getFieldValue('key')
     }
     , function( html ) {
-      setTableStyles();
       setInnerHTML('list', html);
+	  setTableStyles();
     });
 }
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programList.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programList.vm	2014-06-13 10:58:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programList.vm	2014-08-03 16:27:47 +0000
@@ -55,8 +55,9 @@
 
       </tbody>
       </table>
+		<p></p>
 		#parse( "/dhis-web-commons/paging/paging.vm" )
-		</td>
+	</td>
 
 		<td id="detailsData">
       <div id="detailsArea">

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/relationshipType.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/relationshipType.vm	2014-06-13 10:58:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/relationshipType.vm	2014-08-03 16:27:47 +0000
@@ -47,6 +47,7 @@
         #end
         </tbody>
         </table>
+		<p></p>
 		#parse( "/dhis-web-commons/paging/paging.vm" )
     </td>
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/trackedEntity.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/trackedEntity.vm	2014-06-13 10:58:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/trackedEntity.vm	2014-08-03 16:27:47 +0000
@@ -42,7 +42,8 @@
           #end
       </tbody>
       </table>
-	  #parse( "/dhis-web-commons/paging/paging.vm" )
+		<p></p>
+		#parse( "/dhis-web-commons/paging/paging.vm" )
     </td>
 
 		<td id="detailsData">