← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2193: Implement pagination in indicator list.

 

------------------------------------------------------------
revno: 2193
committer: Quang <Quang@Quang-PC>
branch nick: trunk
timestamp: Sat 2010-11-27 14:46:29 +0700
message:
  Implement pagination in indicator list.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/DefaultIndicatorService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/hibernate/HibernateIndicatorStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/GetDataElementGroupListAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicator/GetIndicatorListAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicator.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/indicator.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-api/src/main/java/org/hisp/dhis/indicator/IndicatorService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorService.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorService.java	2010-11-27 07:46:29 +0000
@@ -65,6 +65,14 @@
     
     Collection<Indicator> getIndicatorsWithoutGroups();
 
+    int getIndicatorCountByName( String name );
+    
+    Collection<Indicator> getIndicatorsBetweenByName( String name, int first, int max );
+    
+    int getIndicatorCount();
+    
+    Collection<Indicator> getIndicatorsBetween(int first, int max );
+    
     // -------------------------------------------------------------------------
     // IndicatorType
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorStore.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorStore.java	2010-11-27 07:46:29 +0000
@@ -58,4 +58,12 @@
     Collection<Indicator> getIndicatorsWithGroupSets();
     
     Collection<Indicator> getIndicatorsWithoutGroups();
+
+    int getIndicatorCountByName( String name );
+    
+    Collection<Indicator> getIndicatorsBetweenByName( String name, int first, int max );
+    
+    int getIndicatorCount();
+    
+    Collection<Indicator> getIndicatorsBetween(int first, int max );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/DefaultIndicatorService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/DefaultIndicatorService.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/DefaultIndicatorService.java	2010-11-27 07:46:29 +0000
@@ -175,6 +175,26 @@
     {
         return i18n( i18nService, indicatorStore.getIndicatorsWithoutGroups() );
     }
+
+    public int getIndicatorCount()
+    {
+        return indicatorStore.getIndicatorCount();
+    }
+
+    public int getIndicatorCountByName( String name )
+    {
+        return indicatorStore.getIndicatorCountByName( name );
+    }
+
+    public Collection<Indicator> getIndicatorsBetween( int first, int max )
+    {
+        return i18n( i18nService, indicatorStore.getIndicatorsBetween( first, max ) );
+    }
+
+    public Collection<Indicator> getIndicatorsBetweenByName( String name, int first, int max )
+    {
+        return i18n( i18nService, indicatorStore.getIndicatorsBetweenByName( name, first, max ) );
+    }
     
     // -------------------------------------------------------------------------
     // IndicatorType
@@ -369,4 +389,5 @@
                 }
             } );     
     }
+
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/hibernate/HibernateIndicatorStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/hibernate/HibernateIndicatorStore.java	2010-10-29 12:19:15 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/hibernate/HibernateIndicatorStore.java	2010-11-27 07:46:29 +0000
@@ -45,16 +45,6 @@
 public class HibernateIndicatorStore 
     extends HibernateGenericStore<Indicator> implements IndicatorStore
 {
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    private SessionFactory sessionFactory;
-
-    public void setSessionFactory( SessionFactory sessionFactory )
-    {
-        this.sessionFactory = sessionFactory;
-    }
 
     // -------------------------------------------------------------------------
     // Indicator
@@ -167,5 +157,25 @@
         final String hql = "from Indicator d where d.groups.size = 0";
         
         return sessionFactory.getCurrentSession().createQuery( hql ).list();
+    }
+
+    public int getIndicatorCount()
+    {
+        return getCount();
+    }
+
+    public int getIndicatorCountByName( String name )
+    {
+        return getCountByName( name );
+    }
+
+    public Collection<Indicator> getIndicatorsBetween( int first, int max )
+    {
+        return getBetween( first, max );
+    }
+
+    public Collection<Indicator> getIndicatorsBetweenByName( String name, int first, int max )
+    {
+        return getBetweenByName( name, first, max );
     }    
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2010-11-23 18:25:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2010-11-27 07:46:29 +0000
@@ -57,6 +57,7 @@
 
 	<bean id="org.hisp.dhis.indicator.IndicatorStore"
 		class="org.hisp.dhis.indicator.hibernate.HibernateIndicatorStore">
