Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
added number of items per page to user and widget admin screen. RAVE-376
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/incubator/rave/trunk@1210742 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
ramindersingh committed Dec 6, 2011
1 parent fb701a1 commit 2a69557
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
Expand Up @@ -20,11 +20,14 @@
package org.apache.rave.portal.web.controller.admin;

import org.apache.rave.portal.model.Authority;
import org.apache.rave.portal.model.PortalPreference;
import org.apache.rave.portal.model.User;
import org.apache.rave.portal.model.util.SearchResult;
import org.apache.rave.portal.service.AuthorityService;
import org.apache.rave.portal.service.PortalPreferenceService;
import org.apache.rave.portal.service.UserService;
import org.apache.rave.portal.web.util.ModelKeys;
import org.apache.rave.portal.web.util.PortalPreferenceKeys;
import org.apache.rave.portal.web.util.ViewNames;
import org.apache.rave.portal.web.validator.UserProfileValidator;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -67,6 +70,9 @@ public class UserController {
@Autowired
private UserProfileValidator userProfileValidator;

@Autowired
private PortalPreferenceService preferenceService;

@InitBinder
public void initBinder(WebDataBinder dataBinder) {
dataBinder.registerCustomEditor(Authority.class, new AuthorityEditor());
Expand All @@ -78,7 +84,7 @@ public String viewUsers(@RequestParam(required = false, defaultValue = "0") int
@RequestParam(required = false) final String action,
Model model) {
addNavigationMenusToModel(SELECTED_ITEM, model);
final SearchResult<User> users = userService.getLimitedListOfUsers(offset, DEFAULT_PAGE_SIZE);
final SearchResult<User> users = userService.getLimitedListOfUsers(offset, getPageSize());
model.addAttribute(ModelKeys.SEARCHRESULT, users);

if (isDeleteOrUpdate(action)) {
Expand All @@ -93,7 +99,7 @@ public String searchUsers(@RequestParam(required = true) String searchTerm,
@RequestParam(required = false, defaultValue = "0") int offset, Model model) {
addNavigationMenusToModel(SELECTED_ITEM, model);
final SearchResult<User> users = userService.getUsersByFreeTextSearch(
searchTerm, offset, DEFAULT_PAGE_SIZE);
searchTerm, offset, getPageSize());
model.addAttribute(ModelKeys.SEARCH_TERM, searchTerm);
model.addAttribute(ModelKeys.SEARCHRESULT, users);
return ViewNames.ADMIN_USERS;
Expand Down Expand Up @@ -180,6 +186,16 @@ public void setAsText(String text) throws IllegalArgumentException {
}

}

public int getPageSize() {
final PortalPreference pageSizePref = preferenceService.getPreference(PortalPreferenceKeys.PAGE_SIZE);
if (pageSizePref == null) {
return DEFAULT_PAGE_SIZE;
}
try {
return Integer.parseInt(pageSizePref.getValue());
} catch (NumberFormatException e) {
return DEFAULT_PAGE_SIZE;
}
}

}
Expand Up @@ -19,11 +19,14 @@

package org.apache.rave.portal.web.controller.admin;

import org.apache.rave.portal.model.PortalPreference;
import org.apache.rave.portal.model.Widget;
import org.apache.rave.portal.model.WidgetStatus;
import org.apache.rave.portal.model.util.SearchResult;
import org.apache.rave.portal.service.PortalPreferenceService;
import org.apache.rave.portal.service.WidgetService;
import org.apache.rave.portal.web.util.ModelKeys;
import org.apache.rave.portal.web.util.PortalPreferenceKeys;
import org.apache.rave.portal.web.util.ViewNames;
import org.apache.rave.portal.web.validator.UpdateWidgetValidator;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -62,6 +65,9 @@ public class WidgetController {
@Autowired
private UpdateWidgetValidator widgetValidator;

@Autowired
private PortalPreferenceService preferenceService;

@InitBinder
public void initBinder(WebDataBinder dataBinder) {
dataBinder.setDisallowedFields("entityId");
Expand All @@ -73,7 +79,7 @@ public String viewWidgets(@RequestParam(required = false, defaultValue = "0") in
Model model) {
addNavigationMenusToModel(SELECTED_ITEM, model);
final SearchResult<Widget> widgets =
widgetService.getLimitedListOfWidgets(offset, DEFAULT_PAGE_SIZE);
widgetService.getLimitedListOfWidgets(offset, getPageSize());
model.addAttribute(ModelKeys.SEARCHRESULT, widgets);

if (isDeleteOrUpdate(action)) {
Expand All @@ -90,7 +96,7 @@ public String searchWidgets(@RequestParam(required = false) String searchTerm,
@RequestParam(required = false, defaultValue = "0") int offset, Model model) {
addNavigationMenusToModel(SELECTED_ITEM, model);
final SearchResult<Widget> widgets = widgetService.getWidgetsBySearchCriteria(searchTerm, widgettype,
widgetstatus, offset, DEFAULT_PAGE_SIZE);
widgetstatus, offset, getPageSize());
model.addAttribute(ModelKeys.SEARCHRESULT, widgets);
model.addAttribute(ModelKeys.SEARCH_TERM, searchTerm);
model.addAttribute("selectedWidgetType", widgettype);
Expand Down Expand Up @@ -138,4 +144,15 @@ void setWidgetValidator(UpdateWidgetValidator widgetValidator) {
this.widgetValidator = widgetValidator;
}

public int getPageSize() {
final PortalPreference pageSizePref = preferenceService.getPreference(PortalPreferenceKeys.PAGE_SIZE);
if (pageSizePref == null) {
return DEFAULT_PAGE_SIZE;
}
try {
return Integer.parseInt(pageSizePref.getValue());
} catch (NumberFormatException e) {
return DEFAULT_PAGE_SIZE;
}
}
}

0 comments on commit 2a69557

Please sign in to comment.