Commit 870efecc authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Rows per page value is now persistent. JM-326


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1616 b35dd754-fafc-0310-a699-88a17e54d16e
parent bda54180
......@@ -11,26 +11,19 @@
package org.jivesoftware.util;
import org.jivesoftware.messenger.muc.MultiUserChatServer;
import org.jivesoftware.messenger.*;
import org.jivesoftware.messenger.auth.AuthToken;
import org.jivesoftware.messenger.group.GroupManager;
import org.jivesoftware.messenger.muc.MultiUserChatServer;
import org.jivesoftware.messenger.roster.RosterManager;
import org.jivesoftware.messenger.user.User;
import org.jivesoftware.messenger.user.UserManager;
import org.jivesoftware.messenger.roster.RosterManager;
import org.jivesoftware.messenger.XMPPServer;
import org.jivesoftware.messenger.PrivateStorage;
import org.jivesoftware.messenger.PresenceManager;
import org.jivesoftware.messenger.SessionManager;
import org.jivesoftware.messenger.XMPPServerInfo;
import org.jivesoftware.messenger.group.GroupManager;
import java.io.*;
import java.net.URL;
import java.util.LinkedHashMap;
import java.util.Map;
import java.net.URL;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.util.StringTokenizer;
/**
* A utility bean for Messenger admin console pages.
......@@ -285,4 +278,75 @@ public class WebManager extends WebBean {
out.write(buffer, 0, bytesRead);
}
}
/**
* Returns the 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 look up its stored value.
* @param defaultValue the default value to return if no user value was found.
* @return the number of rows per page for the specified page for the current logged user.
*/
public int getRowsPerPage(String pageName, int defaultValue) {
User user = getUser();
if (user != null) {
String values = user.getProperties().get("console.rows_per_page");
if (values != null) {
StringTokenizer tokens = new StringTokenizer(values, ",=");
while (tokens.hasMoreTokens()) {
String page = tokens.nextToken().trim();
String rows = tokens.nextToken().trim();
if (pageName.equals(page)) {
try {
return Integer.parseInt(rows);
}
catch (NumberFormatException e) {
return defaultValue;
}
}
}
}
}
return 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) {
String toStore = pageName + "=" + newValue;
User user = getUser();
if (user != null) {
String values = user.getProperties().get("console.rows_per_page");
if (values != null) {
if (values.contains(toStore)) {
// The new value for the page was already stored so do nothing
return;
}
else {
if (values.contains(pageName)) {
// Replace an old value for the page with the new value
int oldValue = getRowsPerPage(pageName, -1);
String toRemove = pageName + "=" + oldValue;
user.getProperties().put("console.rows_per_page",
values.replace(toRemove, toStore));
}
else {
// Append the new page-value
user.getProperties().put("console.rows_per_page", values + "," + toStore);
}
}
}
else if (values == null) {
// Store the new page-value as a new user property
user.getProperties().put("console.rows_per_page", toStore);
}
}
}
}
\ No newline at end of file
......@@ -34,10 +34,14 @@
<% // Get parameters
int start = ParamUtils.getIntParameter(request,"start",0);
int range = ParamUtils.getIntParameter(request,"range",DEFAULT_RANGE);
int range = ParamUtils.getIntParameter(request,"range",admin.getRowsPerPage("component-session-summary", DEFAULT_RANGE));
boolean close = ParamUtils.getBooleanParameter(request,"close");
String jid = ParamUtils.getParameter(request,"jid");
if (request.getParameter("range") != null) {
admin.setRowsPerPage("component-session-summary", range);
}
// Get the session manager
SessionManager sessionManager = admin.getSessionManager();
......
......@@ -38,7 +38,11 @@
<% // Get parameters
int start = ParamUtils.getIntParameter(request,"start",0);
int range = ParamUtils.getIntParameter(request,"range",15);
int range = ParamUtils.getIntParameter(request,"range",webManager.getRowsPerPage("group-summary", 15));
if (request.getParameter("range") != null) {
webManager.setRowsPerPage("group-summary", range);
}
// Get the user manager
int groupCount = webManager.getGroupManager().getGroupCount();
......
......@@ -36,7 +36,11 @@
<% // Get parameters
int start = ParamUtils.getIntParameter(request,"start",0);
int range = ParamUtils.getIntParameter(request,"range",15);
int range = ParamUtils.getIntParameter(request,"range",webManager.getRowsPerPage("muc-room-summary", 15));
if (request.getParameter("range") != null) {
webManager.setRowsPerPage("muc-room-summary", range);
}
// Get the rooms in the server
List<MUCRoom> rooms = webManager.getMultiUserChatServer().getChatRooms();
......
......@@ -35,10 +35,14 @@
<% // Get parameters
int start = ParamUtils.getIntParameter(request,"start",0);
int range = ParamUtils.getIntParameter(request,"range",DEFAULT_RANGE);
int range = ParamUtils.getIntParameter(request,"range",admin.getRowsPerPage("server-session-summary", DEFAULT_RANGE));
boolean close = ParamUtils.getBooleanParameter(request,"close");
String hostname = ParamUtils.getParameter(request,"hostname");
if (request.getParameter("range") != null) {
admin.setRowsPerPage("server-session-summary", range);
}
// Get the user manager
SessionManager sessionManager = admin.getSessionManager();
......
......@@ -34,12 +34,16 @@
<% // Get parameters
int start = ParamUtils.getIntParameter(request,"start",0);
int range = ParamUtils.getIntParameter(request,"range",DEFAULT_RANGE);
int range = ParamUtils.getIntParameter(request,"range",admin.getRowsPerPage("session-summary", DEFAULT_RANGE));
int refresh = ParamUtils.getIntParameter(request,"refresh",10);
String refreshParam = ParamUtils.getParameter(request,"refresh");
boolean close = ParamUtils.getBooleanParameter(request,"close");
String jid = ParamUtils.getParameter(request,"jid");
if (request.getParameter("range") != null) {
admin.setRowsPerPage("session-summary", range);
}
// Get the user manager
SessionManager sessionManager = admin.getSessionManager();
......
......@@ -27,7 +27,6 @@
<%!
final int DEFAULT_RANGE = 15;
final int[] RANGE_PRESETS = {15, 25, 50, 75, 100};
final String USER_RANGE_PROP = "admin.userlist.range";
%>
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager" />
......@@ -46,30 +45,10 @@
<% // Get parameters
int start = ParamUtils.getIntParameter(request,"start",0);
int range = ParamUtils.getIntParameter(request,"range",DEFAULT_RANGE);
boolean setRange = request.getParameter("range") != null;
if (setRange) {
User user = webManager.getUser();
if (user != null) {
if (range == DEFAULT_RANGE) {
user.getProperties().remove(USER_RANGE_PROP);
}
else {
user.getProperties().put(USER_RANGE_PROP, String.valueOf(range));
}
}
}
int range = ParamUtils.getIntParameter(request,"range",webManager.getRowsPerPage("user-summary", DEFAULT_RANGE));
// Adjust the range based on the user's settings
if (webManager.getUser() != null) {
User user = webManager.getUser();
try {
range = Integer.parseInt(user.getProperties().get(USER_RANGE_PROP));
}
catch (Exception e) {
user.getProperties().remove(USER_RANGE_PROP);
}
if (request.getParameter("range") != null) {
webManager.setRowsPerPage("user-summary", range);
}
// Get the user manager
......
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