dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #15317
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5499: added navigation to paging controls
------------------------------------------------------------
revno: 5499
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-12-20 10:32:10 +0100
message:
added navigation to paging controls
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseCollection.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Pager.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulator.java
dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl
--
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/common/BaseCollection.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseCollection.java 2011-12-19 22:11:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseCollection.java 2011-12-20 09:32:10 +0000
@@ -105,6 +105,11 @@
}
}
+ /**
+ * Get current page.
+ *
+ * @return Current page
+ */
@XmlAttribute
public Integer getPage()
{
@@ -116,6 +121,11 @@
return pager.getPage();
}
+ /**
+ * Total number of items.
+ *
+ * @return number of items in collection
+ */
@XmlAttribute
public Integer getTotal()
{
@@ -127,6 +137,11 @@
return pager.getTotal();
}
+ /**
+ * How many items per page.
+ *
+ * @return items per page
+ */
@XmlAttribute
public Integer getPageSize()
{
@@ -138,6 +153,11 @@
return pager.getPageSize();
}
+ /**
+ * How many pages in total.
+ *
+ * @return total page count
+ */
@XmlAttribute
public Integer getPageCount()
{
@@ -148,4 +168,26 @@
return pager.getPageCount();
}
+
+ @XmlAttribute
+ public String getNextPage()
+ {
+ if ( pager == null )
+ {
+ return null;
+ }
+
+ return pager.getNextPage();
+ }
+
+ @XmlAttribute
+ public String getPrevPage()
+ {
+ if ( pager == null )
+ {
+ return null;
+ }
+
+ return pager.getPrevPage();
+ }
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Pager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Pager.java 2011-12-20 08:33:04 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Pager.java 2011-12-20 09:32:10 +0000
@@ -42,6 +42,10 @@
private int pageSize = Pager.DEFAULT_PAGE_SIZE;
+ private String nextPage;
+
+ private String prevPage;
+
public Pager()
{
@@ -132,4 +136,26 @@
{
return (page * pageSize) - pageSize;
}
+
+ @JsonProperty
+ public String getNextPage()
+ {
+ return nextPage;
+ }
+
+ public void setNextPage( String nextPage )
+ {
+ this.nextPage = nextPage;
+ }
+
+ @JsonProperty
+ public String getPrevPage()
+ {
+ return prevPage;
+ }
+
+ public void setPrevPage( String prevPage )
+ {
+ this.prevPage = prevPage;
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulator.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulator.java 2011-12-19 22:11:19 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulator.java 2011-12-20 09:32:10 +0000
@@ -35,8 +35,8 @@
import org.hisp.dhis.attribute.Attributes;
import org.hisp.dhis.chart.Chart;
import org.hisp.dhis.chart.Charts;
+import org.hisp.dhis.common.BaseCollection;
import org.hisp.dhis.common.BaseIdentifiableObject;
-import org.hisp.dhis.common.BaseLinkableObject;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.LinkableObject;
import org.hisp.dhis.constant.Constant;
@@ -330,6 +330,34 @@
{
populateMessageConversation( (MessageConversation) source, true );
}
+
+ if ( source instanceof BaseCollection )
+ {
+ BaseCollection baseCollection = (BaseCollection) source;
+
+ if ( baseCollection.getPager() != null )
+ {
+ String basePath = getBasePath( source.getClass() );
+
+ if ( baseCollection.getPage() < baseCollection.getPageCount() )
+ {
+ baseCollection.getPager().setNextPage( basePath + "?page=" + (baseCollection.getPage() + 1) );
+ }
+
+ if ( baseCollection.getPage() > 1 )
+ {
+ if ( (baseCollection.getPage() - 1) == 1 )
+ {
+ baseCollection.getPager().setPrevPage( basePath );
+ }
+ else
+ {
+ baseCollection.getPager().setPrevPage( basePath + "?page=" + (baseCollection.getPage() - 1) );
+ }
+
+ }
+ }
+ }
}
private void populateMessageConversations( MessageConversations messageConversations, boolean root )
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl 2011-12-20 08:57:21 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl 2011-12-20 09:32:10 +0000
@@ -19,6 +19,28 @@
<table>
<tr>
<td>Page <xsl:value-of select="@page" /> / <xsl:value-of select="@pageCount" /></td>
+
+ <xsl:if test="@prevPage">
+ <td>
+ <xsl:element name="a">
+ <xsl:attribute name="href">
+ <xsl:value-of select="@prevPage" />
+ </xsl:attribute>
+ <xsl:text>Previous Page</xsl:text>
+ </xsl:element>
+ </td>
+ </xsl:if>
+
+ <xsl:if test="@nextPage">
+ <td>
+ <xsl:element name="a">
+ <xsl:attribute name="href">
+ <xsl:value-of select="@nextPage" />
+ </xsl:attribute>
+ <xsl:text>Next Page</xsl:text>
+ </xsl:element>
+ </td>
+ </xsl:if>
</tr>
</table>
</xsl:when>