dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #30949
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15737: generate next/prev links for Pager
------------------------------------------------------------
revno: 15737
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-06-17 21:48:34 +0200
message:
generate next/prev links for Pager
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/DefaultLinkService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/LinkService.java
--
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-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java 2014-06-17 15:45:23 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java 2014-06-17 19:48:34 +0000
@@ -179,6 +179,8 @@
handleLinksAndAccess( options, entityList );
+ linkService.generatePagerLinks( pager, getEntityClass() );
+
RootNode rootNode = new RootNode( "metadata" );
rootNode.setDefaultNamespace( DxfNamespaces.DXF_2_0 );
rootNode.setNamespace( DxfNamespaces.DXF_2_0 );
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/DefaultLinkService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/DefaultLinkService.java 2014-06-16 11:17:25 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/DefaultLinkService.java 2014-06-17 19:48:34 +0000
@@ -28,21 +28,21 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Collection;
-
import javassist.util.proxy.ProxyFactory;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.collection.spi.PersistentCollection;
+import org.hisp.dhis.common.Pager;
import org.hisp.dhis.schema.Property;
import org.hisp.dhis.schema.Schema;
import org.hisp.dhis.schema.SchemaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collection;
+
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@@ -58,6 +58,48 @@
private ContextService contextService;
@Override
+ public void generatePagerLinks( Pager pager, Class<?> klass )
+ {
+ if ( pager == null )
+ {
+ return;
+ }
+
+ Schema schema = schemaService.getDynamicSchema( klass );
+
+ if ( !schema.haveEndpoint() )
+ {
+ return;
+ }
+
+ String endpoint = contextService.getServletPath() + "/" + schema.getApiEndpoint();
+
+ if ( pager.getPage() < pager.getPageCount() )
+ {
+ String nextPath = endpoint + "?page=" + (pager.getPage() + 1);
+ nextPath += pager.pageSizeIsDefault() ? "" : "&pageSize=" + pager.getPageSize();
+
+ pager.setNextPage( nextPath );
+ }
+
+ if ( pager.getPage() > 1 )
+ {
+ if ( (pager.getPage() - 1) == 1 )
+ {
+ String prevPath = pager.pageSizeIsDefault() ? endpoint : endpoint + "?pageSize=" + pager.getPageSize();
+ pager.setPrevPage( prevPath );
+ }
+ else
+ {
+ String prevPath = endpoint + "?page=" + (pager.getPage() - 1);
+ prevPath += pager.pageSizeIsDefault() ? "" : "&pageSize=" + pager.getPageSize();
+
+ pager.setPrevPage( prevPath );
+ }
+ }
+ }
+
+ @Override
public <T> void generateLinks( T object )
{
generateLinks( object, contextService.getServletPath() );
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/LinkService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/LinkService.java 2014-05-31 16:27:04 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/LinkService.java 2014-06-17 19:48:34 +0000
@@ -28,17 +28,29 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
+import org.hisp.dhis.common.Pager;
+
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
public interface LinkService
{
/**
+ * Generate next/prev links for Pager class. Needs to know which class we are generating
+ * the pager for, so it can fetch the endpoint.
+ *
+ * @param pager Pager instance to update with prev/next links
+ * @param klass Class type which is paged
+ * @see org.hisp.dhis.common.Pager
+ */
+ void generatePagerLinks( Pager pager, Class<?> klass );
+
+ /**
* Generate HREF and set it using reflection, required a setHref(String) method in your class.
- *
+ * <p/>
* Uses hrefBase from ContextService.getServletPath().
*
- * @param object Object (can be collection) to set HREFs on
+ * @param object Object (can be collection) to set HREFs on
* @see javax.servlet.http.HttpServletRequest
* @see org.hisp.dhis.webapi.utils.ContextService
*/