Author: bbrossaud Date: 2010-05-12 17:38:56 +0200 (Wed, 12 May 2010) New Revision: 23 Url: http://chorem.org/repositories/revision/bow/23 Log: order by name and date work Added: trunk/src/main/webapp/img/asc.png trunk/src/main/webapp/img/desc.png Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java trunk/src/main/webapp/search.jsp Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java =================================================================== --- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-12 13:41:08 UTC (rev 22) +++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-12 15:38:56 UTC (rev 23) @@ -114,6 +114,16 @@ log.debug("Going to actionEditBookmark"); } this.actionEditBookmark(request, response); + } else if (action.equals("orderAsc")) { + if (log.isDebugEnabled()) { + log.debug("Going to actionOrderAsc"); + } + this.actionOrderAsc(request, response); + } else if (action.equals("orderDesc")) { + if (log.isDebugEnabled()) { + log.debug("Going to actionOrderDesc"); + } + this.actionOrderDesc(request, response); } else { user = null; if (log.isDebugEnabled()) { @@ -134,6 +144,57 @@ // } } + + protected void actionOrderAsc(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + String type = request.getParameter("type"); + if (type != null && !type.isEmpty()) { + WikittyProxy proxy = model.getProxy(); + List<Bookmark> bookList = null; + if (type.equals("name")) { + Criteria criteria = Search.query(). + eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(). + addSortAscending(Bookmark.FQ_FIELD_DESCRIPTION); + bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); + } else if (type.equals("date")) { + Criteria criteria = Search.query(). + eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(). + addSortAscending(Bookmark.FQ_FIELD_DATE); + bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); + } + if (bookList != null) { + bookmarkActions.setBookmarks(bookList); + bookmarkActions.createTagsCloud(); + } + } + request.getRequestDispatcher("search.jsp").forward(request, response); + } + + protected void actionOrderDesc(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + String type = request.getParameter("type"); + if (type != null && !type.isEmpty()) { + WikittyProxy proxy = model.getProxy(); + List<Bookmark> bookList = null; + if (type.equals("name")) { + Criteria criteria = Search.query(). + eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(). + addSortDescending(Bookmark.FQ_FIELD_DESCRIPTION); + bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); + } else if (type.equals("date")) { + Criteria criteria = Search.query(). + eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(). + addSortDescending(Bookmark.FQ_FIELD_DATE); + bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); + } + if (bookList != null) { + bookmarkActions.setBookmarks(bookList); + bookmarkActions.createTagsCloud(); + } + } + request.getRequestDispatcher("search.jsp").forward(request, response); + } + protected void actionEditBookmark(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String nameAndTags = request.getParameter("nameAndTags"); @@ -145,7 +206,6 @@ if (bookmark != null) { bookmarkActions.updateBookmark(bookmark, nameAndTags); proxy.store(bookmark); - bookmarkActions.getBookmarks().clear(); Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(); List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user if (bookList != null) { @@ -164,7 +224,6 @@ if (bookmarkId != null && !bookmarkId.isEmpty()) { WikittyProxy proxy = model.getProxy(); proxy.delete(bookmarkId); - bookmarkActions.getBookmarks().clear(); Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(); List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user if (bookList != null) { @@ -186,7 +245,6 @@ if (bookmark != null) { bookmark.removeTags(tag); proxy.store(bookmark); - bookmarkActions.getBookmarks().clear(); Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(); List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user if (bookList != null) { @@ -283,7 +341,6 @@ throws IOException, ServletException { WikittyProxy proxy = model.getProxy(); String tag = request.getParameter("tag"); - bookmarkActions.getBookmarks().clear(); bookmarkActions.getTagsCloud().clear(); Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(); List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user Added: trunk/src/main/webapp/img/asc.png =================================================================== (Binary files differ) Property changes on: trunk/src/main/webapp/img/asc.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/src/main/webapp/img/desc.png =================================================================== (Binary files differ) Property changes on: trunk/src/main/webapp/img/desc.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/src/main/webapp/search.jsp =================================================================== --- trunk/src/main/webapp/search.jsp 2010-05-12 13:41:08 UTC (rev 22) +++ trunk/src/main/webapp/search.jsp 2010-05-12 15:38:56 UTC (rev 23) @@ -41,39 +41,79 @@ } List<String> tagsSearch = bookmarkActions.getTagsSearch(); List<Bookmark> bookmarkList = bookmarkActions.getBookmarks(); - if (!bookmarkList.isEmpty() && !tagsSearch.isEmpty()) { + if (!bookmarkList.isEmpty()) { %> <br/><br/>Results:<br/> + <table border="1"> + <tr> + <th>Remove</th> + <th> + Date + <a style="text-decoration:none" href="bow?action=orderAsc&type=date"> + <IMG style="border:none" SRC="img/asc.png" ALT="order ASC" TITLE="Asc" /> + </a> + <a style="text-decoration:none" href="bow?action=orderDesc&type=date"> + <IMG style="border:none" SRC="img/desc.png" ALT="order DESC" TITLE="Desc" /> + </a> + </th> + <th> + Name + <a style="text-decoration:none" href="bow?action=orderAsc&type=name"> + <IMG style="border:none" SRC="img/asc.png" ALT="order ASC" TITLE="Asc" /> + </a> + <a style="text-decoration:none" href="bow?action=orderDesc&type=name"> + <IMG style="border:none" SRC="img/desc.png" ALT="order DESC" TITLE="Desc" /> + </a> + </th> + <th>Tags</th> + <th>Edit</th> + </tr> + <% + for (Bookmark bookmark : bookmarkList) { + %> + <tr> + <td> + <a style="border:none;" href="bow?action=removeBookmark&bookmarkId=<%=bookmark.getWikittyId()%>"> + <IMG style="border:none;" SRC="img/remove.png" ALT="Remove bookmark" TITLE="Remove" /> + </a> + </td> + <td> + <%=bookmark.getDate()%> + </td> + <td> + <a href="<%=bookmark.getLink()%>"><%=bookmark.getDescription()%></a> + </td> + <td> + <% + Set<String> tagList = bookmark.getTags(); + if (tagList != null && !tagList.isEmpty()) { + for (String tag : tagList) { + %> + <%=tag%> + <a style="text-decoration:none" href="bow?action=deleteTag&bookmarkId=<%=bookmark.getWikittyId()%>&tag=<%=tag%>"> + <IMG style="border:none" SRC="img/delete.png" ALT="Delete tag" TITLE="Delete" /> + </a> + <% + } + %> + </td> + <td> + <form style="display: inline" method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>"> + <input type="text" name="nameAndTags" size="50" value="<%=bookmark.getDescription()%>|tag1 tag2 tag3" /> + <input type="image" src="img/edit.png" value="edit" /> + </form> + </td> + <% + } + %> + <% + } + %> + </table> <% - for (Bookmark bookmark : bookmarkList) { + } else { %> - <br/> - <a style="border:none;" href="bow?action=removeBookmark&bookmarkId=<%=bookmark.getWikittyId()%>"> - <IMG style="border:none;" SRC="img/remove.png" ALT="Remove bookmark" TITLE="Remove" /> - </a> - <a href="<%=bookmark.getLink()%>"><%=bookmark.getDescription()%></a> - <% - Set<String> tagList = bookmark.getTags(); - if (tagList != null && !tagList.isEmpty()) { - for (String tag : tagList) { - %> - <%=tag%> - <a style="text-decoration:none" href="bow?action=deleteTag&bookmarkId=<%=bookmark.getWikittyId()%>&tag=<%=tag%>"> - <IMG style="border:none" SRC="img/delete.png" ALT="Delete tag" TITLE="Delete" /> - </a> - <% - } - %> - <form style="display: inline" method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>"> - <input type="text" name="nameAndTags" size="50" value="<%=bookmark.getDescription()%>|tag1 tag2 tag3" /> - <input type="image" src="img/edit.png" value="edit" /> - </form> - <% - } - } - } else if (!tagsSearch.isEmpty() && bookmarkList.isEmpty()) { - %> - <br/><br/>No Result found<br/><br/> + <br/><br/>No Bookmarks<br/><br/> <% } } %>