changeset 58:b8ad346e39a0

new: modify based on doc 'Improving LGServices interface.docx': user workflow improvement, functions like adding task into a topic and search suggestions.
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 02 May 2016 12:03:30 +0200
parents 5cbe567a9c52
children bc0219c2600b
files src/main/java/de/mpiwg/gazetteer/dataverse/DataverseUtils.java src/main/java/de/mpiwg/gazetteer/rest/AbstractServletMethod.java src/main/java/de/mpiwg/gazetteer/rest/DownloadFileText.java src/main/java/de/mpiwg/gazetteer/rest/DownloadFullTextSearchCsvFile.java src/main/java/de/mpiwg/gazetteer/rest/DownloadTabDelimited4File.java src/main/java/de/mpiwg/gazetteer/rest/GetFullTextSearchHtmlFile.java src/main/java/de/mpiwg/gazetteer/rest/TextServlet.java src/main/java/de/mpiwg/gazetteer/utils/FileManager.java src/main/java/de/mpiwg/web/jsp/ApplicationBean.java src/main/java/de/mpiwg/web/jsp/BooksPage.java src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java src/main/java/de/mpiwg/web/jsp/HomePage.java src/main/java/de/mpiwg/web/jsp/JSPProxy.java src/main/java/de/mpiwg/web/jsp/SearchPage.java src/main/java/de/mpiwg/web/jsp/SessionBean.java src/main/java/de/mpiwg/web/jsp/TopicListPage.java src/main/java/de/mpiwg/web/search/SortSectionByLevel2.java src/main/webapp/componentes/template.jsp src/main/webapp/methods/addSectionToTopic.jsp src/main/webapp/methods/bookNameAutocomplete.jsp src/main/webapp/methods/level2Autocomplete.jsp src/main/webapp/methods/periodAutocomplete.jsp src/main/webapp/methods/sectionNameAutocomplete.jsp src/main/webapp/methods/taskAdminTypeAutocomplete.jsp src/main/webapp/methods/taskBookNameAutocomplete.jsp src/main/webapp/methods/taskDynastyAutocomplete.jsp src/main/webapp/methods/taskLabelAutocomplete.jsp src/main/webapp/methods/taskLevel1Autocomplete.jsp src/main/webapp/methods/taskLevel2Autocomplete.jsp src/main/webapp/methods/taskPeriodAutocomplete.jsp src/main/webapp/methods/taskSectionNameAutocomplete.jsp src/main/webapp/pages/branchPage.jsp src/main/webapp/pages/fullTextSearch.jsp src/main/webapp/pages/home.jsp src/main/webapp/pages/search.jsp src/main/webapp/pages/topicPage.jsp src/main/webapp/resources/images/download.png
diffstat 37 files changed, 1527 insertions(+), 103 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/gazetteer/dataverse/DataverseUtils.java	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/java/de/mpiwg/gazetteer/dataverse/DataverseUtils.java	Mon May 02 12:03:30 2016 +0200
@@ -87,8 +87,8 @@
             JSONObject fileObj = new JSONObject();
             
             // publish to LGDataverse using tab-delimiter data 
-            fileObj.put(branch.getLabel() + ".csv", table);
-            String fileStr = fileObj.toString();
+            fileObj.put(branch.getLabel() + '-' + lgFile.getVersion().toString() + ".csv", table);	// append version of the branch at the end of fileStr, concatenated with '-'
+            String fileStr = fileObj.toString();	
             multipart.addFormField("file", fileStr);
             
             
--- a/src/main/java/de/mpiwg/gazetteer/rest/AbstractServletMethod.java	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/java/de/mpiwg/gazetteer/rest/AbstractServletMethod.java	Mon May 02 12:03:30 2016 +0200
@@ -48,6 +48,8 @@
 		return null;
 	}
 	
+
+	
 	protected static Long getRequestLongPart(HttpServletRequest request, String partName) throws IOException,
 			IllegalStateException, ServletException {
 		
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/mpiwg/gazetteer/rest/DownloadFileText.java	Mon May 02 12:03:30 2016 +0200
@@ -0,0 +1,74 @@
+package de.mpiwg.gazetteer.rest;
+
+import java.io.FileInputStream;
+import java.io.PrintWriter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.lang.StringUtils;
+import org.json.JSONObject;
+
+import de.mpiwg.gazetteer.bo.LGBranch;
+import de.mpiwg.gazetteer.bo.LGFile;
+import de.mpiwg.gazetteer.utils.DataProvider;
+import de.mpiwg.gazetteer.utils.FileManager;
+import de.mpiwg.gazetteer.utils.PropertiesUtils;
+import de.mpiwg.gazetteer.utils.exceptions.GazetteerException;
+
+public class DownloadFileText extends AbstractServletMethod {
+
+	public static String name = "downloadFileText";
+	
+	public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{
+		
+		Long fileId = getQueryLongParam(request, "fileId");
+		
+		System.out.println("%%%%% DownloadFileText [fileId=" + fileId + "]");
+		
+	
+		if(fileId != null){
+	
+			response.setContentType("text/html; charset=UTF-8");  
+			PrintWriter out = response.getWriter();  
+						
+			LGFile file = DataProvider.getInstance().getFile(fileId);
+			if(file != null){
+				String filename = file.getFileName(); // "112_360452_360453_2015.09.04_12.43.08.924_11.txt";   
+			
+				//filename extension with xml
+				filename = filename.substring(0, filename.length()-3);
+				filename += "xml";
+				
+				response.setContentType("text/xml; charset=UTF-8"); 
+				response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");   
+			
+				String text = FileManager.getFileAsText(file);
+				out.print(text);
+				out.flush();
+				
+			}else{
+				
+				response.setContentType("application/json");
+				JSONObject json = new JSONObject();
+				json.put("status", "error");
+				json.put("message", "File no found (" + fileId + ")");
+				json.put("code", GazetteerException.CODE);
+				out = response.getWriter();
+				out.print(json.toString());
+				out.flush();
+				
+			}
+			
+		}else{
+			response.setContentType("application/json");
+			JSONObject json = new JSONObject();
+			json.put("status", "error");
+			json.put("message", "Following parameters are mandatory: fileId.");
+			PrintWriter out = response.getWriter();
+			out.print(json.toString());
+			out.flush();
+		}
+	}
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/mpiwg/gazetteer/rest/DownloadFullTextSearchCsvFile.java	Mon May 02 12:03:30 2016 +0200
@@ -0,0 +1,66 @@
+package de.mpiwg.gazetteer.rest;
+
+import java.io.FileInputStream;
+import java.io.PrintWriter;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.lang.StringUtils;
+import org.json.JSONObject;
+
+import de.mpiwg.gazetteer.bo.LGBranch;
+import de.mpiwg.gazetteer.bo.LGFile;
+import de.mpiwg.gazetteer.utils.DataProvider;
+import de.mpiwg.gazetteer.utils.FileManager;
+import de.mpiwg.gazetteer.utils.PropertiesUtils;
+import de.mpiwg.gazetteer.utils.exceptions.GazetteerException;
+
+public class DownloadFullTextSearchCsvFile extends AbstractServletMethod {
+
+	public static String name = "downloadFullTextSearchCsvFile";
+	
+	public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{
+		
+		//String filename = getQueryLongParam(request, "file");
+		String filename = request.getParameter("file");
+		
+		byte[] bytes = filename.getBytes(StandardCharsets.ISO_8859_1);
+		filename = new String(bytes, StandardCharsets.UTF_8);
+		
+		System.out.println("%%%%% DownloadFullTextSearchCsvFile [filename=" + filename + "]");
+		
+	
+		if(StringUtils.isNotEmpty(filename)){
+			
+			PrintWriter out = response.getWriter();  
+
+			response.setContentType("text/csv; charset=UTF-8"); 
+			
+			String downloadFilename = filename.split("_")[1];	// Strip the user's id at the beginning of the filename, eg 11_ASDF.csv
+			response.setHeader("Content-Disposition","attachment; filename=\"" + URLEncoder.encode(downloadFilename, "UTF-8") + "\"");   
+		
+			String absolutePath = PropertiesUtils.getPropValue("lgmap_datasets") + "/" + filename;
+			
+			byte[] encoded = Files.readAllBytes(Paths.get(absolutePath));
+			String text = new String(encoded, "UTF8");		
+			
+			out.print(text);
+			out.flush();
+			
+		}else{
+			response.setContentType("application/json");
+			JSONObject json = new JSONObject();
+			json.put("status", "error");
+			json.put("message", "Following parameters are mandatory: fileId.");
+			PrintWriter out = response.getWriter();
+			out.print(json.toString());
+			out.flush();
+		}
+	}
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/mpiwg/gazetteer/rest/DownloadTabDelimited4File.java	Mon May 02 12:03:30 2016 +0200
@@ -0,0 +1,68 @@
+package de.mpiwg.gazetteer.rest;
+
+import java.io.PrintWriter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.lang.StringUtils;
+import org.json.JSONObject;
+
+import de.mpiwg.gazetteer.bo.LGFile;
+import de.mpiwg.gazetteer.utils.DataProvider;
+import de.mpiwg.gazetteer.utils.FileManager;
+import de.mpiwg.gazetteer.utils.HTTPUtils;
+
+public class DownloadTabDelimited4File extends AbstractServletMethod {
+	public static String name = "downloadTabDelimited4File";
+	
+	public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{
+		
+		Long fileId = getQueryLongParam(request, "fileId");
+		
+		if(fileId != null){
+			LGFile file = DataProvider.getInstance().getFile(fileId);
+			if(file != null){
+				
+				String text = HTTPUtils.getTabDelimitedOfFile(fileId);	// get text as tab-delimited file
+					
+				if(StringUtils.isNotEmpty(text)){
+				
+					String filename = file.getFileName(); // "112_360452_360453_2015.09.04_12.43.08.924_11.txt";   
+					
+					//filename extension with csv
+					filename = filename.substring(0, filename.length()-3);
+					filename += "csv";
+					
+					response.setContentType("text/csv; charset=UTF-8"); 
+					response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");   
+				
+					
+					PrintWriter out = response.getWriter();
+					out.print(text);
+					out.flush();
+					
+				}	
+							
+				
+			} else{
+				response.setContentType("application/json");
+				JSONObject json = new JSONObject();
+				json.put("status", "error");
+				json.put("message", "File no found (" + fileId + ")");
+				PrintWriter out = response.getWriter();
+				out.print(json.toString());
+				out.flush();
+			}
+		}else{
+			response.setContentType("application/json");
+			JSONObject json = new JSONObject();
+			json.put("status", "error");
+			json.put("message", "Following parameters are mandatory: fileId.");
+			PrintWriter out = response.getWriter();
+			out.print(json.toString());
+			out.flush();
+		}
+	}
+	
+}
--- a/src/main/java/de/mpiwg/gazetteer/rest/GetFullTextSearchHtmlFile.java	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/java/de/mpiwg/gazetteer/rest/GetFullTextSearchHtmlFile.java	Mon May 02 12:03:30 2016 +0200
@@ -1,6 +1,8 @@
 package de.mpiwg.gazetteer.rest;
 
 import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -8,9 +10,14 @@
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.json.JSONObject;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
 
 import de.mpiwg.gazetteer.bo.LGFile;
 import de.mpiwg.gazetteer.bo.LGFullTextSearchFile;
+import de.mpiwg.gazetteer.db.DBContents;
 import de.mpiwg.gazetteer.utils.DataProvider;
 import de.mpiwg.gazetteer.utils.FileManager;
 import de.mpiwg.gazetteer.utils.HTTPUtils;
@@ -35,9 +42,15 @@
 			LGFullTextSearchFile file = DataProvider.getInstance().getFullTextSearchFile(fileId);
 			if(file != null){
 				
-				String text = FileManager.getFullTextSearchHtmlFileText(file);
+				String html = FileManager.getFullTextSearchHtmlFileText(file);
+				
+				// parse text so that it doesn't show the field "isRemoved", which has two values, true or false
+				html = html.replaceAll("isRemoved", "");
+				html = html.replaceAll("true", "");
+				html = html.replaceAll("false", "");	
+				
 				PrintWriter out = response.getWriter();
-				out.print(text);
+				out.print(html);
 				out.flush();
 				response.setContentType("text/plain; charset=UTF-8");
 				
@@ -53,7 +66,6 @@
 			}
 			
 			
-			
 		}else{
 			response.setContentType("application/json");
 			JSONObject json = new JSONObject();
--- a/src/main/java/de/mpiwg/gazetteer/rest/TextServlet.java	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/java/de/mpiwg/gazetteer/rest/TextServlet.java	Mon May 02 12:03:30 2016 +0200
@@ -67,6 +67,16 @@
 			GetTabDelimited4File.execute(request, response);
 		}else if(StringUtils.equals(GetFullTextSearchHtmlFile.name, method)){
 			GetFullTextSearchHtmlFile.execute(request, response);
+			
+		// for download
+		}else if (StringUtils.equals(DownloadFileText.name, method)) {
+			DownloadFileText.execute(request, response);
+		}else if (StringUtils.equals(DownloadTabDelimited4File.name, method)) {
+			DownloadTabDelimited4File.execute(request, response);
+		}else if (StringUtils.equals(DownloadFullTextSearchCsvFile.name, method)) {
+			DownloadFullTextSearchCsvFile.execute(request, response);
+			
+			
 		}else{
 			writeError(response, "Content-type wrong. It should be: multipart/form-data");
 		}
--- a/src/main/java/de/mpiwg/gazetteer/utils/FileManager.java	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/java/de/mpiwg/gazetteer/utils/FileManager.java	Mon May 02 12:03:30 2016 +0200
@@ -156,6 +156,14 @@
 						+ "<td class='tableTitle'>content id</td>"
 						+ "<td class='tableTitle'>isRemoved</td>"
 						
+						// TODO add Author, edition, volume, place name, coordinates (x,y)
+						+ "<td class='tableTitle'>Author</td>"
+						+ "<td class='tableTitle'>edition</td>"
+						+ "<td class='tableTitle'>volume</td>"
+						+ "<td class='tableTitle'>place name</td>"
+						+ "<td class='tableTitle'>cooridnates(x,y)</td>"
+
+		 			
 		 			+ "<tr>";
 		for (DBContents c : list) {			
 		
@@ -178,6 +186,15 @@
 							"<td class='content'>" + c.getContent() + "</td>" +
 							"<td>" + c.getId() + "</td>" +
 							"<td>" + c.isRemoved() + "</td>" +
+							
+							// TODO 
+							"<td>" + book.getAuthor() + "</td>" +
+							"<td>" + book.getEdition() + "</td>" +
+							"<td>" + book.getVolume() + "</td>" +
+							"<td>" + c.getCoordinatesBook().getPlace_name() + "</td>" +
+							"<td> (" + c.getCoordinatesBook().getX() + "," + c.getCoordinatesBook().getY() + ")</td>" +
+						
+						
 						"</tr>";
 			}
 		}
--- a/src/main/java/de/mpiwg/web/jsp/ApplicationBean.java	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/java/de/mpiwg/web/jsp/ApplicationBean.java	Mon May 02 12:03:30 2016 +0200
@@ -89,6 +89,10 @@
 		return getRootServer() + "/resources/images/plus.png";
 	}
 	
