Commit cae57a49 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Made refresh value persistent per user.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1619 b35dd754-fafc-0310-a699-88a17e54d16e
parent 4973c4ed
...@@ -289,9 +289,53 @@ public class WebManager extends WebBean { ...@@ -289,9 +289,53 @@ public class WebManager extends WebBean {
* @return the number of rows per page for the specified page for the current logged user. * @return the number of rows per page for the specified page for the current logged user.
*/ */
public int getRowsPerPage(String pageName, int defaultValue) { public int getRowsPerPage(String pageName, int defaultValue) {
return getPageProperty(pageName, "console.rows_per_page", defaultValue);
}
/**
* Sets the new number of rows per page for the specified page for the current logged user.
* The rows per page value is stored as a user property. The same property is being used for
* different pages. The encoding format is the following "pageName1=value,pageName2=value".
*
* @param pageName the name of the page to stored its new value.
* @param newValue the new rows per page value.
*/
public void setRowsPerPage(String pageName, int newValue) {
setPageProperty(pageName, "console.rows_per_page", newValue);
}
/**
* Returns the number of seconds between each page refresh for the specified page for the
* current logged user. The value is stored as a user property. The same property is being
* used for different pages. The encoding format is the following
* "pageName1=value,pageName2=value".
*
* @param pageName the name of the page to look up its stored value.
* @param defaultValue the default value to return if no user value was found.
* @return the number of seconds between each page refresh for the specified page for
* the current logged user.
*/
public int getRefreshValue(String pageName, int defaultValue) {
return getPageProperty(pageName, "console.refresh", defaultValue);
}
/**
* Sets the number of seconds between each page refresh for the specified page for the
* current logged user. The value is stored as a user property. The same property is being
* used for different pages. The encoding format is the following
* "pageName1=value,pageName2=value".
*
* @param pageName the name of the page to stored its new value.
* @param newValue the new number of seconds between each page refresh.
*/
public void setRefreshValue(String pageName, int newValue) {
setPageProperty(pageName, "console.refresh", newValue);
}
private int getPageProperty(String pageName, String property, int defaultValue) {
User user = getUser(); User user = getUser();
if (user != null) { if (user != null) {
String values = user.getProperties().get("console.rows_per_page"); String values = user.getProperties().get(property);
if (values != null) { if (values != null) {
StringTokenizer tokens = new StringTokenizer(values, ",="); StringTokenizer tokens = new StringTokenizer(values, ",=");
while (tokens.hasMoreTokens()) { while (tokens.hasMoreTokens()) {
...@@ -311,19 +355,11 @@ public class WebManager extends WebBean { ...@@ -311,19 +355,11 @@ public class WebManager extends WebBean {
return defaultValue; return defaultValue;
} }
/** public void setPageProperty(String pageName, String property, int newValue) {
* Sets the new number of rows per page for the specified page for the current logged user.
* The rows per page value is stored as a user property. The same property is being used for
* different pages. The encoding format is the following "pageName1=value,pageName2=value".
*
* @param pageName the name of the page to stored its new value.
* @param newValue the new rows per page value.
*/
public void setRowsPerPage(String pageName, int newValue) {
String toStore = pageName + "=" + newValue; String toStore = pageName + "=" + newValue;
User user = getUser(); User user = getUser();
if (user != null) { if (user != null) {
String values = user.getProperties().get("console.rows_per_page"); String values = user.getProperties().get(property);
if (values != null) { if (values != null) {
if (values.contains(toStore)) { if (values.contains(toStore)) {
// The new value for the page was already stored so do nothing // The new value for the page was already stored so do nothing
...@@ -332,20 +368,19 @@ public class WebManager extends WebBean { ...@@ -332,20 +368,19 @@ public class WebManager extends WebBean {
else { else {
if (values.contains(pageName)) { if (values.contains(pageName)) {
// Replace an old value for the page with the new value // Replace an old value for the page with the new value
int oldValue = getRowsPerPage(pageName, -1); int oldValue = getPageProperty(pageName, property, -1);
String toRemove = pageName + "=" + oldValue; String toRemove = pageName + "=" + oldValue;
user.getProperties().put("console.rows_per_page", user.getProperties().put(property, values.replace(toRemove, toStore));
values.replace(toRemove, toStore));
} }
else { else {
// Append the new page-value // Append the new page-value
user.getProperties().put("console.rows_per_page", values + "," + toStore); user.getProperties().put(property, values + "," + toStore);
} }
} }
} }
else if (values == null) { else if (values == null) {
// Store the new page-value as a new user property // Store the new page-value as a new user property
user.getProperties().put("console.rows_per_page", toStore); user.getProperties().put(property, toStore);
} }
} }
} }
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
org.jivesoftware.messenger.*, org.jivesoftware.messenger.*,
java.util.Date, java.util.Date,
org.jivesoftware.admin.*, org.jivesoftware.admin.*,
java.text.DateFormat,
org.xmpp.packet.JID" org.xmpp.packet.JID"
errorPage="error.jsp" errorPage="error.jsp"
%> %>
...@@ -27,7 +26,8 @@ ...@@ -27,7 +26,8 @@
final int DEFAULT_RANGE = 15; final int DEFAULT_RANGE = 15;
final int[] RANGE_PRESETS = {15, 25, 50, 75, 100}; final int[] RANGE_PRESETS = {15, 25, 50, 75, 100};
static final String[] REFRESHES = {NONE,"10","30","60","90"}; static final int[] REFRESHES = {0, 10, 30, 60, 90};
static final String[] REFRESHES_LABELS = {NONE,"10","30","60","90"};
%> %>
<jsp:useBean id="admin" class="org.jivesoftware.util.WebManager" /> <jsp:useBean id="admin" class="org.jivesoftware.util.WebManager" />
<% admin.init(request, response, session, application, out ); %> <% admin.init(request, response, session, application, out ); %>
...@@ -35,8 +35,7 @@ ...@@ -35,8 +35,7 @@
<% // Get parameters <% // Get parameters
int start = ParamUtils.getIntParameter(request,"start",0); int start = ParamUtils.getIntParameter(request,"start",0);
int range = ParamUtils.getIntParameter(request,"range",admin.getRowsPerPage("session-summary", DEFAULT_RANGE)); int range = ParamUtils.getIntParameter(request,"range",admin.getRowsPerPage("session-summary", DEFAULT_RANGE));
int refresh = ParamUtils.getIntParameter(request,"refresh",10); int refresh = ParamUtils.getIntParameter(request,"refresh",admin.getRefreshValue("session-summary", 0));
String refreshParam = ParamUtils.getParameter(request,"refresh");
boolean close = ParamUtils.getBooleanParameter(request,"close"); boolean close = ParamUtils.getBooleanParameter(request,"close");
String jid = ParamUtils.getParameter(request,"jid"); String jid = ParamUtils.getParameter(request,"jid");
...@@ -44,6 +43,10 @@ ...@@ -44,6 +43,10 @@
admin.setRowsPerPage("session-summary", range); admin.setRowsPerPage("session-summary", range);
} }
if (request.getParameter("refresh") != null) {
admin.setRefreshValue("session-summary", refresh);
}
// Get the user manager // Get the user manager
SessionManager sessionManager = admin.getSessionManager(); SessionManager sessionManager = admin.getSessionManager();
...@@ -83,7 +86,7 @@ ...@@ -83,7 +86,7 @@
<jsp:include page="top.jsp" flush="true" /> <jsp:include page="top.jsp" flush="true" />
<jsp:include page="title.jsp" flush="true" /> <jsp:include page="title.jsp" flush="true" />
<% if (refreshParam != null && !NONE.equals(refreshParam)) { %> <% if (refresh > 0) { %>
<meta http-equiv="refresh" content="<%= refresh %>"> <meta http-equiv="refresh" content="<%= refresh %>">
...@@ -142,9 +145,9 @@ ...@@ -142,9 +145,9 @@
<fmt:message key="global.refresh" />: <fmt:message key="global.refresh" />:
<select size="1" name="refresh" onchange="this.form.submit();"> <select size="1" name="refresh" onchange="this.form.submit();">
<% for (int j=0; j<REFRESHES.length; j++) { <% for (int j=0; j<REFRESHES.length; j++) {
String selected = REFRESHES[j].equals(refreshParam)?" selected":""; String selected = REFRESHES[j] == refresh ? " selected" : "";
%> %>
<option value="<%= REFRESHES[j] %>"<%= selected %>><%= REFRESHES[j] %> <option value="<%= REFRESHES[j] %>"<%= selected %>><%= REFRESHES_LABELS[j] %>
<% } %> <% } %>
</select> </select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment