dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #11166
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3148: minor fixes to cookie-based pageSize implementation
------------------------------------------------------------
revno: 3148
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-03-24 09:59:43 +0100
message:
minor fixes to cookie-based pageSize implementation
modified:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/ContextUtils.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-commons-resources/src/main/webapp/main.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm 2011-03-23 21:30:01 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm 2011-03-24 08:59:43 +0000
@@ -47,6 +47,14 @@
<script type="text/javascript" src="$javascript"></script>
#end
+ <script type="text/javascript">
+ jQuery(document).ready(function() {
+ jQuery("#menuLink4").click( function() {
+ jQuery.cookie('pageSize', null, {path:'/'});
+ window.location.href='../dhis-web-commons-security/logout.action';
+ });
+ });
+ </script>
</head>
<body>
@@ -67,7 +75,7 @@
<div id="menuLink1" class="menuLink" #if ( $maintenanceModules.size() > 0 ) onmouseover="showDropDown( 'menuDropDown1' )" onmouseout="hideDropDownTimeout()" #end>$i18n.getString( "maintenance" )</div>
<div id="menuLink2" class="menuLink" #if ( $serviceModules.size() > 0 ) onmouseover="showDropDown( 'menuDropDown2' )" onmouseout="hideDropDownTimeout()" #end>$i18n.getString( "services" )</div>
<div id="menuLink3" class="menuLink" onmouseover="showDropDown( 'menuDropDown3' )" onmouseout="hideDropDownTimeout()">$i18n.getString( "help" )</div>
- <div id="menuLink4" class="menuLink" onclick="jQuery.cookie('pageSize', null, {path:'/'}); window.location.href='../dhis-web-commons-security/logout.action'">$i18n.getString( "log_out" )</div>
+ <div id="menuLink4" class="menuLink">$i18n.getString( "log_out" )</div>
<div id="menuDropDown1" class="menuDropDownArea" onmouseover="cancelHideDropDownTimeout()" onmouseout="hideDropDownTimeout()">
<ul class="menuDropDownBox">
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java 2011-03-23 21:30:01 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java 2011-03-24 08:59:43 +0000
@@ -35,6 +35,7 @@
import org.apache.struts2.ServletActionContext;
import org.hisp.dhis.system.paging.Paging;
+import org.hisp.dhis.util.ContextUtils;
import com.opensymphony.xwork2.ActionSupport;
@@ -79,20 +80,18 @@
this.usePaging = usePaging;
}
- protected Integer getDefaultPageSize() {
- HttpServletRequest request = ServletActionContext.getRequest();
- Cookie[] cookies = request.getCookies();
+ protected Integer getDefaultPageSize()
+ {
+ String sessionPageSize = ContextUtils.getCookieValue( ServletActionContext.getRequest(), "pageSize" );
- /* Get default based on cookie, if it exists */
- for(Cookie c : cookies) {
- if(c.getName().equalsIgnoreCase( "pageSize" )) {
- return Integer.valueOf( c.getValue() );
- }
+ if ( sessionPageSize != null )
+ {
+ return Integer.valueOf( sessionPageSize );
}
-
+
return DEFAULT_PAGE_SIZE;
}
-
+
@SuppressWarnings( "unchecked" )
private String getCurrentLink()
{
@@ -129,9 +128,9 @@
protected List<T> getBlockElement( List<T> elementList, int startPos, int pageSize )
{
List<T> returnList;
-
+
int endPos = paging.getEndPos();
-
+
returnList = elementList.subList( startPos, endPos );
return returnList;
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/ContextUtils.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/ContextUtils.java 2011-03-08 01:55:01 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/ContextUtils.java 2011-03-24 08:59:43 +0000
@@ -31,6 +31,7 @@
import java.util.HashMap;
import java.util.Map;
+import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -43,83 +44,112 @@
public class ContextUtils
{
public static final String CONTENT_TYPE_PDF = "application/pdf";
+
public static final String CONTENT_TYPE_ZIP = "application/zip";
+
public static final String CONTENT_TYPE_JSON = "application/json";
+
public static final String CONTENT_TYPE_HTML = "text/html";
+
public static final String CONTENT_TYPE_TEXT = "text/plain";
+
public static final String CONTENT_TYPE_XML = "application/xml";
+
public static final String CONTENT_TYPE_CSV = "application/csv";
+
public static final String CONTENT_TYPE_PNG = "image/png";
+
public static final String CONTENT_TYPE_EXCEL = "application/vnd.ms-excel";
-
+
private static final String SEPARATOR = "/";
- private static final String PORT_SEPARATOR = ":";
+
+ private static final String PORT_SEPARATOR = ":";
+
private static final String PROTOCOL = "http://";
-
- private static final Map<String, String> CONTENT_TYPE_MAP = new HashMap<String, String>() { {
- put( "pdf", CONTENT_TYPE_PDF );
- put( "zip", CONTENT_TYPE_ZIP );
- put( "json", CONTENT_TYPE_JSON );
- put( "html", CONTENT_TYPE_HTML );
- put( "txt", CONTENT_TYPE_TEXT );
- put( "xml", CONTENT_TYPE_XML );
- put( "csv", CONTENT_TYPE_CSV );
- put( "png", CONTENT_TYPE_PNG );
- put( "xls", CONTENT_TYPE_EXCEL );
- } };
-
+
+ private static final Map<String, String> CONTENT_TYPE_MAP = new HashMap<String, String>()
+ {
+ {
+ put( "pdf", CONTENT_TYPE_PDF );
+ put( "zip", CONTENT_TYPE_ZIP );
+ put( "json", CONTENT_TYPE_JSON );
+ put( "html", CONTENT_TYPE_HTML );
+ put( "txt", CONTENT_TYPE_TEXT );
+ put( "xml", CONTENT_TYPE_XML );
+ put( "csv", CONTENT_TYPE_CSV );
+ put( "png", CONTENT_TYPE_PNG );
+ put( "xls", CONTENT_TYPE_EXCEL );
+ }
+ };
+
public static String getContentType( String type, String defaultType )
{
String contentType = CONTENT_TYPE_MAP.get( type );
return contentType != null ? contentType : defaultType;
}
-
+
@SuppressWarnings( "unchecked" )
public static Map<String, String> getParameterMap( HttpServletRequest request )
{
Enumeration<String> enumeration = request.getParameterNames();
-
+
Map<String, String> params = new HashMap<String, String>();
-
+
while ( enumeration.hasMoreElements() )
{
String name = enumeration.nextElement();
-
+
params.put( name, request.getParameter( name ) );
}
-
+
return params;
}
-
+
public static String getBaseUrl( HttpServletRequest request )
{
String server = request.getServerName();
-
+
int port = request.getServerPort();
-
+
String baseUrl = PROTOCOL + server + PORT_SEPARATOR + port + SEPARATOR;
-
+
return baseUrl;
}
-
- public static void configureResponse( HttpServletResponse response, String contentType, boolean disallowCache, String filename, boolean attachment )
+
+ public static void configureResponse( HttpServletResponse response, String contentType, boolean disallowCache,
+ String filename, boolean attachment )
{
if ( contentType != null )
{
response.setContentType( contentType );
}
-
+
if ( disallowCache )
- {
+ {
response.addHeader( "Cache-Control", "no-cache" );
response.addHeader( "Expires", DateUtils.getExpiredHttpDateString() );
- }
+ }
if ( filename != null )
{
String type = attachment ? "attachment" : "inline";
-
+
response.addHeader( "Content-Disposition", type + "; filename=\"" + filename + "\"" );
}
}
+
+ public static String getCookieValue( HttpServletRequest request, String cookieName )
+ {
+ Cookie[] cookies = request.getCookies();
+
+ for ( Cookie c : cookies )
+ {
+ if ( c.getName().equalsIgnoreCase( "pageSize" ) )
+ {
+ return c.getValue();
+ }
+ }
+
+ return null;
+ }
}