+	public String getDownloadImage(){
+		return getRootServer() + "/resources/images/download.png";
+	}
+	
 	public String getShowImage(){
 		return getRootServer() + "/resources/images/show_16.png";
 	}
--- a/src/main/java/de/mpiwg/web/jsp/BooksPage.java	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/java/de/mpiwg/web/jsp/BooksPage.java	Mon May 02 12:03:30 2016 +0200
@@ -95,6 +95,7 @@
 					(StringUtils.isEmpty(periodFilter) || StringUtils.contains(book.getPeriod(), periodFilter)) &&
 					(StringUtils.isEmpty(editionFilter) || StringUtils.contains(book.getEdition(), editionFilter)) &&
 					(StringUtils.isEmpty(bookNameFilter) || StringUtils.contains(book.getName(), bookNameFilter)) &&
+					(StringUtils.isEmpty(dynastyFilter) || StringUtils.contains(book.getDynasty(), dynastyFilter)) &&
 					(StringUtils.isEmpty(adminTypeFilter) || StringUtils.contains(book.getAdmin_type(), adminTypeFilter))	
 					){
 						String lastEditor = new String();
--- a/src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java	Mon May 02 12:03:30 2016 +0200
@@ -81,8 +81,11 @@
 	
 	private String mouseX;
 	private String mouseY;
+
+	private LGFullTextSearchFile file = null;
 	
 	
+
 	@Override
 	public void init(){
 		super.init();
@@ -179,6 +182,8 @@
 		this.level1Filter = new String();
 		this.adminTypeFilter = new String();
 		
+		this.setFile(null);
+		
 		if(StringUtils.isNotEmpty(this.searchTerm)){
 			try {
 				List<String> terms = splitTerms();
@@ -287,12 +292,15 @@
 	
 	public void loadFile() {
 		Long fileId = getLongParameter("fileId");
+		
+		
 		logger.debug("loading fileId=" + fileId);
 		
 		if(fileId != null){
 			// load from html file into searching result table
 			LGFullTextSearchFile file = DataProvider.getInstance().getFullTextSearchFile(fileId);
-			if(file != null){
+			if(file != null) {
+				this.setFile(file);
 				String html;
 				try {
 					html = FileManager.getFullTextSearchHtmlFileText(file);
@@ -370,6 +378,8 @@
 					e.printStackTrace();
 				}
 				
+			} else {
+				this.setFile(null);
 			}
 		}
 		
@@ -418,6 +428,8 @@
 			
 			logger.debug("file: " + file.getInfo());
 			
+			this.setFile(file);
+			
 			addMsg("The table has been saved!");
 
 			
@@ -865,6 +877,14 @@
 		this.selectedNumOfContent = selectedNumOfContent;
 	}
 
+	public LGFullTextSearchFile getFile() {
+		return file;
+	}
+
+	public void setFile(LGFullTextSearchFile file) {
+		this.file = file;
+	}
+	
 	
 	
 	/////// Sorting
--- a/src/main/java/de/mpiwg/web/jsp/HomePage.java	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/java/de/mpiwg/web/jsp/HomePage.java	Mon May 02 12:03:30 2016 +0200
@@ -2,7 +2,9 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -35,8 +37,14 @@
 
 
 
+
+
+
+
 import de.mpiwg.gazetteer.bo.LGBranch;
+import de.mpiwg.gazetteer.bo.LGTopicSectionRelation;
 import de.mpiwg.gazetteer.db.DBBook;
+import de.mpiwg.gazetteer.db.DBSection;
 import de.mpiwg.gazetteer.utils.DBService;
 import de.mpiwg.gazetteer.utils.DataProvider;
 import de.mpiwg.web.books.SortBooksByBookId;
@@ -86,6 +94,8 @@
 
 	private DataPaginator paginator = new DataPaginator();
 
+	private Map<Long, List<LGTopicSectionRelation>> topicSectionRelationMap;
+	
 	
 	public void loadParameters(HttpServletRequest request, HttpServletResponse response){
 		this.request = request;
@@ -106,16 +116,28 @@
 	
 	public void reloadBranches(){
 		logger.debug("reloadBranches");
+		
 		if (this.completeBranchList == null) {
 			this.forceLoadBranches();
+		
 			this.filteringMessage = null;
+		} else {
+	
+			this.loadTopicSectionRelation();
+							
+			for(LGBranch branch : this.completeBranchList){
+				branch.getSection().setTopicSectionRelation(this.topicSectionRelationMap.get(branch.getSection().getId()));
+			}
+			
 		}
+	
 		return;
 	}
 	
 	
 	public void forceLoadBranches(){
 		logger.debug("forceLoadBranches");
+		this.filteringMessage = null;
 		
 		this.completeBranchList = new ArrayList<LGBranch>();
 		if(getSessionBean().getUser() != null){
@@ -128,15 +150,34 @@
 				} else {
 					this.completeBranchList.add(branch);
 				}
-			}	
+			}
 		}
 		this.setBranchNumber(this.completeBranchList.size());
 		
 		sortByLastModifiedDown();	// default sorting by from lasted modified to oldest
 		
+		// loadTopicSectionRelation?
+		this.loadTopicSectionRelation();
+									
+		for(LGBranch branch : this.completeBranchList){
+			branch.getSection().setTopicSectionRelation(this.topicSectionRelationMap.get(branch.getSection().getId()));
+		}
 		
 	}
 	
+	private void loadTopicSectionRelation(){
+		this.topicSectionRelationMap = new HashMap<Long, List<LGTopicSectionRelation>>();
+		List<LGTopicSectionRelation> list = DataProvider.getInstance().getAllExistingTopicSectionRelation();
+		
+		for(LGTopicSectionRelation relation : list){
+			relation.loadTransientData();
+			if(this.topicSectionRelationMap.get(relation.getSectionId()) == null){
+				this.topicSectionRelationMap.put(relation.getSectionId(), new ArrayList<LGTopicSectionRelation>());
+			}
+			this.topicSectionRelationMap.get(relation.getSectionId()).add(relation);
+		}
+	}
+
 	public void deleteBranch(){
 		logger.debug("deleteBranch " + branchId);
 		
@@ -144,7 +185,9 @@
 			LGBranch branch = DataProvider.getInstance().getBranch(branchId);
 			if(branch != null){
 				DataProvider.getInstance().deleteBranch(branch);
-				this.reloadBranches();
+				//this.reloadBranches();
+				this.forceLoadBranches();
+				
 			}	
 		}
 	}
@@ -279,6 +322,123 @@
 	
 	}
 	
+	
+	public List<String> suggestBookName(String term, int limit){
+		List<String> list = new ArrayList<String>();
+		for(LGBranch branch : this.completeBranchList){
+			String bookName = branch.getBook().getName();
+			if(!list.contains(bookName) && bookName.startsWith(term)){
+				list.add(bookName);
+			}
+			if(limit == list.size()){
+				break;
+			}	
+		}
+		return list;
+	}
+	
+	public List<String> suggestLevel1(String term, int limit){
+		List<String> list = new ArrayList<String>();
+		for(LGBranch branch : this.completeBranchList){
+			String level1 = branch.getBook().getLevel1();
+			if(!list.contains(level1) && level1.startsWith(term)){
+				list.add(level1);
+			}
+			if(limit == list.size()){
+				break;
+			}	
+		}
+		return list;
+	}
+	
+	public List<String> suggestLevel2(String term, int limit){
+		List<String> list = new ArrayList<String>();
+		for(LGBranch branch : this.completeBranchList){
+			String level2 = branch.getBook().getLevel2();
+			if(!list.contains(level2) && level2.startsWith(term)){
+				list.add(level2);
+			}
+			if(limit == list.size()){
+				break;
+			}	
+		}
+		return list;
+	}
+	
+	public List<String> suggestDynasty(String term, int limit){
+		List<String> list = new ArrayList<String>();
+		for(LGBranch branch : this.completeBranchList){
+			String dynasty = branch.getBook().getDynasty();
+			if(!list.contains(dynasty) && dynasty.startsWith(term)){
+				list.add(dynasty);
+			}
+			if(limit == list.size()){
+				break;
+			}	
+		}
+		return list;
+	}
+	
+	public List<String> suggestPeriod(String term, int limit){
+		List<String> list = new ArrayList<String>();
+		for(LGBranch branch : this.completeBranchList){
+			String period = branch.getBook().getPeriod();
+			if(!list.contains(period) && period.startsWith(term)){
+				list.add(period);
+			}
+			if(limit == list.size()){
+				break;
+			}	
+		}
+		return list;
+	}
+	
+	public List<String> suggestAdminType(String term, int limit){
+		List<String> list = new ArrayList<String>();
+		for(LGBranch branch : this.completeBranchList){
+			String adminType = branch.getBook().getAdmin_type();
+			if(!list.contains(adminType) && adminType.startsWith(term)){
+				list.add(adminType);
+			}
+			if(limit == list.size()){
+				break;
+			}	
+		}
+		return list;
+	}
+	
+	public List<String> suggestSectionName(String term, int limit){
+		List<String> list = new ArrayList<String>();
+		for(LGBranch branch : this.completeBranchList){
+			String sectionName = branch.getSection().getName();
+			if(!list.contains(sectionName) && sectionName.startsWith(term)){
+				list.add(sectionName);
+			}
+			if(limit == list.size()){
+				break;
+			}	
+		}
+		return list;
+	}
+	
+	public List<String> suggestLabel(String term, int limit){
+		List<String> list = new ArrayList<String>();
+		for(LGBranch branch : this.completeBranchList){
+			String label = branch.getLabel();
+			if(!list.contains(label) && label.startsWith(term)){
+				list.add(label);
+			}
+			if(limit == list.size()){
+				break;
+			}	
+		}
+		return list;
+	}
+	
+	
+	
+	
+	
 	public void sortByBranchIdUp() {
 		Collections.sort(this.completeBranchList, new SortBranchByBranchId());
 		filter();
--- a/src/main/java/de/mpiwg/web/jsp/JSPProxy.java	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/java/de/mpiwg/web/jsp/JSPProxy.java	Mon May 02 12:03:30 2016 +0200
@@ -37,8 +37,8 @@
 				}else if(StringUtils.equals(action, "logout")){
 					getSessionBean().logout();
 				}
-				return TopicListPage.page;	// the new home page
-				//return "pages/home.jsp";
+				//return TopicListPage.page;	// the new home page?
+				return "pages/home.jsp";
 				
 			} else if (getSessionBean() == null || getSessionBean().getUser() == null) {
 				// return to home page where will ask user to login.
@@ -46,7 +46,8 @@
 				// alert session timeout
 				getSessionBean().addMsg("Timeout or Logout at another page! Please login again.");
 				
-				return TopicListPage.page;	// the new home page
+				//return TopicListPage.page;	// the new home page?
+				return "pages/home.jsp";
 			}
 		
 			