+		<property name="clazz" value="org.hisp.dhis.indicator.Indicator"/>
 		<property name="sessionFactory" ref="sessionFactory"/>
 	</bean>
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/GetDataElementGroupListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/GetDataElementGroupListAction.java	2010-11-25 21:34:02 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/GetDataElementGroupListAction.java	2010-11-27 07:46:29 +0000
@@ -87,7 +87,7 @@
 
     public String execute()
     {
-        if ( isNotBlank( key) )
+        if ( isNotBlank( key ) )
         {
             this.paging = createPaging( dataElementService.getDataElementGroupCountByName( key ) );
             

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicator/GetIndicatorListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicator/GetIndicatorListAction.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicator/GetIndicatorListAction.java	2010-11-27 07:46:29 +0000
@@ -27,24 +27,21 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.apache.commons.lang.StringUtils.isNotBlank;
+
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 
-import org.apache.commons.collections.CollectionUtils;
 import org.hisp.dhis.datadictionary.DataDictionary;
 import org.hisp.dhis.datadictionary.DataDictionaryService;
 import org.hisp.dhis.datadictionary.comparator.DataDictionaryNameComparator;
 import org.hisp.dhis.indicator.Indicator;
-import org.hisp.dhis.indicator.IndicatorGroup;
 import org.hisp.dhis.indicator.IndicatorService;
-import org.hisp.dhis.indicator.comparator.IndicatorGroupNameComparator;
 import org.hisp.dhis.options.datadictionary.DataDictionaryModeManager;
 import org.hisp.dhis.options.displayproperty.DisplayPropertyHandler;
-
-import com.opensymphony.xwork2.Action;
+import org.hisp.dhis.paging.ActionPagingSupport;
 
 /**
  * @author Torgeir Lorange Ostby
@@ -52,7 +49,7 @@
  *          ch_bharath1 $
  */
 public class GetIndicatorListAction
-    implements Action
+extends ActionPagingSupport<Indicator>
 {
     // -------------------------------------------------------------------------
     // Dependencies
@@ -119,13 +116,6 @@
         return dataDictionaries;
     }
 
-    private List<IndicatorGroup> indicatorGroups;
-
-    public List<IndicatorGroup> getIndicatorGroups()
-    {
-        return indicatorGroups;
-    }
-
     // -------------------------------------------------------------------------
     // Input & Output
     // -------------------------------------------------------------------------
@@ -142,16 +132,16 @@
         this.dataDictionaryId = dataDictionaryId;
     }
 
-    private Integer indicatorGroupId;
-
-    public Integer getIndicatorGroupId()
+    private String key;
+    
+    public String getKey()
     {
-        return indicatorGroupId;
+        return key;
     }
 
-    public void setIndicatorGroupId( Integer indicatorGroupId )
+    public void setKey( String key )
     {
-        this.indicatorGroupId = indicatorGroupId;
+        this.key = key;
     }
 
     // -------------------------------------------------------------------------
@@ -176,10 +166,6 @@
             dataDictionaryModeManager.setCurrentDataDictionary( dataDictionaryId );
         }
         
-        indicatorGroups = new ArrayList<IndicatorGroup>( indicatorService.getAllIndicatorGroups() );
-
-        Collections.sort( indicatorGroups, new IndicatorGroupNameComparator() );
-
         dataDictionaries = new ArrayList<DataDictionary>( dataDictionaryService.getAllDataDictionaries() );
 
         Collections.sort( dataDictionaries, new DataDictionaryNameComparator() );
@@ -188,25 +174,25 @@
         // Criteria
         // -------------------------------------------------------------------------
 
-        if ( dataDictionaryId != null && indicatorGroupId == null )
+        if ( isNotBlank( key ) ) // Filter on key only if set
+        {
+            this.paging = createPaging( indicatorService.getIndicatorCountByName( key ) );
+            
+            indicators = new ArrayList<Indicator>( indicatorService.getIndicatorsBetweenByName( key, paging.getStartPos(), paging.getPageSize() ) );
+        }
+        else if ( dataDictionaryId != null )
         {
             indicators = new ArrayList<Indicator>( dataDictionaryService.getDataDictionary( dataDictionaryId ).getIndicators() );
-        }
-        else if ( dataDictionaryId == null && indicatorGroupId != null )
-        {
-            indicators = new ArrayList<Indicator>( indicatorService.getIndicatorGroup( indicatorGroupId ).getMembers() );
-        }
-        else if ( dataDictionaryId != null && indicatorGroupId != null )
-        {
-            Collection<Indicator> dictionary = dataDictionaryService.getDataDictionary( dataDictionaryId ).getIndicators();
-
-            Collection<Indicator> members = indicatorService.getIndicatorGroup( indicatorGroupId ).getMembers();
-
-            indicators = new ArrayList<Indicator>( CollectionUtils.intersection( dictionary, members ) );
+            
+            this.paging = createPaging( indicators.size() );
+            
+            indicators = getBlockElement( indicators, paging.getStartPage(), paging.getEndPos() );
         }
         else
         {
-            indicators = new ArrayList<Indicator>( indicatorService.getAllIndicators() );
+            this.paging = createPaging( indicatorService.getIndicatorCount() );
+            
+            indicators = new ArrayList<Indicator>( indicatorService.getIndicatorsBetween( paging.getStartPos(), paging.getPageSize() ) );
         }
         
         Collections.sort( indicators, indicatorComparator );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml	2010-11-25 21:34:02 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml	2010-11-27 07:46:29 +0000
@@ -318,6 +318,7 @@
 			<param name="page">/dhis-web-maintenance-datadictionary/indicator.vm</param>
 			<param name="menu">/dhis-web-maintenance-datadictionary/menu.vm</param>
 			<param name="javascripts">javascript/indicator.js,javascript/dataDictionary.js,javascript/denum.js</param>
+			<param name="stylesheets">../dhis-web-commons/paging/paging.css</param>
 		</action>
 
 		<action name="showSortIndicatorForm"

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicator.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicator.vm	2010-11-20 08:23:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicator.vm	2010-11-27 07:46:29 +0000
@@ -6,7 +6,7 @@
 		<td style="vertical-align:top">
 			<table width="100%">
 				<tr>
-					<td>$i18n.getString( "filter_by_name" ): <form style="display:inline" action="none" onsubmit="return false"><div style="inline"><input type="text" onkeyup="filterValues( this.value )"></div></form></td>
+					<td>#filterDiv( "indicator" )</td>
 					<td>$i18n.getString( "select_data_dictionary" ):
 						<div style="inline">
 							<select id="dataDictionaryList" name="dataDictionaryList" onchange="criteriaChanged()" style="min-width:140px">
@@ -17,17 +17,7 @@
 							</select>
 						</div>
 					</td>
-                    <td>$i18n.getString( "filter_by_group_view_all" ):
-                        <div style="inline">
-                            <select id="indicatorGroupList" name="indicatorGroupList" onchange="criteriaChanged()" style="min-width:200px">
-                                <option value="null">[ $i18n.getString( "all" ) ]</option>
-                                #foreach( $indicatorGroup in $indicatorGroups )
-                                <option value="$indicatorGroup.id" #if ( $indicatorGroup.id == $indicatorGroupId ) selected="selected"#end>$indicatorGroup.name</option>
-                                #end
-                            </select>
-                        </div>
-                    </td>					
-					<td colspan="4" style="text-align:right">
+					<td style="text-align:right">
                         <input type="button" value="$i18n.getString( 'get_pdf' )" onclick="exportPdfByType( 'indicator' );" style="width:80px"/>
 						<input type="button" value="$i18n.getString( 'sort' )" onclick="window.location.href='showSortIndicatorForm.action'" style="width:80px"/>
 					    #if ( $dataDictionaryMode == "extended" )
@@ -69,6 +59,8 @@
 				#end
 				</tbody>
 			</table>
+			<p></p>
+	  		#parse( "/dhis-web-commons/paging/paging.vm" )
 
 		</td>
 		<td style="width:20em; padding-left:2em; vertical-align:top">

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/indicator.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/indicator.js	2010-11-20 08:23:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/indicator.js	2010-11-27 07:46:29 +0000
@@ -4,10 +4,9 @@
 
 function criteriaChanged()
 {
-    var indicatorGroupId = getListValue( "indicatorGroupList" );
     var dataDictionaryId = getListValue( "dataDictionaryList" );
     
-    var url = "indicator.action?&dataDictionaryId=" + dataDictionaryId + "&indicatorGroupId=" + indicatorGroupId;
+    var url = "indicator.action?&dataDictionaryId=" + dataDictionaryId;
     
     window.location.href = url;
 }