← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14856: Add filter-by-name and pagging for TrackedEntity ( tracker module ).

 

------------------------------------------------------------
revno: 14856
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-04-15 00:10:45 +0800
message:
  Add filter-by-name and pagging for TrackedEntity   ( tracker module ).
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/GetTrackedEntityListAction.java
  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/trackedentity/TrackedEntityService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityService.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityService.java	2014-04-14 16:10:45 +0000
@@ -101,4 +101,42 @@
      *         collection if there are no TrackedEntitys.
      */
     Collection<TrackedEntity> getAllTrackedEntity();
-}
\ No newline at end of file
+    
+    /**
+     * Returns The number of TrackedEntities with the key searched
+     * 
+     * @param name Keyword for searching by name
+     * 
+     * @return A number
+     * 
+     */
+    Integer getTrackedEntityCountByName( String name );
+
+    /**
+     * Returns {@link TrackedEntity} list with paging
+     * 
+     * @param name Keyword for searching by name
+     * @param min
+     * @param max
+     * @return a collection of all TrackedEntity, or an empty
+     *         collection if there are no TrackedEntity.
+     */
+    Collection<? extends TrackedEntity> getTrackedEntityBetweenByName( String name,
+        int min, int max );
+
+    /**
+     * Returns The number of all TrackedEntity available
+     * 
+     */
+    Integer getTrackedEntityCount();
+
+    /**
+     * Returns {@link TrackedEntity} list with paging
+     * 
+     * @param min
+     * @param max
+     * @return a collection of all TrackedEntity, or an empty
+     *         collection if there are no TrackedEntity.
+     */
+    Collection<TrackedEntity> getTrackedEntitysBetween( int min, int max );
+}

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java	2014-04-14 16:10:45 +0000
@@ -28,11 +28,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Collection;
+
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.Collection;
-
 /**
  * @author Chau Thu Tran
  * @version $ DefaultTrackedEntityService.java Feb 15, 2014 7:28:41 PM $
@@ -98,4 +98,28 @@
         return trackedEntityStore.getAll();
     }
 
+    @Override
+    public Integer getTrackedEntityCountByName( String name )
+    {
+        return trackedEntityStore.getCountLikeName( name );
+    }
+
+    @Override
+    public Collection<? extends TrackedEntity> getTrackedEntityBetweenByName( String name, int min, int max )
+    {
+        return trackedEntityStore.getAllLikeNameOrderedName( name, min, max );
+    }
+
+    @Override
+    public Integer getTrackedEntityCount()
+    {
+        return trackedEntityStore.getCount();
+    }
+
+    @Override
+    public Collection<TrackedEntity> getTrackedEntitysBetween( int min, int max )
+    {
+        return trackedEntityStore.getAllOrderedName( min, max );
+    }
+
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/GetTrackedEntityListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/GetTrackedEntityListAction.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/trackedentity/GetTrackedEntityListAction.java	2014-04-14 16:10:45 +0000
@@ -28,24 +28,25 @@
  * 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.Collections;
 import java.util.List;
 
 import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
+import org.hisp.dhis.paging.ActionPagingSupport;
 import org.hisp.dhis.trackedentity.TrackedEntity;
 import org.hisp.dhis.trackedentity.TrackedEntityService;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import com.opensymphony.xwork2.Action;
-
 /**
  * @author Chau Thu Tran
  * 
  * @version $ AddTrackedEntityAction.java Feb 15, 2014 7:20:44 PM $
  */
 public class GetTrackedEntityListAction
-    implements Action
+extends ActionPagingSupport<TrackedEntity>
 {
     // -------------------------------------------------------------------------
     // Dependency
@@ -65,6 +66,18 @@
         return trackedEntities;
     }
 
+    private String key;
+
+    public String getKey()
+    {
+        return key;
+    }
+
+    public void setKey( String key )
+    {
+        this.key = key;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -73,7 +86,22 @@
     public String execute()
         throws Exception
     {
-        trackedEntities = new ArrayList<TrackedEntity>( trackedEntityService.getAllTrackedEntity() );
+        if ( isNotBlank( key ) )
+        {
+            this.paging = createPaging( trackedEntityService.getTrackedEntityCountByName( key ) );
+
+            trackedEntities = new ArrayList<TrackedEntity>(
+                trackedEntityService.getTrackedEntityBetweenByName( key, paging.getStartPos(),
+                    paging.getPageSize() ) );
+        }
+        else
+        {
+            this.paging = createPaging( trackedEntityService.getTrackedEntityCount() );
+
+            trackedEntities = new ArrayList<TrackedEntity>(
+                trackedEntityService.getTrackedEntitysBetween( paging.getStartPos(),
+                    paging.getPageSize() ) );
+        }
 
         Collections.sort( trackedEntities, IdentifiableObjectNameComparator.INSTANCE );
 

=== 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-02-17 15:00:27 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/trackedEntity.vm	2014-04-14 16:10:45 +0000
@@ -16,7 +16,7 @@
 		<table width="100%">
 			<tr>
 				<td>
-					$i18n.getString( "filter_by_name" ): <input type="text" onkeyup="filterValues( this.value , 1)" style="width:250px"/>
+					#filterDiv( "trackedEntity" )
 				</td>
 				<td colspan="3" style="text-align:right"><input type="button" value="$i18n.getString( "add_new" )" onclick="window.location.href='showAddTrackedEntityForm.action'" style="width:70px"></td>				
 			</tr>
@@ -42,6 +42,7 @@
           #end
       </tbody>
       </table>
+	  #parse( "/dhis-web-commons/paging/paging.vm" )
     </td>
 
 		<td id="detailsData">