@@ -56,7 +57,7 @@
 				
 				if(StringUtils.equals(action, "addContributor")){
 					getSessionBean().getBranchPage().addContributor();
-				} else if(StringUtils.equals(action, "removeContributor")){
+				}else if(StringUtils.equals(action, "removeContributor")){
 					getSessionBean().getBranchPage().removeContributor();
 				}else if(StringUtils.equals(action, "deleteFile")){
 					getSessionBean().getBranchPage().deleteFile();
@@ -209,7 +210,11 @@
 					getSessionBean().getSearchPage().sortByLevel1Up();
 				} else if(StringUtils.equals(action, "sortByLevel1Down")){
 					getSessionBean().getSearchPage().sortByLevel1Down();
-					
+				} else if(StringUtils.equals(action, "sortByLevel2Up")){
+					getSessionBean().getSearchPage().sortByLevel2Up();
+				} else if(StringUtils.equals(action, "sortByLevel2Down")){
+					getSessionBean().getSearchPage().sortByLevel2Down();
+						
 				} else if(StringUtils.equals(action, "sortByAdminTypeUp")){
 					getSessionBean().getSearchPage().sortByAdminTypeUp();
 				} else if(StringUtils.equals(action, "sortByAdminTypeDown")){
@@ -372,8 +377,18 @@
 					Long selectedSectionId = getLongParameter("selectedSectionId");
 					Long selectedTopicId = getLongParameter("selectedTopicId");
 					getSessionBean().getTopicPage().addSectionToTopic(selectedSectionId, selectedTopicId);
+					
+					// TODO it's possible to add a section into a topic in the task page, so need to modify here...
+					
 					getSessionBean().getSearchPage().updateTopicSectionRelation();
 					
+					String sourceBean = getParameter("sourceBean");
+					if (StringUtils.equals(sourceBean, "home")) {
+						return HomePage.page;
+					} else if (StringUtils.equals(sourceBean, "search")) {
+						return SearchPage.page;
+					}
+					
 					return SearchPage.page;
 				
 				} else if(StringUtils.equals(action, "addAllSections")) {
@@ -530,14 +545,14 @@
 			e.printStackTrace();
 			addMsg("There is an internal error: " + e.getLocalizedMessage());
 			
-			return TopicListPage.page;
-			//return HomePage.page;
+			//return TopicListPage.page;
+			return HomePage.page;
 		}
 		
 	
 		//Default Page:
-		return TopicListPage.page;	// will be the new home page
-		//return HomePage.page;
+		//return TopicListPage.page;	// will be the new home page?
+		return HomePage.page;
 	}
 
 
--- a/src/main/java/de/mpiwg/web/jsp/SearchPage.java	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/java/de/mpiwg/web/jsp/SearchPage.java	Mon May 02 12:03:30 2016 +0200
@@ -25,6 +25,7 @@
 import de.mpiwg.web.search.SortSectionByEdition;
 import de.mpiwg.web.search.SortSectionById;
 import de.mpiwg.web.search.SortSectionByLevel1;
+import de.mpiwg.web.search.SortSectionByLevel2;
 import de.mpiwg.web.search.SortSectionByPeriod;
 import de.mpiwg.web.search.SortSectionByStartPage;
 import de.mpiwg.web.search.SortSectionByVolume;
@@ -53,6 +54,11 @@
 	private String dynastyFilter = new String();
 	private String adminTypeFilter = new String();
 	private String level1Filter = new String();
+	private String level2Filter = new String();
+	
+	private String bookNameFilter = new String();
+	private String periodFilter = new String();
+	private String sectionNameFilter = new String();
 	
 	private DataPaginator paginator = new DataPaginator();
 	private String searchMessage;
@@ -76,6 +82,11 @@
 		this.dynastyFilter = getParameter("dynastyFilter");
 		this.adminTypeFilter = getParameter("adminTypeFilter");
 		this.level1Filter = getParameter("level1Filter");
+		this.level2Filter = getParameter("level2Filter");
+		this.bookNameFilter = getParameter("bookNameFilter");
+		this.periodFilter = getParameter("periodFilter");
+		this.sectionNameFilter = getParameter("sectionNameFilter");
+		
 		this.searchIn = getIntParameter("searchIn");
 			
 	}
@@ -130,36 +141,45 @@
 	
 	public void filter(){	
 		this.filteredSectionList = new ArrayList<DBSection>();
-		for(DBSection section : this.completeSectionList){
-			if(!this.filteredSectionList.contains(section)){
-					
-				if( (StringUtils.isEmpty(dynastyFilter) || StringUtils.startsWith(section.getBook().getDynasty(), dynastyFilter)) &&
-						(StringUtils.isEmpty(level1Filter) || StringUtils.startsWith(section.getBook().getLevel1(), level1Filter)) &&
-						(StringUtils.isEmpty(adminTypeFilter) || StringUtils.startsWith(section.getBook().getAdmin_type(), adminTypeFilter))
-								){
-					this.filteredSectionList.add(section);
-				}	
+		if (this.completeSectionList != null) {
+		
+			for(DBSection section : this.completeSectionList){
+				if(!this.filteredSectionList.contains(section)){
+						
+					if( (StringUtils.isEmpty(dynastyFilter) || StringUtils.startsWith(section.getBook().getDynasty(), dynastyFilter)) &&
+							(StringUtils.isEmpty(level1Filter) || StringUtils.startsWith(section.getBook().getLevel1(), level1Filter)) &&
+							(StringUtils.isEmpty(level2Filter) || StringUtils.startsWith(section.getBook().getLevel2(), level2Filter)) &&
+							(StringUtils.isEmpty(bookNameFilter) || StringUtils.startsWith(section.getBook().getName(), bookNameFilter)) &&
+							(StringUtils.isEmpty(periodFilter) || StringUtils.startsWith(section.getBook().getPeriod(), periodFilter)) &&
+							(StringUtils.isEmpty(sectionNameFilter) || StringUtils.startsWith(section.getName(), sectionNameFilter)) &&
+							
+							(StringUtils.isEmpty(adminTypeFilter) || StringUtils.startsWith(section.getBook().getAdmin_type(), adminTypeFilter))
+									){
+						this.filteredSectionList.add(section);
+					}	
+				}
 			}
-		}
 			
-		if(completeSectionList.size() > 0){
-			this.searchMessage = completeSectionList.size() + " section(s) found for the term(s): " + this.searchTerm;
-			this.filteringMessage = this.filteredSectionList.size() + " section(s) listed after the filtering";
-
-			this.paginator.setCurrentPage(0);
-			this.paginator.resetNumberOfPages(filteredSectionList.size());
-							
-		}else{
-			this.searchMessage = "No sections found for the term(s): " + this.searchTerm;
-			this.filteredSectionList = null;
-			this.filteringMessage = "";
+		
+			
+			if(completeSectionList.size() > 0){
+				this.searchMessage = completeSectionList.size() + " section(s) found for the term(s): " + this.searchTerm;
+				this.filteringMessage = this.filteredSectionList.size() + " section(s) listed after the filtering";
+	
+				this.paginator.setCurrentPage(0);
+				this.paginator.resetNumberOfPages(filteredSectionList.size());
+								
+			}else{
+				this.searchMessage = "No sections found for the term(s): " + this.searchTerm;
+				this.filteredSectionList = null;
+				this.filteringMessage = "";
+					
+				this.paginator.setCurrentPage(0);
+				this.paginator.resetNumberOfPages(0);
+			}
 				
-			this.paginator.setCurrentPage(0);
-			this.paginator.resetNumberOfPages(0);
+			this.updateCurrentSections();
 		}
-			
-		this.updateCurrentSections();
-			
 	}
 	
 	private void updateCurrentSections() {
@@ -255,6 +275,49 @@
 		return list;
 	}
 	
+	public List<String> suggestLevel2(String term, int limit){
+		List<String> list = new ArrayList<String>();
+		for(DBSection section : this.completeSectionList){
+			String level2 = section.getBook().getLevel2();
+			if(!list.contains(level2) && level2.startsWith(term)){
+				list.add(level2);
+			}
+			if(limit == list.size()){
+				break;
+			}	
+		}
+		return list;
+	}
+	
+	
+	public List<String> suggestBookName(String term, int limit){
+		List<String> list = new ArrayList<String>();
+		for(DBSection section : this.completeSectionList){
+			String bookName = section.getBook().getName();
+			if(!list.contains(bookName) && bookName.startsWith(term)){
+				list.add(bookName);
+			}
+			if(limit == list.size()){
+				break;
+			}	
+		}
+		return list;
+	}
+	
+	public List<String> suggestPeriod(String term, int limit){
+		List<String> list = new ArrayList<String>();
+		for(DBSection section : this.completeSectionList){
+			String period = section.getBook().getPeriod();
+			if(!list.contains(period) && period.startsWith(term)){
+				list.add(period);
+			}
+			if(limit == list.size()){
+				break;
+			}	
+		}
+		return list;
+	}
+	
 	public List<String> suggestAdminType(String term, int limit){
 		List<String> list = new ArrayList<String>();
 		for(DBSection section : this.completeSectionList){
@@ -268,6 +331,19 @@
 		}
 		return list;
 	}
+	public List<String> suggestSectionName(String term, int limit){
+		List<String> list = new ArrayList<String>();
+		for(DBSection section : this.completeSectionList){
+			String sectionName = section.getName();
+			if(!list.contains(sectionName) && sectionName.startsWith(term)){
+				list.add(sectionName);
+			}
+			if(limit == list.size()){
+				break;
+			}	
+		}
+		return list;
+	}
 	
 
 	public static Integer getSEARCH_IN_SECTION_NAME() {
@@ -422,6 +498,39 @@
 		this.dynastyFilter = dynastyFilter;
 	}
 
+	public String getLevel2Filter() {
+		return level2Filter;
+	}
+
+	public void setLevel2Filter(String level2Filter) {
+		this.level2Filter = level2Filter;
+	}
+
+	public String getBookNameFilter() {
+		return bookNameFilter;
+	}
+
+	public void setBookNameFilter(String bookNameFilter) {
+		this.bookNameFilter = bookNameFilter;
+	}
+
+	public String getSectionNameFilter() {
+		return sectionNameFilter;
+	}
+
+	public void setSectionNameFilter(String sectionNameFilter) {
+		this.sectionNameFilter = sectionNameFilter;
+	}
+
+	public String getPeriodFilter() {
+		return periodFilter;
+	}
+
+	public void setPeriodFilter(String periodFilter) {
+		this.periodFilter = periodFilter;
+	}
+
+	
 	
 	/////// Sorting
 	
@@ -536,6 +645,17 @@
 		filter();
 	}
 	
+	public void sortByLevel2Up(){
+		Collections.sort(this.completeSectionList, new SortSectionByLevel2());
+		filter();
+	}
+	
+	public void sortByLevel2Down(){
+		Collections.sort(this.completeSectionList, new SortSectionByLevel2());
+		Collections.reverse(completeSectionList);
+		filter();
+	}
+	
 	public void sortByAdminTypeUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByAdminType());
 		filter();
