Commit 2c16031f authored by Matija Obreza's avatar Matija Obreza
Browse files

Switch from /acn to Explorer

parent 125c6455
...@@ -13,7 +13,6 @@ encoding//src/main/resources/content/language_zh.properties=UTF-8 ...@@ -13,7 +13,6 @@ encoding//src/main/resources/content/language_zh.properties=UTF-8
encoding//src/main/webapp/WEB-INF/decorator/header.jsp=UTF-8 encoding//src/main/webapp/WEB-INF/decorator/header.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/accession/data.jsp=UTF-8 encoding//src/main/webapp/WEB-INF/jsp/accession/data.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/descr/index.jsp=UTF-8 encoding//src/main/webapp/WEB-INF/jsp/descr/index.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/filter/index.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/login.jsp=UTF-8 encoding//src/main/webapp/WEB-INF/jsp/login.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/metadata/index.jsp=UTF-8 encoding//src/main/webapp/WEB-INF/jsp/metadata/index.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/metadata/view.jsp=UTF-8 encoding//src/main/webapp/WEB-INF/jsp/metadata/view.jsp=UTF-8
......
...@@ -118,22 +118,6 @@ public class AccessionController extends BaseController { ...@@ -118,22 +118,6 @@ public class AccessionController extends BaseController {
return "/accession/resolve"; return "/accession/resolve";
} }
/**
* Browse all
*
* @param model
* @param page
* @return
*/
@RequestMapping("/")
public String viewAll(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
Page<Accession> accessions = genesysService.listAccessions(new PageRequest(page - 1, 50, new Sort("accessionName")));
_logger.info("Got: " + accessions);
model.addAttribute("pagedData", accessions);
return "/accession/data";
}
/** /**
* View by Taxonomy * View by Taxonomy
* *
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package org.genesys2.server.servlet.controller; package org.genesys2.server.servlet.controller;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
...@@ -193,15 +194,27 @@ public class ExplorerController extends BaseController { ...@@ -193,15 +194,27 @@ public class ExplorerController extends BaseController {
} }
} }
model.addAttribute("selectedFilters", filterService.selectFilters(selectedFilters));
try { try {
JsonNode jsonTree = mapper.readTree(jsonFilter); ObjectNode jsonTree = (ObjectNode) mapper.readTree(jsonFilter);
// Add missing filters to pick list
List<String> l1 = new ArrayList<String>(selectedFilters.length * 2);
l1.addAll(Arrays.asList(selectedFilters));
for (String filter : IteratorUtils.toList(jsonTree.fieldNames())) {
if (!l1.contains(filter)) {
l1.add(filter);
}
}
selectedFilters = (String[]) l1.toArray(new String[l1.size()]);
model.addAttribute("jsonFilter", jsonTree.toString()); model.addAttribute("jsonFilter", jsonTree.toString());
} catch (NullPointerException | IOException e) { } catch (NullPointerException | IOException e) {
_logger.warn(e.getMessage(), e); _logger.warn(e.getMessage(), e);
} }
model.addAttribute("selectedFilters", filterService.selectFilters(selectedFilters));
try { try {
if (selectedFilters != null && selectedFilters.length > 0) if (selectedFilters != null && selectedFilters.length > 0)
model.addAttribute("pick", mapper.writeValueAsString(selectedFilters)); model.addAttribute("pick", mapper.writeValueAsString(selectedFilters));
......
/**
* Copyright 2013 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.servlet.controller;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map.Entry;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TaxonomyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@Controller
@RequestMapping("/acn")
public class FilterController extends BaseController {
@Autowired
private InstituteService instituteService;
@Autowired
private GenesysService genesysService;
@Autowired
private GenesysFilterService filterService;
@Autowired
private TaxonomyService taxonomyService;
@RequestMapping("/filter")
public String see(ModelMap model, @RequestParam(value = "filter", required = false, defaultValue = "{}") String jsonFilter) {
_logger.info("Filtering by: " + jsonFilter);
// What filters do we support?
model.addAttribute("availableFilters", filterService.listAvailableFilters());
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonTree = null;
try {
jsonTree = mapper.readTree(jsonFilter);
_logger.debug(jsonTree.toString());
model.addAttribute("jsonString", jsonTree.toString());
model.addAttribute("jsonFilter", jsonTree);
Iterator<Entry<String, JsonNode>> fields = jsonTree.fields();
while (fields.hasNext()) {
Entry<String, JsonNode> entry = fields.next();
_logger.debug("2=" + entry.getKey() + " = " + entry.getValue());
}
} catch (IOException e) {
_logger.error("Invalid JSON filter:" + e.getMessage(), e);
}
return "/filter/index";
}
/**
* Browse all
*
* @param model
* @param page
* @return
*/
@RequestMapping("/f")
public String viewFiltered(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page,
@RequestParam(value = "filter", required = true, defaultValue = "{}") String jsonFilter) {
_logger.info("Filtering by: " + jsonFilter);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonTree = null;
try {
jsonTree = mapper.readTree(jsonFilter);
_logger.debug(jsonTree.toString());
model.addAttribute("jsonString", jsonTree.toString());
model.addAttribute("jsonFilter", jsonTree);
Iterator<Entry<String, JsonNode>> fields = jsonTree.fields();
while (fields.hasNext()) {
Entry<String, JsonNode> entry = fields.next();
_logger.debug("2=" + entry.getKey() + " = " + entry.getValue());
}
} catch (IOException e) {
e.printStackTrace();
}
Page<Accession> accessions = filterService.listAccessions(jsonTree, new PageRequest(page - 1, 50, new Sort("acceNumb")));
_logger.info("Got: " + accessions);
model.addAttribute("pagedData", accessions);
return "/accession/data";
}
}
...@@ -310,6 +310,7 @@ filters.view=Current filters ...@@ -310,6 +310,7 @@ filters.view=Current filters
filters.data-is-filtered=The data is filtered. filters.data-is-filtered=The data is filtered.
filters.modify-filters=View & Modify filters filters.modify-filters=View & Modify filters
filter.taxonomy=Taxonomy filter.taxonomy=Taxonomy
filter.inTrust=ITPGRFA Art. 15 accession
filter.accenumb=Accession name filter.accenumb=Accession name
filter.crop=Crop filter.crop=Crop
filter.countryOfOrigin=Country of Origin filter.countryOfOrigin=Country of Origin
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
<c:forEach items="${codeMap.keySet()}" var="key" varStatus="status"> <c:forEach items="${codeMap.keySet()}" var="key" varStatus="status">
<li class="${status.count % 2 == 0 ? 'even' : 'odd'}"> <li class="${status.count % 2 == 0 ? 'even' : 'odd'}">
<span class="method-code"><c:out value="${key}" /></span> <span class="method-code"><c:out value="${key}" /></span>
<a title="<spring:message code="view.accessions" />" href="<c:url value="/acn/f"><c:param name="filter">{"gm:${method.id}":["${key}"]}</c:param></c:url>"> <a title="<spring:message code="view.accessions" />" href="<c:url value="/explore"><c:param name="crop" value="${trait.crop.shortName}" /><c:param name="filter">{"gm:${method.id}":["${key}"]}</c:param></c:url>">
<c:out value="${codeMap[key]}" /> <c:out value="${codeMap[key]}" />
</a> </a>
count=${codeStatistics[key]} count=${codeStatistics[key]}
......
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<html>
<head>
<title><spring:message code="filters.page.title" /></title>
</head>
<body>
<h1><spring:message code="filters.view" /></h1>
<div id="allfilters">
<c:forEach items="${availableFilters}" var="filter">
<div class="clearfix filter-block">
<div class="pull-left filter-name"><spring:message code="filter.${filter.name}" /></div>
<div class="pull-left" id="filter-${filter.name.replace(':', '_')}">
<c:choose>
<c:when test="${filter.dataType=='NUMERIC'}">
<div class="filter-new form-group pull-left input-group"><span class="input-group-btn"><input class="span1 form-control" type="text" /><input class="span1 form-control" type="text" /><button class="btn notimportant">+</button></span></div>
</c:when>
<c:when test="${filter.dataType=='BOOLEAN'}">
<div class="filter-new pull-left"><select><option value="true"><spring:message code="boolean.true" /></option><option value="false"><spring:message code="boolean.false" /></option><option value="null"><spring:message code="boolean.null" /></option></select><button class="notimportant">+</button></div>
</c:when>
<c:otherwise>
<div class="filter-new form-group pull-left input-group"><span class="input-group-btn"><input class="span2 form-control" type="text" /><button class="btn notimportant">+</button></span></div>
</c:otherwise>
</c:choose>
<div class="filter-values pull-left"></div>
</div>
</div>
</c:forEach>
<div class="clearfix">
<a id="filtersHref" href=""><button class="btn btn-green pull-left">View!</button></a>
</div>
</div>
<div id="filtersJson">${jsonObject}</div>
<content tag="javascript">
<script type="text/javascript">
jQuery(document).ready(function() {
// alert('${jsonString}');
var filters={};
try {
filters=$.parseJSON('${jsonString}');
} catch (e) {filters={}; console.error(e);}
// debugger;
console.log("Filters: " +JSON.stringify(filters));
var FF = {
updateValues: function(id, filterName, values) {
var c=$(id);
c.closest(".clearfix").attr("x-filtername", filterName)
//alert(c.data("filtername"));
c.empty();
if (values==null) return;
values.forEach(function(i, idx) {
console.log("Adding: " + i);
//debugger;
if ($.isPlainObject(i)) {
// ranges & ops
var x="<div class='filtval complex'>";
if (i["range"]!=null) {
x+="Between " + i["range"][0] + " and " + i["range"][1];
} else if (i["min"]!=null) {
x+="More than " + i["min"];
} else if (i["max"]!=null) {
x+="Less than " + i["max"];
}
x+="</div>";
} else {
var x="<div class='filtval discrete'>" + i + "</div>";
}
c.append(x);
});
},
refreshJson: function(newFilter) {
$("#filtersJson").html(JSON.stringify(newFilter));
$("#filtersHref").attr("href", "/acn/f?filter="+JSON.stringify(newFilter));
},
addFilterValue: function(element) {
var name=$(element).closest(".clearfix").attr("x-filtername").replace('_',':');
//debugger;
var a=null, b=null;
var inputs=$(element).parent().children("input");
var selects=$(element).parent().children("select");
var r=null;
if (inputs.length==1) {
// add 1
a=inputs[0].value.trim();
if (a!='') r=a;
} else if (inputs.length==2) {
a=inputs[0].value.trim();
b=inputs[1].value.trim();
if (a=='' && b=='') {
} else if (a==b) {
r=a;
} else if (b=='') {
r={"min":parseFloat(a)};
if (isNaN(r["min"])) r=null;
} else if (a=='') {
r={"max":parseFloat(b)};
if (isNaN(r["max"])) r=null;
} else {
r={"range":[parseFloat(a),parseFloat(b)]};
if (isNaN(r["range"][0]) || isNaN(r["range"][1])) r=null;
}
} else if (selects.length==1) {
a=selects[0].value;
r = (a == 'true' ? true : a=='null' ? 'null' : false);
}
console.log(r);
if (r!=null) {
r = (r=='null' ? null : r);
if (filters[name]==null) {
filters[name]=[r];
} else {
filters[name][filters[name].length]=r;
}
if (inputs[0]) { inputs[0].value=''; inputs[0].focus(); }
if (inputs[1]) inputs[1].value='';
}
console.log(filters);
filters=FF.cleanup(filters);
console.log(filters);
FF.refreshJson(filters);
FF.updateValues("#filter-" + name + " .filter-values", name, filters[name]);
},
cleanup: function(filt) {
var newFilt={};
for (var prop in filt) {
console.log("Yada: " + prop);
var nv=newFilt[prop]=[];
for (var i=0; i<filt[prop].length; i++) {
var pos=nv.indexOf(filt[prop][i]);
if (pos<0) nv[nv.length]=filt[prop][i];
}
}
return newFilt;
}
};
[<c:forEach items="${availableFilters}" var="filter" varStatus="status">${status.index gt 0 ? ',' : ''} "${filter.name.replace(':','_')}"</c:forEach> ].forEach(function(name) {
FF.updateValues("#filter-" + name + " .filter-values", name, filters[name]);
});
$("body").on("click", ".filter-block .filtval", function(event) {
event.preventDefault();
var idx=$(this).index();
var name=$(this).closest(".clearfix").attr("x-filtername");
//debugger;
console.log("Delete! " + idx + " from " + name);
filters[name].splice(idx, 1);
if (filters[name].length==0)
delete filters[name];
console.log(filters[name]);
$(this).remove();
FF.refreshJson(filters);
});
$("body").on("click", ".filter-block .filter-new button", function(event) {
event.preventDefault();
FF.addFilterValue(this);
});
$("body").on("keydown", ".filter-block .filter-new input", function(event) {
if (event.keyCode==13) {
event.preventDefault();
FF.addFilterValue(this);
}
});
FF.refreshJson(filters);
});
</script>
</content>
</body>
</html>
\ No newline at end of file
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
</h1> </h1>
<div class="main-col-header"> <div class="main-col-header">
<a href="<c:url value="/acn/f?filter={"mls":[true]}" />"><spring:message code="view.accessions" /></a> <a href="<c:url value="/explore"><c:param name="filter" value='{"mls":[true]}' /></c:url>"><spring:message code="view.accessions" /></a>
</div> </div>
<%@include file="/WEB-INF/jsp/content/include/blurp-display.jsp"%> <%@include file="/WEB-INF/jsp/content/include/blurp-display.jsp"%>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment