changeset 32:74fe1518bc5c

new: sorting and filters in homepage for branch list
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Fri, 25 Sep 2015 14:30:46 +0200
parents c8d367a4bbcd
children 5520f941f6cb
files src/main/java/de/mpiwg/web/jsp/HomePage.java src/main/java/de/mpiwg/web/jsp/JSPProxy.java src/main/webapp/pages/books.jsp src/main/webapp/pages/home.jsp
diffstat 4 files changed, 557 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/web/jsp/HomePage.java	Thu Sep 24 13:35:39 2015 +0200
+++ b/src/main/java/de/mpiwg/web/jsp/HomePage.java	Fri Sep 25 14:30:46 2015 +0200
@@ -1,6 +1,7 @@
 package de.mpiwg.web.jsp;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
@@ -12,8 +13,33 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 import de.mpiwg.gazetteer.bo.LGBranch;
+import de.mpiwg.gazetteer.db.DBBook;
+import de.mpiwg.gazetteer.utils.DBService;
 import de.mpiwg.gazetteer.utils.DataProvider;
+import de.mpiwg.web.books.SortBooksByBookId;
+import de.mpiwg.web.branch.SortBranchByBookName;
+import de.mpiwg.web.branch.SortBranchByBranchId;
+import de.mpiwg.web.branch.SortBranchByLabel;
+import de.mpiwg.web.branch.SortBranchByLastModified;
+import de.mpiwg.web.branch.SortBranchByPeriod;
+import de.mpiwg.web.branch.SortBranchBySectionName;
 
 public class HomePage  extends AbstractJSPPage{
 	
@@ -23,22 +49,56 @@
 	public static String page = "pages/home.jsp";
 	
 	
-	private List<LGBranch> branches;
+	private List<LGBranch> completeBranchList;	// complete branch list
 	private Long branchId;
 	
+	private List<LGBranch> filteredBranchList;
+
+	private List<LGBranch> displayBranchList;
+	
+	private String bookNameFilter = new String();
+	private String bookIdFilter = new String();
+	private String periodFilter = new String();
+	private String sectionNameFilter = new String();
+	private String labelFilter = new String();
+
+	
+	
+	private int branchNumber;
+	
+	private String filteringMessage;
+
+	private DataPaginator paginator = new DataPaginator();
+
 	
 	public void loadParameters(HttpServletRequest request, HttpServletResponse response){
 		this.request = request;
 		this.response = response;
 		
 		this.branchId = getLongParameter("branchId");
+		this.bookIdFilter = getParameter("bookIdFilter");
+		this.bookNameFilter = getParameter("bookNameFilter");
+		this.periodFilter = getParameter("periodFilter");
+		this.sectionNameFilter = getParameter("sectionNameFilter");
+		this.labelFilter = getParameter("labelFilter");
+		
 	}
 	
+	
 	public void reloadBranches(){
+		logger.debug("reloadBranches");
+		if (this.completeBranchList == null) {
+			this.forceLoadBranches();
+			this.filteringMessage = null;
+		}
+		return;
+	}
+	
+	
+	public void forceLoadBranches(){
+		logger.debug("forceLoadBranches");
 		
-		logger.debug("reloadBranches");
-		
-		this.branches = new ArrayList<LGBranch>();
+		this.completeBranchList = new ArrayList<LGBranch>();
 		if(getSessionBean().getUser() != null){
 			for(LGBranch branch : DataProvider.getInstance().getBranches(getSessionBean().getUser().getId())){
 				branch.loadTransientData();
@@ -47,14 +107,18 @@
 				if (branch.isEmpty()) {
 					logger.debug("section of the branch doesn't exist anymore.");
 				} else {
-					this.branches.add(branch);
+					this.completeBranchList.add(branch);
 				}
 			}	
 		}
+		this.setBranchNumber(this.completeBranchList.size());
+		
+		sortByLastModifiedDown();	// default sorting by from lasted modified to oldest
+		
+		
 	}
 	
 	public void deleteBranch(){
-		
 		logger.debug("deleteBranch " + branchId);
 		
 		if(branchId != null){
@@ -66,20 +130,237 @@
 		}
 	}
 	
-	public List<LGBranch> getBranches() {
-		return branches;
+	
+
+
+
+	public List<LGBranch> getFilteredBranchList() {
+		return filteredBranchList;
+	}
+
+
+	public void setFilteredBranchList(List<LGBranch> filteredBranchList) {
+		this.filteredBranchList = filteredBranchList;
 	}
 
 
-	public void setBranches(List<LGBranch> branches) {
-		this.branches = branches;
+	public List<LGBranch> getDisplayBranchList() {
+		return displayBranchList;
+	}
+
+
+	public void setDisplayBranchList(List<LGBranch> displayBranchList) {
+		this.displayBranchList = displayBranchList;
 	}
 
+
+	public List<LGBranch> getCompleteBranchList() {
+		return completeBranchList;
+	}
+
+
+	public void setCompleteBranchList(List<LGBranch> completeBranchList) {
+		this.completeBranchList = completeBranchList;
+	}
+
+
 	public Long getBranchId() {
 		return branchId;
 	}
 
 	public void setBranchId(Long branchId) {
 		this.branchId = branchId;
-	}	
+	}
+
+
+	public String getPeriodFilter() {
+		return periodFilter;
+	}
+
+
+	public void setPeriodFilter(String periodFilter) {
+		this.periodFilter = periodFilter;
+	}
+
+
+	public String getSectionNameFilter() {
+		return sectionNameFilter;
+	}
+
+
+	public void setSectionNameFilter(String sectionNameFilter) {
+		this.sectionNameFilter = sectionNameFilter;
+	}
+
+
+	public List<LGBranch> getFilteredBranches() {
+		return filteredBranchList;
+	}
+
+
+	public void setFilteredBranches(List<LGBranch> filteredBranches) {
+		this.filteredBranchList = filteredBranches;
+	}
+
+
+	public String getBookNameFilter() {
+		return bookNameFilter;
+	}
+
+
+	public void setBookNameFilter(String bookNameFilter) {
+		this.bookNameFilter = bookNameFilter;
+	}
+
+	public String getBookIdFilter() {
+		return bookIdFilter;
+	}
+
+
+	public void setBookIdFilter(String bookIdFilter) {
+		this.bookIdFilter = bookIdFilter;
+	}
+
+
+	private void updateCurrentBranches() {
+		this.displayBranchList = this.filteredBranchList;
+		
+	}
+
+	public void filter(){
+		this.filteredBranchList = new ArrayList<LGBranch>();
+		for (LGBranch branch : this.completeBranchList) {
+			if(!this.filteredBranchList.contains(branch)){
+				if( (StringUtils.isEmpty(bookNameFilter) || StringUtils.startsWith(branch.getBook().getName(), bookNameFilter)) &&
+					(StringUtils.isEmpty(bookIdFilter) || StringUtils.startsWith(branch.getBook().getId(), bookIdFilter)) &&
+					(StringUtils.isEmpty(periodFilter) || StringUtils.startsWith(branch.getBook().getPeriod(), periodFilter)) &&
+					(StringUtils.isEmpty(sectionNameFilter) || StringUtils.startsWith(branch.getSection().getName(), sectionNameFilter)) &&
+					(StringUtils.isEmpty(labelFilter) || StringUtils.startsWith(branch.getLabel(), labelFilter))
+					){
+
+					this.filteredBranchList.add(branch);
+					
+				}
+			}
+		}
+		
+		if(completeBranchList.size() > 0){
+			this.filteringMessage = this.filteredBranchList.size() + " branches listed after filtering";
+			this.paginator.setCurrentPage(0);
+			this.paginator.resetNumberOfPages(filteredBranchList.size());
+			this.updateCurrentBranches();
+			
+		}else{
+			this.filteredBranchList = null;
+		}
+	
+	}
+	
+	public void sortByBranchIdUp() {
+		Collections.sort(this.completeBranchList, new SortBranchByBranchId());
+		filter();
+	}
+
+	public void sortByBranchIdDown() {
+		Collections.sort(this.completeBranchList, new SortBranchByBranchId());
+		Collections.reverse(this.completeBranchList);
+		filter();
+	}
+
+	
+	public void sortByBookNameUp() {
+		Collections.sort(this.completeBranchList, new SortBranchByBookName());
+		filter();
+	}
+
+	public void sortByBookNameDown() {
+		Collections.sort(this.completeBranchList, new SortBranchByBookName());
+		Collections.reverse(this.completeBranchList);
+		filter();
+	}
+	public void sortByPeriodUp() {
+		Collections.sort(this.completeBranchList, new SortBranchByPeriod());
+		filter();
+	}
+
+	public void sortByPeriodDown() {
+		Collections.sort(this.completeBranchList, new SortBranchByPeriod());
+		Collections.reverse(this.completeBranchList);
+		filter();
+	}
+	public void sortBySectionNameUp() {
+		Collections.sort(this.completeBranchList, new SortBranchBySectionName());
+		filter();
+	}
+
+	public void sortBySectionNameDown() {
+		Collections.sort(this.completeBranchList, new SortBranchBySectionName());
+		Collections.reverse(this.completeBranchList);
+		filter();
+	}
+	public void sortByLabelUp() {
+		Collections.sort(this.completeBranchList, new SortBranchByLabel());
+		filter();
+	}
+
+	public void sortByLabelDown() {
+		Collections.sort(this.completeBranchList, new SortBranchByLabel());
+		Collections.reverse(this.completeBranchList);
+		filter();
+	}
+	public void sortByLastModifiedUp() {
+		Collections.sort(this.completeBranchList, new SortBranchByLastModified());
+		filter();
+	}
+
+	public void sortByLastModifiedDown() {
+		Collections.sort(this.completeBranchList, new SortBranchByLastModified());
+		Collections.reverse(this.completeBranchList);
+		filter();
+	}
+
+
+	public int getBranchNumber() {
+		return branchNumber;
+	}
+
+
+	public void setBranchNumber(int branchNumber) {
+		this.branchNumber = branchNumber;
+	}
+
+
+	public String getFilteringMessage() {
+		return filteringMessage;
+	}
+
+
+	public void setFilteringMessage(String filteringMessage) {
+		this.filteringMessage = filteringMessage;
+	}
+
+
+	public String getLabelFilter() {
+		return labelFilter;
+	}
+
+
+	public void setLabelFilter(String labelFilter) {
+		this.labelFilter = labelFilter;
+	}
+
+
+	public DataPaginator getPaginator() {
+		return paginator;
+	}
+
+
+	public void setPaginator(DataPaginator paginator) {
+		this.paginator = paginator;
+	}
+
+
+	
+	
+	
 }
--- a/src/main/java/de/mpiwg/web/jsp/JSPProxy.java	Thu Sep 24 13:35:39 2015 +0200
+++ b/src/main/java/de/mpiwg/web/jsp/JSPProxy.java	Fri Sep 25 14:30:46 2015 +0200
@@ -64,8 +64,39 @@
 				
 				if(StringUtils.equals(action, "deleteBranch")){
 					getSessionBean().getHomePage().deleteBranch();
-				}else if(StringUtils.equals(action, "reloadBranches")){
+				} else if(StringUtils.equals(action, "reloadBranches")){
 					getSessionBean().getHomePage().reloadBranches();
+				} 
+				// zoe add for sorting in home page, which shows user's branches
+				else if (StringUtils.equals(action, "forceReloadBranches")) {
+					getSessionBean().getHomePage().forceLoadBranches();;		
+				} else if(StringUtils.equals(action, "filter")){
+					getSessionBean().getHomePage().filter();
+				}
+				 else if(StringUtils.equals(action, "sortByBranchIdUp")) {
+					getSessionBean().getHomePage().sortByBranchIdUp();
+				} else if(StringUtils.equals(action, "sortByBranchIdDown")) {
+					getSessionBean().getHomePage().sortByBranchIdDown();
+				} else if(StringUtils.equals(action, "sortByBookNameUp")) {
+					getSessionBean().getHomePage().sortByBookNameUp();
+				} else if(StringUtils.equals(action, "sortByBookNameDown")) {
+					getSessionBean().getHomePage().sortByBookNameDown();
+				} else if(StringUtils.equals(action, "sortByPeriodUp")) {
+					getSessionBean().getHomePage().sortByPeriodUp();
+				} else if(StringUtils.equals(action, "sortByPeriodDown")) {
+					getSessionBean().getHomePage().sortByPeriodDown();
+				} else if(StringUtils.equals(action, "sortBySectionNameUp")) {
+					getSessionBean().getHomePage().sortBySectionNameUp();
+				} else if(StringUtils.equals(action, "sortBySectionNameDown")) {
+					getSessionBean().getHomePage().sortBySectionNameDown();
+				} else if(StringUtils.equals(action, "sortByLabelUp")) {
+					getSessionBean().getHomePage().sortByLabelUp();
+				} else if(StringUtils.equals(action, "sortByLabelDown")) {
+					getSessionBean().getHomePage().sortByLabelDown();
+				} else if(StringUtils.equals(action, "sortByLastModifiedUp")) {
+					getSessionBean().getHomePage().sortByLastModifiedUp();
+				} else if(StringUtils.equals(action, "sortByLastModifiedDown")) {
+					getSessionBean().getHomePage().sortByLastModifiedDown();
 				}
 				
 				return HomePage.page;
--- a/src/main/webapp/pages/books.jsp	Thu Sep 24 13:35:39 2015 +0200
+++ b/src/main/webapp/pages/books.jsp	Fri Sep 25 14:30:46 2015 +0200
@@ -53,7 +53,7 @@
 					onclick="setAction('forceReloadBooks', 'booksForm');"
 			src="<%=sessionBean.getApplicationBean().getRefreshImage()%>" width="20" height="20"/>
 			
-			<p class="label"><%= sessionBean.getBooksPage().getBookNumber() %> books in Chinese localgazetteers</p>
+			<p class="label"><%= sessionBean.getBooksPage().getBookNumber() %> books in Chinese Local Gazetteers </p>
 			<p class="label"><%= (StringUtils.isNotEmpty(sessionBean.getBooksPage().getFilteringMessage())) ? sessionBean.getBooksPage().getFilteringMessage() : ""%> </p>
 		</div>
 		
--- a/src/main/webapp/pages/home.jsp	Thu Sep 24 13:35:39 2015 +0200
+++ b/src/main/webapp/pages/home.jsp	Fri Sep 25 14:30:46 2015 +0200
@@ -20,39 +20,251 @@
 		<% if(sessionBean.getUser() == null) { %>
 			<label>You must login!</label>
 		<% } else { 
+			
+			if (sessionBean.getHomePage().getCompleteBranchList() == null){ 
+				sessionBean.getHomePage().loadParameters(request, response);
+				sessionBean.getHomePage().reloadBranches();
+			}
+			/*
 			sessionBean.getHomePage().loadParameters(request, response);
 			sessionBean.getHomePage().reloadBranches();
+			*/
 		%>
-		<label class="subTitel">User's Branches</label>
+		
 		
-		<% if(sessionBean.getHomePage().getBranches().isEmpty()) { %>
-			<label>You do not have branches!</label>
+		
+		
+		<% if(sessionBean.getHomePage().getCompleteBranchList().isEmpty()) { %>
+			<label class="subTitel">You have no branch!</label>
 		<% } else { %>
 				
-			<form
-				name="homeForm"
-				action="<%=sessionBean.getApplicationBean().getRootServer()%>/proxy.jsp"
-				method="post">
+			<form name="homeForm" method="post"
+				action="<%=sessionBean.getApplicationBean().getRootServer()%>/proxy.jsp" >
+				<input name="bean" type="hidden" value="homeBean" /> 
 				
-				<input name="bean" type="hidden" value="homeBean" /> 
+				<div class="subTitel">User's Branches
+					<input type="image"
+						onclick="setAction('forceReloadBranches', 'homeForm');"
+						src="<%=sessionBean.getApplicationBean().getRefreshImage()%>" width="20" height="20"/>
+			
+					<p class="label">You have <%= sessionBean.getHomePage().getBranchNumber() %> branches.</p>
+					<p class="label"><%= (StringUtils.isNotEmpty(sessionBean.getHomePage().getFilteringMessage())) ? sessionBean.getHomePage().getFilteringMessage() : ""%> </p>
+				</div>
+				<jsp:include page="../componentes/paginator.jsp">
+					<jsp:param name="formName" value="homeForm"/>
+				</jsp:include> 
+				
 				
 				<table style="width: 90%; margin-left: auto;margin-right: auto;"  class="pageTable">
 					<tr>
-						<td><label class="tableTitle">Branch ID</label></td>
-						<td><label class="tableTitle">Book ID</label></td>
-						<td><label class="tableTitle">Book Name</label></td>
-						<td><label class="tableTitle">Period</label></td>
-						<td><label class="tableTitle">Section Name</label></td>
-						<td><label class="tableTitle">Label</label></td>
+						<td>
+							<table class="sortTable">
+								<tr>
+									<td><label class="tableTitle">Branch ID</label></td>
+									<td>
+										<table>
+											<tr><td>
+												<input type="image" 
+													onclick="setAction('sortByBranchIdUp', 'homeForm');"
+													src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
+											</td></tr>
+											<tr><td>
+												<input type="image"
+													onclick="setAction('sortByBranchIdDown', 'homeForm');"
+													src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
+											</td></tr>
+										</table>
+									</td>
+								</tr>
+							</table>
+						</td>
+						
+						<td>
+							<table class="sortTable">
+								<tr>
+									<td><label class="tableTitle">Book ID</label></td>
+									<td>
+										<table>
+											<tr><td>
+												<input type="image" 
+													onclick="setAction('sortByBookIdUp', 'homeForm');"
+													src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
+											</td></tr>
+											<tr><td>
+												<input type="image"
+													onclick="setAction('sortByBookIdDown', 'homeForm');"
+													src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
+											</td></tr>
+										</table>
+									</td>
+								</tr>
+								<tr>
+									<td>
+										<input type="text" name="bookIdFilter" value="<%= sessionBean.getHomePage().getBookIdFilter()%>" size="10"/>
+									</td>									
+									<td>
+										<input type="image"
+											onclick="setAction('filter', 'homeForm');"
+											src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
+									</td>							
+								</tr>
+							</table>
+						</td>
+						<td>
+							<table class="sortTable">
+								<tr>
+									<td><label class="tableTitle">Book Name</label></td>
+									<td>
+										<table>
+											<tr><td>
+												<input type="image" 
+													onclick="setAction('sortByBookNameUp', 'homeForm');"
+													src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
+											</td></tr>
+											<tr><td>
+												<input type="image"
+													onclick="setAction('sortByBookNameDown', 'homeForm');"
+													src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
+											</td></tr>
+										</table>
+									</td>
+								</tr>
+								<tr>
+									<td>
+										<input type="text" name="bookNameFilter" value="<%= sessionBean.getHomePage().getBookNameFilter()%>" size="10"/>
+									</td>									
+									<td>
+										<input type="image"
+											onclick="setAction('filter', 'homeForm');"
+											src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
+									</td>							
+								</tr>
+							</table>
+						</td>
+						<td>
+							<table class="sortTable">
+								<tr>
+									<td><label class="tableTitle">Period</label></td>
+									<td>
+										<table>
+											<tr><td>
+												<input type="image" 
+													onclick="setAction('sortByPeriodUp', 'homeForm');"
+													src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
+											</td></tr>
+											<tr><td>
+												<input type="image"
+													onclick="setAction('sortByPeriodDown', 'homeForm');"
+													src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
+											</td></tr>
+										</table>
+									</td>
+								</tr>
+								<tr>
+									<td>
+										<input type="text" name="periodFilter" value="<%= sessionBean.getHomePage().getPeriodFilter()%>" size="10"/>
+									</td>									
+									<td>
+										<input type="image"
+											onclick="setAction('filter', 'homeForm');"
+											src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
+									</td>							
+								</tr>
+							</table>
+						</td>
+						<td>
+							<table class="sortTable">
+								<tr>
+									<td><label class="tableTitle">Section Name</label></td>
+									<td>
+										<table>
+											<tr><td>
+												<input type="image" 
+													onclick="setAction('sortBySectionNameUp', 'homeForm');"
+													src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
+											</td></tr>
+											<tr><td>
+												<input type="image"
+													onclick="setAction('sortBySectionNameDown', 'homeForm');"
+													src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
+											</td></tr>
+										</table>
+									</td>
+								</tr>
+								<tr>
+									<td>
+										<input type="text" name="sectionNameFilter" value="<%= sessionBean.getHomePage().getSectionNameFilter()%>" size="10"/>
+									</td>									
+									<td>
+										<input type="image"
+											onclick="setAction('filter', 'homeForm');"
+											src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
+									</td>							
+								</tr>
+							</table>
+						</td>
+						<td>
+							<table class="sortTable">
+								<tr>
+									<td><label class="tableTitle">Label</label></td>
+									<td>
+										<table>
+											<tr><td>
+												<input type="image" 
+													onclick="setAction('sortByLabelUp', 'homeForm');"
+													src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
+											</td></tr>
+											<tr><td>
+												<input type="image"
+													onclick="setAction('sortByLabelDown', 'homeForm');"
+													src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
+											</td></tr>
+										</table>
+									</td>
+								</tr>
+								<tr>
+									<td>
+										<input type="text" name="labelFilter" value="<%= sessionBean.getHomePage().getLabelFilter()%>" size="10"/>
+									</td>									
+									<td>
+										<input type="image"
+											onclick="setAction('filter', 'homeForm');"
+											src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
+									</td>							
+								</tr>
+							</table>
+						</td>
 						<td><label class="tableTitle">Contributors</label></td>
-						<td><label class="tableTitle">Last Modified</label></td>
+						<td>
+							<table class="sortTable">
+								<tr>
+									<td><label class="tableTitle">Last Modified</label></td>
+									<td>
+										<table>
+											<tr><td>
+												<input type="image" 
+													onclick="setAction('sortByLastModifiedUp', 'homeForm');"
+													src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
+											</td></tr>
+											<tr><td>
+												<input type="image"
+													onclick="setAction('sortByLastModifiedDown', 'homeForm');"
+													src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
+											</td></tr>
+										</table>
+									</td>
+								</tr>
+								
+							</table>
+						</td>
 						<td><label class="tableTitle">Extraction Interface</label></td>
 						<td><label class="tableTitle">Published in Dataverse</label></td>
 						<td><label class="tableTitle">Manage</label></td>
 						<td><label class="tableTitle">Delete</label></td>
 					</tr>	
 					
-					<% for(LGBranch branch : sessionBean.getHomePage().getBranches()) { %>
+					<% for (LGBranch branch : sessionBean.getHomePage().getDisplayBranchList() ) {
+					%>
 					<tr>
 						<td><%=branch.getId() %></td>
 						<td><%=branch.getBook().getId() %></td>
@@ -105,6 +317,10 @@
 					</tr>
 				</table>
 				 -->
+				 <jsp:include page="../componentes/paginator.jsp">
+					<jsp:param name="formName" value="homeForm"/>
+				</jsp:include> 
+				
 			</form>
 		<% } %>
 		<% } %>