Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

GADGETS-30: Save user based 'currentPageId' in the backend.

  • Loading branch information...
commit de03fe884701a4d5af9897c8c8b3c6ec97434829 1 parent 54a3e41
@jeffyu jeffyu authored
View
10 gadget-core/src/main/java/org/overlord/gadgets/server/model/User.java
@@ -63,8 +63,8 @@
@Column(name="USER_ROLE")
private String role;
- @Transient
- private long currentPageId;
+ @Column(name="CURR_PAGE_ID")
+ private Long currentPageId = new Long(0);
public long getId() {
return id;
@@ -106,11 +106,13 @@ public void setPassword(String password) {
this.password = password;
}
- public long getCurrentPageId() {
+ public Long getCurrentPageId() {
+ if (null == currentPageId)
+ currentPageId = new Long(0);
return currentPageId;
}
- public void setCurrentPageId(long currentPageId) {
+ public void setCurrentPageId(Long currentPageId) {
this.currentPageId = currentPageId;
}
View
4 gadget-web/src/main/java/org/overlord/gadgets/web/client/URLBuilder.java
@@ -55,6 +55,10 @@ public static String getAddPageURL(long userId) {
return urlBase + "rs/users/user/" + userId + "/page";
}
+ public static String updateCurrentPageId(long userId, long pageId) {
+ return urlBase + "rs/users/user/" + userId + "/current/" + pageId;
+ }
+
public static String getStoreURL(int offset, int pageSize) {
return urlBase + "rs/stores/all/" + offset + "/" + pageSize;
}
View
14 gadget-web/src/main/java/org/overlord/gadgets/web/client/widgets/TabLayout.java
@@ -174,16 +174,17 @@ public void clearAllTabs(){
private void setCurrentPage(Long indexId) {
String theIndexId = String.valueOf(indexId);
String pageId = indexIdMap.get(theIndexId);
- currentUser.setCurrentPage(Long.valueOf(pageId));
+ long thePageId = Long.valueOf(pageId).longValue();
+ updateUserCurrentPageId(thePageId);
}
private void removePage(Long indexId) {
String theIndexId = String.valueOf(indexId);
String pageId = indexIdMap.get(theIndexId);
+ indexIdMap.remove(theIndexId);
RestfulInvoker.invoke(RequestBuilder.POST, URLBuilder.getRemovePageURL(Long.valueOf(pageId).longValue()),
null, new RestfulInvoker.Response() {
public void onResponseReceived(Request request, Response response) {
- //TODO:
}
});
}
@@ -192,6 +193,15 @@ public void selectCurrentActiveTab() {
String tabContentId = getTabContentId(String.valueOf(currentUser.getCurrentPage()));
selectTab(id, tabContentId);
}
+
+ private void updateUserCurrentPageId(final long pageId) {
+ RestfulInvoker.invoke(RequestBuilder.POST, URLBuilder.updateCurrentPageId(currentUser.getUserId(), pageId), null,
+ new RestfulInvoker.Response() {
+ public void onResponseReceived(Request arg0, Response arg1) {
+ currentUser.setCurrentPage(pageId);
+ }
+ });
+ }
/**
* JSNI methods
View
16 gadget-web/src/main/java/org/overlord/gadgets/web/server/UserController.java
@@ -83,11 +83,7 @@ public UserModel getUser(User user, @Context HttpServletRequest request){
if (theUser != null) {
userModel.setUserId(theUser.getId());
userModel.setUserName(theUser.getName());
- List<Page> pages = userManager.getPages(theUser.getId());
- //TODO: need to get the currentPageId somehow.
- if (pages != null && pages.size() > 0) {
- userModel.setCurrentPageId(pages.get(0).getId());
- }
+ userModel.setCurrentPageId(theUser.getCurrentPageId());
userModel.setDisplayName(theUser.getDisplayName());
request.getSession().setAttribute("user", userModel);
}
@@ -187,6 +183,16 @@ public Response createPage(@PathParam("userId") long userId, PageModel pageModel
return createJsonResponse(thePage.getId());
}
+ @POST
+ @Path("user/{userId}/current/{pageId}")
+ @Consumes("application/json")
+ public Response updateUserCurrentPageId(@PathParam("userId") long userId, @PathParam("pageId") long pageId) {
+ User theUser = userManager.getUserById(userId);
+ theUser.setCurrentPageId(pageId);
+ userManager.updateUser(theUser);
+ return createJsonResponse(pageId);
+ }
+
private Response createJsonResponse(Object wrapper) {
Gson gson = GsonFactory.createInstance();
Please sign in to comment.
Something went wrong with that request. Please try again.