--- a/src/main/java/de/mpiwg/web/jsp/SessionBean.java	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/java/de/mpiwg/web/jsp/SessionBean.java	Mon May 02 12:03:30 2016 +0200
@@ -102,6 +102,8 @@
 					this.homePage.loadParameters(request, response);
 					this.homePage.reloadBranches();	
 					
+					this.topicListPage.loadParameters(request, response);
+					this.topicListPage.reloadTopics();
 					
 					
 				} else {					
--- a/src/main/java/de/mpiwg/web/jsp/TopicListPage.java	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/java/de/mpiwg/web/jsp/TopicListPage.java	Mon May 02 12:03:30 2016 +0200
@@ -61,8 +61,9 @@
 		
 		this.completeTopicList = new ArrayList<LGTopic>();
 		
-		// TODO sometimes this.getSessionBean() will cause NullPointerException
-		if(this.getSessionBean().getUser() != null){
+		// sometimes this.getSessionBean() will cause NullPointerException. Fixed.
+		
+		if(getSessionBean().getUser() != null){
 			for(LGTopic topic : DataProvider.getInstance().getTopics(this.getSessionBean().getUser().getId())){
 				
 				if (topic.isEmpty()) {
--- a/src/main/java/de/mpiwg/web/search/SortSectionByLevel2.java	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/java/de/mpiwg/web/search/SortSectionByLevel2.java	Mon May 02 12:03:30 2016 +0200
@@ -10,6 +10,6 @@
 		if(o1.getBook() == null || o2.getBook() == null){
 			return o1.getName().compareTo(o2.getName());	
 		}
-		return o1.getBook().getLevel1().compareTo(o2.getBook().getLevel1());
+		return o1.getBook().getLevel2().compareTo(o2.getBook().getLevel2());
 	}
 }
--- a/src/main/webapp/componentes/template.jsp	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/webapp/componentes/template.jsp	Mon May 02 12:03:30 2016 +0200
@@ -76,9 +76,10 @@
 	    <!-- 
 	    <a href="<%=sessionBean.getApplicationBean().getRootServer()%>/pages/createFile.jsp" class="current">Create File</a>
 	    -->
-	    <a href="<%=sessionBean.getApplicationBean().getRootServer()%>/pages/search.jsp">Search</a>
+	    <a href="<%=sessionBean.getApplicationBean().getRootServer()%>/pages/search.jsp">Sections</a>
+	    <a href="<%=sessionBean.getApplicationBean().getRootServer()%>/pages/books.jsp">Books</a>
 	    <a href="<%=sessionBean.getApplicationBean().getRootServer()%>/pages/fullTextSearch.jsp">Full Text Search</a>
-	    <a href="<%=sessionBean.getApplicationBean().getRootServer()%>/pages/books.jsp">Books</a>
+	    
 	</div>	
 	
 	
--- a/src/main/webapp/methods/addSectionToTopic.jsp	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/webapp/methods/addSectionToTopic.jsp	Mon May 02 12:03:30 2016 +0200
@@ -29,7 +29,8 @@
 				action="<%= sessionBean.getApplicationBean().getRootServer()%>/proxy.jsp"
 				method="post">
 				<input name="bean" type="hidden" value="topicBean" /> 
-		
+				<input name="sourceBean" type="hidden" value="<%=request.getParameter("sourceBean")%>" /> 
+				
 						
 				<table class="dialogTable">
 					<tr>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/webapp/methods/bookNameAutocomplete.jsp	Mon May 02 12:03:30 2016 +0200
@@ -0,0 +1,24 @@
+<%@page import="java.util.List"%>
+<%@page import="de.mpiwg.gazetteer.utils.DBService"%>
+<%@page import="org.json.JSONObject"%>
+<%@page import="org.json.JSONArray"%>
+
+<jsp:useBean id="sessionBean" class="de.mpiwg.web.jsp.SessionBean" scope="session" />
+
+<%
+	
+	String term = request.getParameter("term");
+	List<String> list = sessionBean.getSearchPage().suggestBookName(term, 10);
+
+	
+	JSONArray jsonArr = new JSONArray();
+	
+	for(String item : list){
+		JSONObject json = new JSONObject();
+		json.put("name", item);
+		json.put("value", item);
+		jsonArr.put(json);
+		System.out.print("*");
+	}
+	out.println(jsonArr);
+%>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/webapp/methods/level2Autocomplete.jsp	Mon May 02 12:03:30 2016 +0200
@@ -0,0 +1,25 @@
+<%@page import="java.util.List"%>
+<%@page import="de.mpiwg.gazetteer.utils.DBService"%>
+<%@page import="org.json.JSONObject"%>
+<%@page import="org.json.JSONArray"%>
+
+<jsp:useBean id="sessionBean" class="de.mpiwg.web.jsp.SessionBean" scope="session" />
+
+<%
+
+
+	String term = request.getParameter("term");
+	List<String> list = sessionBean.getSearchPage().suggestLevel2(term, 10);
+
+	
+	JSONArray jsonArr = new JSONArray();
+	
+	for(String item : list){
+		JSONObject json = new JSONObject();
+		json.put("name", item);
+		json.put("value", item);
+		jsonArr.put(json);
+		System.out.print("*");
+	}
+	out.println(jsonArr);
+%>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/webapp/methods/periodAutocomplete.jsp	Mon May 02 12:03:30 2016 +0200
@@ -0,0 +1,24 @@
+<%@page import="java.util.List"%>
+<%@page import="de.mpiwg.gazetteer.utils.DBService"%>
+<%@page import="org.json.JSONObject"%>
+<%@page import="org.json.JSONArray"%>
+
+<jsp:useBean id="sessionBean" class="de.mpiwg.web.jsp.SessionBean" scope="session" />
+
+<%
+	
+	String term = request.getParameter("term");
+	List<String> list = sessionBean.getSearchPage().suggestPeriod(term, 10);
+
+	
+	JSONArray jsonArr = new JSONArray();
+	
+	for(String item : list){
+		JSONObject json = new JSONObject();
+		json.put("name", item);
+		json.put("value", item);
+		jsonArr.put(json);
+		System.out.print("*");
+	}
+	out.println(jsonArr);
+%>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/webapp/methods/sectionNameAutocomplete.jsp	Mon May 02 12:03:30 2016 +0200
@@ -0,0 +1,24 @@
+<%@page import="java.util.List"%>
+<%@page import="de.mpiwg.gazetteer.utils.DBService"%>
+<%@page import="org.json.JSONObject"%>
+<%@page import="org.json.JSONArray"%>
+
+<jsp:useBean id="sessionBean" class="de.mpiwg.web.jsp.SessionBean" scope="session" />
+
+<%
+	
+	String term = request.getParameter("term");
+	List<String> list = sessionBean.getSearchPage().suggestSectionName(term, 10);
+
+	
+	JSONArray jsonArr = new JSONArray();
+	
+	for(String item : list){
+		JSONObject json = new JSONObject();
+		json.put("name", item);
+		json.put("value", item);
+		jsonArr.put(json);
+		System.out.print("*");
+	}
+	out.println(jsonArr);
+%>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/webapp/methods/taskAdminTypeAutocomplete.jsp	Mon May 02 12:03:30 2016 +0200
@@ -0,0 +1,26 @@
+<%@page import="java.util.List"%>
+<%@page import="de.mpiwg.gazetteer.utils.DBService"%>
+<%@page import="org.json.JSONObject"%>
+<%@page import="org.json.JSONArray"%>
+
+<jsp:useBean id="sessionBean" class="de.mpiwg.web.jsp.SessionBean" scope="session" />
+
+<%
+
+	
+	
+	String term = request.getParameter("term");
+
+	List<String> list = sessionBean.getHomePage().suggestAdminType(term, 10);	
+	
+	JSONArray jsonArr = new JSONArray();
+	
+	for(String item : list){
+		JSONObject json = new JSONObject();
+		json.put("name", item);
+		json.put("value", item);
+		jsonArr.put(json);
+		System.out.print("*");
+	}
+	out.println(jsonArr);
+%>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/webapp/methods/taskBookNameAutocomplete.jsp	Mon May 02 12:03:30 2016 +0200
@@ -0,0 +1,26 @@
+<%@page import="java.util.List"%>
+<%@page import="de.mpiwg.gazetteer.utils.DBService"%>
+<%@page import="org.json.JSONObject"%>
+<%@page import="org.json.JSONArray"%>
+
+<jsp:useBean id="sessionBean" class="de.mpiwg.web.jsp.SessionBean" scope="session" />
+
+<%
+
+	
+	
+	String term = request.getParameter("term");
+
+	List<String> list = sessionBean.getHomePage().suggestBookName(term, 10);	
+	
+	JSONArray jsonArr = new JSONArray();
+	
+	for(String item : list){
+		JSONObject json = new JSONObject();
+		json.put("name", item);
+		json.put("value", item);
+		jsonArr.put(json);
+		System.out.print("*");
+	}
+	out.println(jsonArr);
+%>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/webapp/methods/taskDynastyAutocomplete.jsp	Mon May 02 12:03:30 2016 +0200
@@ -0,0 +1,26 @@
+<%@page import="java.util.List"%>
+<%@page import="de.mpiwg.gazetteer.utils.DBService"%>
+<%@page import="org.json.JSONObject"%>
+<%@page import="org.json.JSONArray"%>
+
+<jsp:useBean id="sessionBean" class="de.mpiwg.web.jsp.SessionBean" scope="session" />
+
+<%
+
+	
+	
+	String term = request.getParameter("term");
+
+	List<String> list = sessionBean.getHomePage().suggestDynasty(term, 10);	
+	
+	JSONArray jsonArr = new JSONArray();
+	
+	for(String item : list){
+		JSONObject json = new JSONObject();
+		json.put("name", item);
+		json.put("value", item);
+		jsonArr.put(json);
+		System.out.print("*");
+	}
+	out.println(jsonArr);
+%>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/webapp/methods/taskLabelAutocomplete.jsp	Mon May 02 12:03:30 2016 +0200
@@ -0,0 +1,26 @@
+<%@page import="java.util.List"%>
+<%@page import="de.mpiwg.gazetteer.utils.DBService"%>
+<%@page import="org.json.JSONObject"%>
+<%@page import="org.json.JSONArray"%>
+
+<jsp:useBean id="sessionBean" class="de.mpiwg.web.jsp.SessionBean" scope="session" />
+
+<%
+
+	
+	
+	String term = request.getParameter("term");
+
+	List<String> list = sessionBean.getHomePage().suggestLabel(term, 10);	
+	
+	JSONArray jsonArr = new JSONArray();
+	
+	for(String item : list){
+		JSONObject json = new JSONObject();
+		json.put("name", item);
+		json.put("value", item);
+		jsonArr.put(json);
+		System.out.print("*");
+	}
+	out.println(jsonArr);
+%>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/webapp/methods/taskLevel1Autocomplete.jsp	Mon May 02 12:03:30 2016 +0200
@@ -0,0 +1,26 @@
+<%@page import="java.util.List"%>
+<%@page import="de.mpiwg.gazetteer.utils.DBService"%>
+<%@page import="org.json.JSONObject"%>
+<%@page import="org.json.JSONArray"%>
+
+<jsp:useBean id="sessionBean" class="de.mpiwg.web.jsp.SessionBean" scope="session" />
+
+<%
+
+	
+	
+	String term = request.getParameter("term");
+
+	List<String> list = sessionBean.getHomePage().suggestLevel1(term, 10);	
+	
+	JSONArray jsonArr = new JSONArray();
+	
+	for(String item : list){
+		JSONObject json = new JSONObject();
+		json.put("name", item);
+		json.put("value", item);
+		jsonArr.put(json);
+		System.out.print("*");
+	}
+	out.println(jsonArr);
+%>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/webapp/methods/taskLevel2Autocomplete.jsp	Mon May 02 12:03:30 2016 +0200
@@ -0,0 +1,26 @@
+<%@page import="java.util.List"%>
+<%@page import="de.mpiwg.gazetteer.utils.DBService"%>
+<%@page import="org.json.JSONObject"%>
+<%@page import="org.json.JSONArray"%>
+
+<jsp:useBean id="sessionBean" class="de.mpiwg.web.jsp.SessionBean" scope="session" />
+
+<%
+
+	
+	
+	String term = request.getParameter("term");
+
+	List<String> list = sessionBean.getHomePage().suggestLevel2(term, 10);	
+	
+	JSONArray jsonArr = new JSONArray();
+	
+	for(String item : list){
+		JSONObject json = new JSONObject();
+		json.put("name", item);
+		json.put("value", item);
+		jsonArr.put(json);
+		System.out.print("*");
+	}
+	out.println(jsonArr);
+%>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/webapp/methods/taskPeriodAutocomplete.jsp	Mon May 02 12:03:30 2016 +0200
@@ -0,0 +1,26 @@
+<%@page import="java.util.List"%>
+<%@page import="de.mpiwg.gazetteer.utils.DBService"%>
+<%@page import="org.json.JSONObject"%>
+<%@page import="org.json.JSONArray"%>
+
+<jsp:useBean id="sessionBean" class="de.mpiwg.web.jsp.SessionBean" scope="session" />
+
+<%
+
+	
+	
+	String term = request.getParameter("term");
+
+	List<String> list = sessionBean.getHomePage().suggestPeriod(term, 10);	
+	
+	JSONArray jsonArr = new JSONArray();
+	
+	for(String item : list){
+		JSONObject json = new JSONObject();
+		json.put("name", item);
+		json.put("value", item);
+		jsonArr.put(json);
+		System.out.print("*");
+	}
+	out.println(jsonArr);
+%>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/webapp/methods/taskSectionNameAutocomplete.jsp	Mon May 02 12:03:30 2016 +0200
@@ -0,0 +1,26 @@
+<%@page import="java.util.List"%>
+<%@page import="de.mpiwg.gazetteer.utils.DBService"%>
+<%@page import="org.json.JSONObject"%>
+<%@page import="org.json.JSONArray"%>
+
+<jsp:useBean id="sessionBean" class="de.mpiwg.web.jsp.SessionBean" scope="session" />
+
+<%
+
+	
+	
+	String term = request.getParameter("term");
+
+	List<String> list = sessionBean.getHomePage().suggestSectionName(term, 10);	
+	
+	JSONArray jsonArr = new JSONArray();
+	
+	for(String item : list){
+		JSONObject json = new JSONObject();
+		json.put("name", item);
+		json.put("value", item);
+		jsonArr.put(json);
+		System.out.print("*");
+	}
+	out.println(jsonArr);
+%>
\ No newline at end of file
--- a/src/main/webapp/pages/branchPage.jsp	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/webapp/pages/branchPage.jsp	Mon May 02 12:03:30 2016 +0200
@@ -1,4 +1,5 @@
 <%@page import="de.mpiwg.gazetteer.dataverse.bo.VDCUser"%>
+<%@page import="de.mpiwg.gazetteer.bo.LGBranch"%>
 <%@page import="de.mpiwg.gazetteer.bo.LGFile"%>
 <%@page import="org.apache.commons.lang.StringUtils"%>
 <%@page import="de.mpiwg.gazetteer.db.DBSection"%>
@@ -186,12 +187,6 @@
 									</tr>
 									
 									
-									
-									
-									
-									
-									
-									
 									<tr>
 										<td><label>Created</label></td>
 										<td><label><%=sessionBean.getBranchPage().getBranch().getFomattedCreation() %></label></td>
@@ -258,11 +253,22 @@
 										<td><label><%=sessionBean.getBranchPage().getLastFile().getFomattedCreation() %></label></td>
 									</tr>									
 									<tr>
-										<td><label>Text</label></td>
+										<td><label>Tagged Text</label>
+											<% LGBranch branch = sessionBean.getBranchPage().getBranch(); %>
+											<a onclick="branchInExtractionInterface('<%=branch.getId() %>', '<%=branch.getCurrentLastFileId() %>', '<%=branch.getSectionId() %>', '<%=branch.getSection().getName() %>', '<%=branch.getBook().getId() %>', '<%=branch.getBook().getName() %>', '<%=sessionBean.getUser().getId() %>', '<%=sessionBean.getApplicationBean().getExtractionInterfaceUrl()%>');">
+												<img title="Show Task in Extraction Interface" src="<%=sessionBean.getApplicationBean().getEditImage()%>"/>
+											</a>
+										
+										</td>
+										
 										<td>
 											<textarea rows=20" cols="70">
 												<%=sessionBean.getBranchPage().getText() %>
-											</textarea>											
+											</textarea>	
+											<a href="<%=sessionBean.getApplicationBean().getRootServer() %>/rest/text/downloadFileText?fileId=<%=branch.getCurrentLastFileId() %>"
+														target="_blank">
+													<img title="Download text (XML)" src="<%=sessionBean.getApplicationBean().getDownloadImage()%>"/>
+											</a>											
 										</td>
 									</tr>
 								</table>
@@ -283,14 +289,14 @@
 											<th><label class="tableTitle">Version</label></th>
 											<th><label class="tableTitle">User</label></th>
 											<th><label class="tableTitle">Created</label></th>
-											<th><label class="tableTitle">Text</label></th>
-											<th><label class="tableTitle">View in table</label></th>
-											<th><label class="tableTitle">Text(to be published)</label></th>
+											<th><label class="tableTitle">Tagged text (XML)</label></th>
+											<th><label class="tableTitle">View table</label></th>
+											<th><label class="tableTitle">Table in CSV (tab-delimited)</label></th>
 											<th><label class="tableTitle">Upload to LGDataverse</label><br>
 												
 												<% LGFile lastFile = sessionBean.getBranchPage().getLastFile();
 													if(lastFile.getDvId() == null) {%>
-														<button type="button" class="get-studies" data-file-id="<%=lastFile.getId()%>">Upload it</button>
+														<button type="button" class="get-studies" data-file-id="<%=lastFile.getId()%>">Upload the latest version</button>
 													<% } else if (lastFile.getFileIdInDv() == null) { %>
 														<label><i>Uploaded, but it's been deleted from <a href="<%=lastFile.getDatasetUrl() %>" target="_blank"><%= lastFile.getDatasetTitle() %></a></i></label>	
 														<button type="button" class="get-studies" data-file-id="<%=lastFile.getId()%>">Re-upload it</button>
@@ -312,24 +318,39 @@
 												<td><label><%= file.getUsername() %></label></td>
 												<td><label><%= file.getFomattedCreation() %></label></td>
 												<td>
+													<!-- action change to download the file, instead of open file in a new tab -->
+													
+													<a href="<%=sessionBean.getApplicationBean().getRootServer() %>/rest/text/downloadFileText?fileId=<%=file.getId() %>"
+														target="_blank">
+														<img title="Download XML file" src="<%=sessionBean.getApplicationBean().getDownloadImage()%>"/>
+													</a>
+													<!-- 
 													<a href="<%=sessionBean.getApplicationBean().getRootServer() %>/rest/text/getFileText?fileId=<%=file.getId() %>"
 														target="_blank">
 														<img title="Show text" src="<%=sessionBean.getApplicationBean().getShowImage()%>"/>
 													</a>
+													-->
 												</td>
 												<td>
 													<a href="<%=sessionBean.getApplicationBean().getRootServer() %>/rest/text/getTable4File?fileId=<%=file.getId() %>"
 														target="_blank">
-														<img title="Show table" src="<%=sessionBean.getApplicationBean().getShowImage()%>"/>
+														<img title="Show table (html)" src="<%=sessionBean.getApplicationBean().getShowImage()%>"/>
 													</a>												
 												</td>	
 												
 												<!-- add to get tab-delimited file -->
+												<!-- Taction change to download the csv file, instead of open file in a new tab -->
 												<td>
+													<a href="<%=sessionBean.getApplicationBean().getRootServer() %>/rest/text/downloadTabDelimited4File?fileId=<%=file.getId() %>"
+														target="_blank">
+														<img title="Download CSV file (tab-delimited)" src="<%=sessionBean.getApplicationBean().getDownloadImage()%>"/>
+													</a>
+													<!-- 
 													<a href="<%=sessionBean.getApplicationBean().getRootServer() %>/rest/text/getTabDelimited4File?fileId=<%=file.getId() %>"
 														target="_blank">
 														<img title="Show text" src="<%=sessionBean.getApplicationBean().getShowImage()%>"/>
-													</a>												
+													</a>
+													 -->												
 												</td>	
 														
 												<td>
--- a/src/main/webapp/pages/fullTextSearch.jsp	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/webapp/pages/fullTextSearch.jsp	Mon May 02 12:03:30 2016 +0200
@@ -46,6 +46,8 @@
 				dialogSave.dialog( "open" );
 			});
 			
+		
+			
 			var dialogViewSavedResult = $("#dialogViewSavedResult").dialog(
 				{
 					autoOpen: false,
@@ -194,12 +196,19 @@
 									target="_blank">
 							<img title="Show text in html" src="<%=sessionBean.getApplicationBean().getShowImage()%>"/>	
 						</a>
+						
+						<!-- download csv file -->
+						<a href="<%=sessionBean.getApplicationBean().getRootServer() %>/rest/text/downloadFullTextSearchCsvFile?file=<%=aFile.getUserId().toString()%>_<%=aFile.getFileName()%>.csv"
+							target="_blank">
+							<img title="Download CSV" src="<%=sessionBean.getApplicationBean().getDownloadImage()%>"/>
+						</a>
+						
 						<!-- view on LGMap -->
 						<a href="<%=sessionBean.getApplicationBean().getLGMapUrl() %>&file=<%=aFile.getUserId().toString()%>_<%=aFile.getFileName()%>.csv&name=<%=aFile.getSearchTerms() %>"
 									target="_blank">
 							<img title="View on LGMap" src="<%=sessionBean.getApplicationBean().getViewOnMap()%>"/>	
 						</a>
-					
+						
 						<input type="image" title="Delete it"
 							onclick="<%=sessionBean.getApplicationBean().getJSConfirmationDelete() %> setAction0('deleteFile', 'fullTextSearchForm', 'fileId','<%=aFile.getId() %>'); document.getElementById('fullTextSearchForm').submit();" 
 							src="<%=sessionBean.getApplicationBean().getDeleteImage()%>"/>
@@ -226,13 +235,18 @@
 							<img title="Show text in html" src="<%=sessionBean.getApplicationBean().getShowImage()%>"/>	
 						</a>
 					
+						<!-- download csv file -->
+						<a href="<%=sessionBean.getApplicationBean().getRootServer() %>/rest/text/downloadFullTextSearchCsvFile?file=<%=aFile.getUserId().toString()%>_<%=aFile.getFileName()%>.csv"
+							target="_blank">
+							<img title="Download CSV" src="<%=sessionBean.getApplicationBean().getDownloadImage()%>"/>
+						</a>
 			
 						<!-- view on LGMap -->
 						<a href="<%=sessionBean.getApplicationBean().getLGMapUrl() %>&file=<%=aFile.getUserId().toString()%>_<%=aFile.getFileName()%>.csv&name=<%=aFile.getSearchTerms() %>"
 									target="_blank">
 							<img title="View on LGMap" src="<%=sessionBean.getApplicationBean().getViewOnMap()%>"/>	
 						</a>
-					
+							 
 						<input type="image" title="Delete it"
 							onclick="<%=sessionBean.getApplicationBean().getJSConfirmationDelete() %> setAction0('deleteFile', 'fullTextSearchForm', 'fileId','<%=aFile.getId() %>'); document.getElementById('fullTextSearchForm').submit();" 
 							src="<%=sessionBean.getApplicationBean().getDeleteImage()%>"/>
@@ -259,8 +273,14 @@
 							<img title="Show text in html" src="<%=sessionBean.getApplicationBean().getShowImage()%>"/>	
 						</a>
 					
-			
+						<!-- download csv file -->
+						<a href="<%=sessionBean.getApplicationBean().getRootServer() %>/rest/text/downloadFullTextSearchCsvFile?file=<%=aFile.getUserId().toString()%>_<%=aFile.getFileName()%>.csv"
+							target="_blank">
+							<img title="Download CSV" src="<%=sessionBean.getApplicationBean().getDownloadImage()%>"/>
+						</a>
+						
 						<!-- view on LGMap -->
+						
 						<a href="<%=sessionBean.getApplicationBean().getLGMapUrl() %>&file=<%=aFile.getUserId().toString()%>_<%=aFile.getFileName()%>.csv&name=<%=aFile.getSearchTerms() %>"
 									target="_blank">
 							<img title="View on LGMap" src="<%=sessionBean.getApplicationBean().getViewOnMap()%>"/>	
@@ -356,7 +376,7 @@
 				
 				<!-- batching querying -->
 				<!-- for batching, query keyword sets separated by ";" and within each keyword set, keywords separated by "," -->
-				<% if (StringUtils.equals(sessionBean.getUserName(), "zhong") || StringUtils.equals(sessionBean.getUserName(), "silk")) { %>
+				<% if (StringUtils.equals(sessionBean.getUserName(), "zhong")) { // || StringUtils.equals(sessionBean.getUserName(), "silk")) { %>
 				<tr>
 					<td>
 						<input
@@ -385,12 +405,31 @@
 				<tr><td>
 					<button id="saveResult" type="button" class="lgButton">Save Table</button>								
 					<button id="viewSavedResult" type="button" class="lgButton">View/Load Saved Table(s)</button>
+					
+					
 				</td></tr>
+				<tr><td>
+					<!-- for view on LGMap, prompt to save if it's not saved. After saving, it could be shown on LGMap -->
+					<% if (sessionBean.getFullTextSearchPage().getFile() != null) { 
+						LGFullTextSearchFile theFile = sessionBean.getFullTextSearchPage().getFile(); %>
+						<a href="<%=sessionBean.getApplicationBean().getLGMapUrl() %>&file=<%=theFile.getUserId().toString()%>_<%=theFile.getFileName()%>.csv&name=<%=theFile.getSearchTerms() %>"
+								target="_blank">View on LGMap
+						</a>
+						
+						<!-- download csv file -->
+						<a href="<%=sessionBean.getApplicationBean().getRootServer() %>/rest/text/downloadFullTextSearchCsvFile?file=<%=theFile.getUserId().toString()%>_<%=theFile.getFileName()%>.csv"
+							target="_blank">
+							<img title="Download CSV" src="<%=sessionBean.getApplicationBean().getDownloadImage()%>"/>
+						</a>
 					
+					<% } else { %>
+						<!-- prompt to save -->
+						<label class="label">(save table first to view on LGMap)</label>
+					<% } %>
+				</td></tr>	
 				
 				</table>
-		
-		
+	
 	
 			<%
 				if (sessionBean.getFullTextSearchPage().getCompleteList() != null) {
@@ -676,6 +715,8 @@
 									</tr>
 								</table>	
 							</th>
+							
+							<!-- 
 							<th>
 								<table class="sortTable">
 									<tr>
@@ -697,7 +738,8 @@
 									</tr>
 								</table>	
 							</th>
-							<th><label class="tableTitle">View Text</label></th>
+							-->
+							<th><label class="tableTitle">Load Text</label></th>
 							<th>
 								<table class="sortTable">
 									<tr>
@@ -764,8 +806,7 @@
 							<td><%=content.getSection().getBook().getPeriod()%></td>
 							<td><%=content.getSection().getBook().getAdmin_type() %></td>
 							<td><%=content.getSection().getName() %></td>
-							<td><%=content.getSection().getPages()%></td>
-					
+							
 							<!-- View text in Ext-Interface -->
 							<td>
 								<a href="#"
--- a/src/main/webapp/pages/home.jsp	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/webapp/pages/home.jsp	Mon May 02 12:03:30 2016 +0200
@@ -1,4 +1,5 @@
 <%@page import="de.mpiwg.gazetteer.bo.LGBranch"%>
+<%@page import="de.mpiwg.gazetteer.bo.LGTopicSectionRelation"%>
 <%@page import="org.apache.commons.lang.StringUtils"%>
 <%@page import="de.mpiwg.gazetteer.db.DBSection"%>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
@@ -9,13 +10,259 @@
 
 <head>
 	<jsp:include page="../componentes/headContent.jsp"/>	
+	<script>
 	
+		$(function() {
+			
+			
+			$( ".addSectionToTopic" ).click(function() {
+				var sectionId = $( this ).data('section-id');
+				console.log("addSectionToTopic. sectionId = " + sectionId);
+						
+				var url0 = "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/addSectionToTopic.jsp?sectionId=" + sectionId + "&sourceBean=home";
+		
+				$.ajax( url0 )
+				.done(function(data) {
+					$( "#dialogAddSectionToTopicTable" ).replaceWith(data);
+					dialogAddSectionToTopic.dialog( "open" );
+				})
+			  	.fail(function() {
+			    	console.error("Error calling: " + query);
+			  	})
+					
+			});
+			
+			
+			var dialogAddSectionToTopic = $("#dialogAddSectionToTopic").dialog({
+				position: { my: "center", at: "top+400", of: window },	// TODO show dialog at cursor position?
+				autoOpen: false
+			});	  
+			
+			
+			
+			$("#level1Filter").autocomplete({
+				source : function(request, response) {
+					$.ajax({
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/taskLevel1Autocomplete.jsp",
+						type : "POST",
+						dataType : "json",
+						data : {
+							term : request.term
+						},
+						success : function(data) {
+	
+							response($.map(data, function(item) {
+								return {
+									label : item.name,
+									value : item.value,
+								}
+							}));
+						},
+						error : function(error) {
+							alert('error: ' + error);
+						}
+					});
+				},
+				minLength : 0
+			});	
+			
+			$("#level2Filter").autocomplete({
+				source : function(request, response) {
+					$.ajax({
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/taskLevel2Autocomplete.jsp",
+						type : "POST",
+						dataType : "json",
+						data : {
+							term : request.term
+						},
+						success : function(data) {
+	
+							response($.map(data, function(item) {
+								return {
+									label : item.name,
+									value : item.value,
+								}
+							}));
+						},
+						error : function(error) {
+							alert('error: ' + error);
+						}
+					});
+				},
+				minLength : 0
+			});	
+	
+		
+			$("#bookNameFilter").autocomplete({
+				source : function(request, response) {
+					$.ajax({
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/taskBookNameAutocomplete.jsp",
+						type : "POST",
+						dataType : "json",
+						data : {
+							term : request.term
+						},
+						success : function(data) {
+	
+							response($.map(data, function(item) {
+								return {
+									label : item.name,
+									value : item.value,
+								}
+							}));
+						},
+						error : function(error) {
+							alert('error: ' + error);
+						}
+					});
+				},
+				minLength : 0
+			});	
+			
+			
+			$("#dynastyFilter").autocomplete({
+				source : function(request, response) {
+					$.ajax({
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/taskDynastyAutocomplete.jsp",
+						type : "POST",
+						dataType : "json",
+						data : {
+							term : request.term
+						},
+						success : function(data) {
+	
+							response($.map(data, function(item) {
+								return {
+									label : item.name,
+									value : item.value,
+								}
+							}));
+						},
+						error : function(error) {
+							alert('error: ' + error);
+						}
+					});
+				},
+				minLength : 0
+			});	
+		
+			$("#periodFilter").autocomplete({
+				source : function(request, response) {
+					$.ajax({
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/taskPeriodAutocomplete.jsp",
+						type : "POST",
+						dataType : "json",
+						data : {
+							term : request.term
+						},
+						success : function(data) {
+	
+							response($.map(data, function(item) {
+								return {
+									label : item.name,
+									value : item.value,
+								}
+							}));
+						},
+						error : function(error) {
+							alert('error: ' + error);
+						}
+					});
+				},
+				minLength : 0
+			});	
+			
+			$("#adminTypeFilter").autocomplete({
+				source : function(request, response) {
+					$.ajax({
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/taskAdminTypeAutocomplete.jsp",
+						type : "POST",
+						dataType : "json",
+						data : {
+							term : request.term
+						},
+						success : function(data) {
+	
+							response($.map(data, function(item) {
+								return {
+									label : item.name,
+									value : item.value,
+								}
+							}));
+						},
+						error : function(error) {
+							alert('error: ' + error);
+						}
+					});
+				},
+				minLength : 0
+			});	
+			
+			$("#sectionNameFilter").autocomplete({
+				source : function(request, response) {
+					$.ajax({
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/taskSectionNameAutocomplete.jsp",
+						type : "POST",
+						dataType : "json",
+						data : {
+							term : request.term
+						},
+						success : function(data) {
+	
+							response($.map(data, function(item) {
+								return {
+									label : item.name,
+									value : item.value,
+								}
+							}));
+						},
+						error : function(error) {
+							alert('error: ' + error);
+						}
+					});
+				},
+				minLength : 0
+			});	
+			
+			$("#labelFilter").autocomplete({
+				source : function(request, response) {
+					$.ajax({
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/taskLabelAutocomplete.jsp",
+						type : "POST",
+						dataType : "json",
+						data : {
+							term : request.term
+						},
+						success : function(data) {
+	
+							response($.map(data, function(item) {
+								return {
+									label : item.name,
+									value : item.value,
+								}
+							}));
+						},
+						error : function(error) {
+							alert('error: ' + error);
+						}
+					});
+				},
+				minLength : 0
+			});	
+			
+		});
+		
+	</script>
 </head>
 
 <body>
 
 	<jsp:include page="../componentes/template.jsp"/>
-
+	
+	<div id="dialogAddSectionToTopic" title="Add Section(s) into Topic:">
+		<div id="dialogAddSectionToTopicTable"></div>
+	</div>
+	
 	<div id="page">
 		
 		<% if(sessionBean.getUser() == null) { %>
@@ -24,15 +271,13 @@
 			
 			if (sessionBean.getHomePage().getCompleteBranchList() == null){ 
 				sessionBean.getHomePage().loadParameters(request, response);
-				sessionBean.getHomePage().reloadBranches();
+				//sessionBean.getHomePage().reloadBranches();
 			}
-			/*
-			sessionBean.getHomePage().loadParameters(request, response);
 			sessionBean.getHomePage().reloadBranches();
-			*/
+		
 		%>
 		
-		
+			
 		
 		
 		<% if(sessionBean.getHomePage().getCompleteBranchList().isEmpty()) { %>
@@ -43,7 +288,7 @@
 				action="<%=sessionBean.getApplicationBean().getRootServer()%>/proxy.jsp" >
 				<input name="bean" type="hidden" value="homeBean" /> 
 				
-				<div class="subTitel">Your Task
+				<div class="subTitel">Your Tasks
 					<input type="image"
 						onclick="setAction('forceReloadBranches', 'homeForm');"
 						src="<%=sessionBean.getApplicationBean().getRefreshImage()%>" width="20" height="20"/>
@@ -58,6 +303,7 @@
 				<div class="tableDiv double-scroll">
 					<table class="pageTable" >
 						<tr>
+							<!-- remove this to save space 
 							<td>
 								<table class="sortTable">
 									<tr>
@@ -79,7 +325,7 @@
 									</tr>
 								</table>
 							</td>
-							
+							-->
 							<td>
 								<table class="sortTable">
 									<tr>
@@ -132,7 +378,7 @@
 									</tr>
 									<tr>
 										<td>
-											<input type="text" name="bookNameFilter" value="<%= sessionBean.getHomePage().getBookNameFilter()%>" size="8"/>
+											<input type="text" name="bookNameFilter" id="bookNameFilter" value="<%= sessionBean.getHomePage().getBookNameFilter()%>" size="8"/>
 										</td>									
 										<td>
 											<input type="image"
@@ -164,7 +410,7 @@
 									</tr>
 									<tr>
 										<td>
-											<input type="text" name="level1Filter" value="<%= sessionBean.getHomePage().getLevel1Filter()%>" size="8"/>
+											<input type="text" class="filterInput"  name="level1Filter" id="level1Filter" value="<%= sessionBean.getHomePage().getLevel1Filter()%>" size="8"/>
 										</td>									
 										<td>
 											<input type="image"
@@ -195,7 +441,7 @@
 									</tr>
 									<tr>
 										<td>
-											<input type="text" name="level2Filter" value="<%= sessionBean.getHomePage().getLevel2Filter()%>" size="8"/>
+											<input type="text" name="level2Filter" id="level2Filter" value="<%= sessionBean.getHomePage().getLevel2Filter()%>" size="8"/>
 										</td>									
 										<td>
 											<input type="image"
@@ -226,7 +472,7 @@
 									</tr>
 									<tr>
 										<td>
-											<input type="text" name="dynastyFilter" value="<%= sessionBean.getHomePage().getDynastyFilter()%>" size="8"/>
+											<input type="text" name="dynastyFilter" id="dynastyFilter" value="<%= sessionBean.getHomePage().getDynastyFilter()%>" size="8"/>
 										</td>									
 										<td>
 											<input type="image"
@@ -257,7 +503,7 @@
 									</tr>
 									<tr>
 										<td>
-											<input type="text" name="periodFilter" value="<%= sessionBean.getHomePage().getPeriodFilter()%>" size="8"/>
+											<input type="text" name="periodFilter" id="periodFilter" value="<%= sessionBean.getHomePage().getPeriodFilter()%>" size="8"/>
 										</td>									
 										<td>
 											<input type="image"
@@ -288,7 +534,7 @@
 									</tr>
 									<tr>
 										<td>
-											<input type="text" name="adminTypeFilter" value="<%= sessionBean.getHomePage().getAdminTypeFilter()%>" size="8"/>
+											<input type="text" name="adminTypeFilter" id="adminTypeFilter" value="<%= sessionBean.getHomePage().getAdminTypeFilter()%>" size="8"/>
 										</td>									
 										<td>
 											<input type="image"
@@ -319,7 +565,7 @@
 									</tr>
 									<tr>
 										<td>
-											<input type="text" name="sectionNameFilter" value="<%= sessionBean.getHomePage().getSectionNameFilter()%>" size="8"/>
+											<input type="text" name="sectionNameFilter" id="sectionNameFilter" value="<%= sessionBean.getHomePage().getSectionNameFilter()%>" size="8"/>
 										</td>									
 										<td>
 											<input type="image"
@@ -371,7 +617,7 @@
 									</tr>
 									<tr>
 										<td>
-											<input type="text" name="labelFilter" size="20" value="<%= sessionBean.getHomePage().getLabelFilter()%>" size="8"/>
+											<input type="text" name="labelFilter"  id="labelFilter" size="20" value="<%= sessionBean.getHomePage().getLabelFilter()%>" size="8"/>
 										</td>									
 										<td>
 											<input type="image"
@@ -385,7 +631,7 @@
 							<td>
 								<table class="sortTable">
 									<tr>
-										<td><label class="tableTitle">Last Modified</label></td>
+										<td><label class="tableTitle">Last Saved</label></td>
 										<td>
 											<table>
 												<tr><td>
@@ -404,7 +650,7 @@
 									
 								</table>
 							</td>
-							<td><label class="tableTitle">Extraction Interface</label></td>
+							<td><label class="tableTitle">Load Text</label></td>
 							<td>
 								<table class="sortTable">
 									<tr>
@@ -430,13 +676,13 @@
 							</td>
 							
 							<td><label class="tableTitle">Manage</label></td>
+							<td><label class="tableTitle">Add to Topic</label></td>
 							<td><label class="tableTitle">Delete</label></td>
 						</tr>	
 						
 						<% for (LGBranch branch : sessionBean.getHomePage().getDisplayBranchList() ) {
 						%>
 						<tr>
-							<td><%=branch.getId() %></td>
 							<td><%=branch.getBook().getId() %></td>
 							<td><%=branch.getBook().getName() %></td>
 							<td><%=branch.getBook().getLevel1() %></td>	
@@ -461,7 +707,7 @@
 							</td>
 							<td><%=branch.getFomattedLastChange() %></td>
 							<td>
-								<a onclick="branchInExtractionInterface('<%=branch.getId() %>', '<%=branch.getCurrentLastFileId() %>', '<%=branch.getSectionId() %>', '<%=branch.getSection().getName() %>', '<%=branch.getBook().getId() %>', '<%=branch.getBook().getName() %>', '<%=sessionBean.getUser().getId() %>', '<%=sessionBean.getApplicationBean().getExtractionInterfaceUrl() %>');">
+								<a onclick="branchInExtractionInterface('<%=branch.getId() %>', '<%=branch.getCurrentLastFileId() %>', '<%=branch.getSectionId() %>', '<%=branch.getSection().getName() %>', '<%=branch.getBook().getId() %>', '<%=branch.getBook().getName() %>', '<%=sessionBean.getUser().getId() %>', '<%=sessionBean.getApplicationBean().getExtractionInterfaceUrl()%>');">
 									<img title="Show Task in Extraction Interface" src="<%=sessionBean.getApplicationBean().getShowImage()%>"/>
 								</a>
 							</td>
@@ -469,11 +715,44 @@
 							<td>
 								<%= (branch.isPublished()) ? "V":"" %>	
 							</td>
+							
+							<!-- Manage -->
 							<td>
 								<a href="<%=sessionBean.getApplicationBean().getRootServer() %>/pages/branchPage.jsp?branchId=<%=branch.getId() %>" >
 									<img title="Manage the task" src="<%=sessionBean.getApplicationBean().getEditBranchImage()%>"/>
 								</a>
 							</td>
+							
+							<!-- Add to Topic -->
+							<td style="max-width:300px;">
+								<!-- existing topic -->
+								<% if(branch.getSection().getTopicSectionRelation() != null && !branch.getSection().getTopicSectionRelation().isEmpty()) { %>
+									<lable>Already in topic: </lable>
+									<table style="width:100%">		
+										<% for(LGTopicSectionRelation relation : branch.getSection().getTopicSectionRelation()) { %>
+											<tr>
+												<td>
+													<table style="width:100%; min-width:100px">
+													<tr><td><%=relation.getTopic().info() %></td></tr>
+													</table>
+												</td>
+												<td style="max-width:150px">
+													
+													<a href="<%=sessionBean.getApplicationBean().getRootServer() %>/pages/topicPage.jsp?topicId=<%=relation.getTopicId() %>" >
+														<img title="Manage Topic" src="<%=sessionBean.getApplicationBean().getEditBranchImage()%>"/>
+													</a>												
+													
+												</td>
+											</tr>
+										<% } %>
+									</table>
+								<% } %>
+								
+								<img width="10" height="10" title="Add the section to Topic" src="<%=sessionBean.getApplicationBean().getPlusImage()%>" data-section-id="<%=branch.getSection().getId()%>" class="addSectionToTopic">
+					
+							</td>
+									
+							<!-- Delete -->
 							<td>
 								<input type="image" title="Delete it"
 									onclick="<%=sessionBean.getApplicationBean().getJSConfirmationDelete() %> deleteBranch('deleteBranch', 'homeForm', '<%=branch.getId() %>');" 
--- a/src/main/webapp/pages/search.jsp	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/webapp/pages/search.jsp	Mon May 02 12:03:30 2016 +0200
@@ -43,7 +43,7 @@
 				var sectionId = $( this ).data('section-id');
 				//console.log("addSectionToTopic. sectionId = " + sectionId);
 						
-				var url0 = "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/addSectionToTopic.jsp?sectionId=" + sectionId;
+				var url0 = "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/addSectionToTopic.jsp?sectionId=" + sectionId + "&sourceBean=search";
 		
 				$.ajax( url0 )
 				.done(function(data) {
@@ -120,6 +120,32 @@
 				minLength : 0
 			});
 			
+			$("#bookNameFilter").autocomplete({
+				source : function(request, response) {
+					$.ajax({
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/bookNameAutocomplete.jsp",
+						type : "POST",
+						dataType : "json",
+						data : {
+							term : request.term
+						},
+						success : function(data) {
+	
+							response($.map(data, function(item) {
+								return {
+									label : item.name,
+									value : item.value,
+								}
+							}));
+						},
+						error : function(error) {
+							alert('error: ' + error);
+						}
+					});
+				},
+				minLength : 0
+			});	
+	
 			$("#dynastyFilter").autocomplete({
 				source : function(request, response) {
 					$.ajax({
@@ -145,6 +171,7 @@
 				},
 				minLength : 0
 			});	
+	
 			
 			$("#level1Filter").autocomplete({
 				source : function(request, response) {
@@ -170,8 +197,63 @@
 					});
 				},
 				minLength : 0
+			});	
+			
+
+			$("#level2Filter").autocomplete({
+				source : function(request, response) {
+					$.ajax({
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/level2Autocomplete.jsp",
+						type : "POST",
+						dataType : "json",
+						data : {
+							term : request.term
+						},
+						success : function(data) {
+	
+							response($.map(data, function(item) {
+								return {
+									label : item.name,
+									value : item.value,
+								}
+							}));
+						},
+						error : function(error) {
+							alert('error: ' + error);
+						}
+					});
+				},
+				minLength : 0
 			});		
 			
+			
+			$("#periodFilter").autocomplete({
+				source : function(request, response) {
+					$.ajax({
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/periodAutocomplete.jsp",
+						type : "POST",
+						dataType : "json",
+						data : {
+							term : request.term
+						},
+						success : function(data) {
+	
+							response($.map(data, function(item) {
+								return {
+									label : item.name,
+									value : item.value,
+								}
+							}));
+						},
+						error : function(error) {
+							alert('error: ' + error);
+						}
+					});
+				},
+				minLength : 0
+			});	
+	
+			
 			$("#adminTypeFilter").autocomplete({
 				source : function(request, response) {
 					$.ajax({
@@ -197,9 +279,56 @@
 				},
 				minLength : 0
 			});		
+			
+			$("#sectionNameFilter").autocomplete({
+				source : function(request, response) {
+					$.ajax({
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/sectionNameAutocomplete.jsp",
+						type : "POST",
+						dataType : "json",
+						data : {
+							term : request.term
+						},
+						success : function(data) {
+	
+							response($.map(data, function(item) {
+								return {
+									label : item.name,
+									value : item.value,
+								}
+							}));
+						},
+						error : function(error) {
+							alert('error: ' + error);
+						}
+					});
+				},
+				minLength : 0
+			});	
+			
 				
+			// enter pressed event, we don't want to always go to "search".
+			$(document).keypress(
+				function(event){
+					if (event.which == '13') {	// enter pressed
+						// if any of the filter fields is filled in, filter first; otherwize, go to search
+						$(".filterInput" ).each(function( i ) {
+							//console.log( this.value );
+							if (this.value != "") {
+								//console.log('filtering' + i);
+								setAction('filter', 'searchForm');
+								$("#searchForm").submit();
+								return false;		
+							}
+							
+						});
+				    }
+			});
+			
+			
+			
 		});
-	
+		
 		
 	</script>
 </head>
@@ -314,6 +443,16 @@
 													</table>
 												</td>
 											</tr>
+											<tr>
+												<td>
+													<input type="text" class="filterInput" name="bookNameFilter" id="bookNameFilter" value="<%= sessionBean.getSearchPage().getBookNameFilter()%>"/>
+												</td>									
+												<td>
+													<input type="image"
+														onclick="setAction('filter', 'searchForm');"
+														src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
+												</td>							
+											</tr>
 										</table>					
 									</th>
 									<th>
@@ -347,7 +486,39 @@
 											</tr>								
 										</table>	
 									</th>
-									<th><label class="tableTitle">Level 2</label></th>
+									<th>
+										
+										<table class="sortTable">
+											<tr>
+												<td><label class="tableTitle">Level 2</label></td>
+												<td>
+													<table>
+														<tr><td>
+															<input type="image"
+																onclick="setAction('sortByLevel2Up', 'searchForm');"
+																src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>
+														</td></tr>
+														<tr><td>
+															<input type="image"
+																onclick="setAction('sortByLevel2Down', 'searchForm');"
+																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
+														</td></tr>
+													</table>
+												</td>
+											</tr>
+											<tr>
+												<td>
+													<input type="text" class="filterInput" name="level2Filter" id="level2Filter" value="<%= sessionBean.getSearchPage().getLevel2Filter()%>"/>
+												</td>									
+												<td>
+													<input type="image"
+														onclick="setAction('filter', 'searchForm');"
+														src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
+												</td>							
+											</tr>								
+										</table>
+									
+									</th>
 									<th>
 										<table class="sortTable">
 											<tr>
@@ -398,6 +569,16 @@
 													</table>
 												</td>
 											</tr>
+											<tr>
+												<td>
+													<input type="text" class="filterInput" name="periodFilter" id="periodFilter" value="<%= sessionBean.getSearchPage().getPeriodFilter()%>"/>
+												</td>									
+												<td>
+													<input type="image"
+														onclick="setAction('filter', 'searchForm');"
+														src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
+												</td>							
+											</tr>
 										</table>						
 									</th>
 									<th>
@@ -450,6 +631,16 @@
 													</table>
 												</td>
 											</tr>
+											<tr>
+												<td>
+													<input type="text" class="filterInput" name="sectionNameFilter" id="sectionNameFilter" value="<%= sessionBean.getSearchPage().getSectionNameFilter()%>"/>
+												</td>									
+												<td>
+													<input type="image"
+														onclick="setAction('filter', 'searchForm');"
+														src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
+												</td>							
+											</tr>	
 										</table>	
 									</th>
 									<th>
@@ -474,7 +665,7 @@
 										</table>							
 									
 									</th>
-									<th><label class="tableTitle">View Text</label></th>
+									<th><label class="tableTitle">Load Text</label></th>
 									
 									<th>
 										<label class="tableTitle">Add to Topic</label>
--- a/src/main/webapp/pages/topicPage.jsp	Wed Feb 17 14:58:19 2016 +0100
+++ b/src/main/webapp/pages/topicPage.jsp	Mon May 02 12:03:30 2016 +0200
@@ -213,8 +213,8 @@
 										<th><label class="tableTitle">Admin Type</label></th>
 										<th><label class="tableTitle">Section Name</label></th>
 										<th><label class="tableTitle">Section Pages</label></th>
-										<th><label class="tableTitle">View Text</label></th>
-										<th><label class="tableTitle">Existing Tasks</label></th>
+										<th><label class="tableTitle">Load Text (Plain)</label></th>
+										<th><label class="tableTitle">Load tagged text in Extraction Interface</label></th>
 										<th><label class="tableTitle">Remove</label></th>
 									</tr>	
 									
@@ -536,8 +536,8 @@
 										</table>
 									</th>
 									
-									<th><label class="tableTitle">View Text</label></th>
-									<th><label class="tableTitle">Existing Tasks</label></th>
+									<th><label class="tableTitle">Load Text (Plain)</label></th>
+									<th><label class="tableTitle">Load tagged text in Extraction Interface</label></th>
 									<th><label class="tableTitle">Remove</label></th>
 								</tr>	
 								
@@ -581,9 +581,22 @@
 														</td>
 														<td style="max-width:150px">
 															<% if (branch.hasContributor(sessionBean.getUser().getId())) { %>
-															<a href="<%=sessionBean.getApplicationBean().getRootServer() %>/pages/branchPage.jsp?branchId=<%=branch.getId() %>" >
-																<img title="Manage Branch" src="<%=sessionBean.getApplicationBean().getEditBranchImage()%>"/>
-															</a>												
+															
+															<table style="width:100%">
+																<tr><td>
+																	<a href="<%=sessionBean.getApplicationBean().getRootServer() %>/pages/branchPage.jsp?branchId=<%=branch.getId() %>" >
+																		<img title="Manage Branch" src="<%=sessionBean.getApplicationBean().getEditBranchImage()%>"/>
+																	</a>
+																</td></tr>
+																<tr><td>
+																	<!-- view text for the latest version -->
+																	<a onclick="branchInExtractionInterface('<%=branch.getId() %>', '<%=branch.getCurrentLastFileId() %>', '<%=branch.getSectionId() %>', '<%=branch.getSection().getName() %>', '<%=branch.getBook().getId() %>', '<%=branch.getBook().getName() %>', '<%=sessionBean.getUser().getId() %>', '<%=sessionBean.getApplicationBean().getExtractionInterfaceUrl() %>');">
+																		<img title="Show Task in Extraction Interface" src="<%=sessionBean.getApplicationBean().getShowImage()%>"/>
+																	</a>
+																		
+																</td></tr>
+															</table>
+																											
 															<% } else { %>
 																<label>Contributors: <%=branch.getContributorsNameList() %></label>
 															<% } %>
Binary file src/main/webapp/resources/images/download.png has changed