Commit 3705c8b3 authored by igoshin's avatar igoshin Committed by Matija Obreza
Browse files

Enabled additional filters, enabled toggle "edit filter"

#11886
parent 3513c410
......@@ -25,12 +25,13 @@ import org.apache.commons.collections4.IteratorUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.genesys.Parameter;
import org.genesys2.server.model.genesys.ParameterCategory;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.service.*;
import org.genesys2.server.service.impl.GenesysFilterServiceImpl.LabelValue;
import org.genesys2.spring.ResourceNotFoundException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
......@@ -276,6 +277,9 @@ public class ExplorerController extends BaseController {
@RequestParam(value = "filter", required = true, defaultValue = "{}") String jsonFilter,
@RequestParam(value = "pick", required = false) String jsonPick) {
String[] selectedFilters =new String[0];
jsonFilter=jsonFilter.replaceAll("_",":");
if (StringUtils.isNotBlank(jsonPick)) {
// Cleanup JSON pick
try {
......@@ -287,8 +291,29 @@ public class ExplorerController extends BaseController {
pick.put(key,key);
}
JsonNode jsonTree = mapper.readTree(jsonPick);
model.addAttribute("test",new JSONObject(filters));
JsonNode jsonTree = mapper.readTree(jsonPick);
if (filters.get("crop") != null) {
String shortName = filters.get("crop").get(0);
// Add crop descriptors
Crop crop = cropService.getCrop(shortName);
if (crop != null) {
List<ParameterCategory> categories = traitService.listCategories();
Map<ParameterCategory, List<Parameter>> descriptors = traitService.mapTraits(crop, categories);
Map<Long, List<Method>> methods = traitService.mapMethods(crop);
model.addAttribute("crop", crop);
model.addAttribute("categories", categories);
model.addAttribute("descriptors", descriptors);
model.addAttribute("methods", methods);
String[] array = convertToPickString(categories, descriptors, methods);
selectedFilters = mapper.readValue(Arrays.toString(array), selectedFilters.getClass());
}
}
model.addAttribute("filters",filters);
model.addAttribute("pick",pick);
model.addAttribute("jsonPick", jsonTree.toString());
......@@ -301,11 +326,11 @@ public class ExplorerController extends BaseController {
_logger.info("Filtering by: " + jsonFilter);
ObjectNode jsonTree = null;
try {
jsonTree = (ObjectNode) mapper.readTree(jsonFilter);
jsonTree = (ObjectNode) mapper.readTree(jsonFilter.replaceAll("gm:","gm_"));
_logger.debug(jsonTree.toString());
if (model.containsAttribute("crop")) {
jsonTree.remove("crop");
// jsonTree.remove("crop");
model.addAttribute("jsonFilter", jsonTree.toString());
// Replace any other crop filters...
......@@ -323,12 +348,45 @@ public class ExplorerController extends BaseController {
Page<Accession> accessions = filterService.listAccessions(jsonTree, new PageRequest(page - 1, 50, new Sort("acceNumb")));
_logger.info("Got: " + accessions);
List<GenesysFilterService.GenesysFilter> additionalFilters = filterService.selectFilters(selectedFilters);
List<GenesysFilterService.GenesysFilter> availableFilters =filterService.listAvailableFilters();
List<GenesysFilterService.GenesysFilter> allFilters=new ArrayList<>();
allFilters.addAll(availableFilters);
allFilters.addAll(additionalFilters);
model.addAttribute("crops", cropService.list(getLocale()));
model.addAttribute("pagedData", accessions);
model.addAttribute("availableFilters", filterService.listAvailableFilters());
model.addAttribute("availableFilters", availableFilters);
model.addAttribute("additionalFilters", additionalFilters);
model.addAttribute("allFilters", allFilters);
return "/accession/explore_new";
}
@RequestMapping(value = "/explore/ac/{field}", produces = MediaType.APPLICATION_JSON_VALUE)
private String[] convertToPickString(List<ParameterCategory> categories, Map<ParameterCategory, List<Parameter>> descriptors, Map<Long, List<Method>> methods) {
List<String> s = new ArrayList<>();
for (ParameterCategory category : categories) {
List<Parameter> desc = descriptors.get(category);
for (Parameter descriptor : desc) {
List<Method> meth = methods.get(descriptor.getId());
if (meth != null) {
for (Method method : meth) {
String value="\"gm:"+ method.getId()+"\"";
s.add(value);
}
}
}
}
return s.toArray(new String[s.size()]);
}
@RequestMapping(value = "/explore/ac/{field}", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<LabelValue<String>> autocomplete(@PathVariable("field") String filter, @RequestParam(value = "term", required = false) String ac) {
return filterService.autocomplete(filter, ac);
......
......@@ -336,7 +336,9 @@ filter.mlsStat=MLS status of the accession
filter.available=Available for distribution
filter.download-dwca=Download DwCA
filter.add=Add filter
filter.additional=Additional filters
filter.apply=Apply
filter.close=Close
search.page.title=Full-text Search
search.no-results=No matches found for your query.
......
......@@ -15,11 +15,10 @@
<ul class="nav nav-pills">
<li class="dropdown form-horizontal" id="menu1">
<a class="btn btn-default dropdown-toggle" data-toggle="dropdown" href="#">
<spring:message code="filter.add"/>
<b class="glyphicon-plus"></b>
</a>
<a class="btn btn-default dropdown-toggle" data-toggle="dropdown" href="#">
<spring:message code="filter.add"/>
<b class="glyphicon-plus"></b>
</a>
<ul class="dropdown-menu">
<c:forEach items="${availableFilters}" var="filter">
......@@ -27,7 +26,18 @@
<spring:message code="filter.${filter.key}"/></a></li>
</c:forEach>
</ul>
</li>
<c:if test="${crop != null}">
<li class="dropdown form-horizontal" id="menu2">
<a class="btn btn-default" data-toggle="modal" data-target="#myModal">
<spring:message code="filter.additional"/>
<b class="glyphicon-plus"></b>
</a>
</li>
</c:if>
</ul>
<div class="nav-header">
......@@ -57,80 +67,130 @@
<%--Filters--%>
<div id="allfilters">
<div class="row">
<div style="text-align: center">
<button class="btn btn-green apply"><spring:message code="filter.apply"/></button>
</div>
</div>
<c:forEach items="${allFilters}" var="filter">
<c:forEach items="${availableFilters}" var="filter">
<c:set var="normalizedKey" value="${filter.key.replace(':', '_')}"/>
<c:set var="filterKey" value="${filter.key}"/>
<div class="clearfix filter-block" style="display:${pick[filter.key] eq filter.key ? '' : 'none'}"
id="${filter.key}_filter" key="${filter.key}">
<div class="clearfix filter-block" style="display:${pick[filterKey] eq filterKey ? '' : 'none'}"
id="${normalizedKey}_filter" key="${normalizedKey}">
<div class="col-lg-3">
<spring:message code="filter.${filter.name}"/>
<c:if test="${not filter.core}">
<a href="<c:url value="/descriptors/${filter.key}" />"><c:out value="${filter.title}" /></a>
</c:if>
<c:if test="${filter.core}">
<spring:message code="filter.${filter.name}" />
</c:if>
</div>
<div class="col-lg-5 filter-new">
<div class="col-lg-5 filter-new" style="display: none">
<c:choose>
<c:when test="${filter.filterType=='LIST'}">
<div class="">
<c:forEach items="${filter.options}" var="option">
<div>
<label><input class="list" type="checkbox" value="${option.value}"/> <c:out value="${option.name}"/></label>
<span class="pull-right"><c:out value="${option.count}"/></span>
<label>
<input id="${option.value}_input" ${fn:contains(filters[filter.key], option.value)?'checked':''} i-key="${normalizedKey}${option.value}" type="checkbox" value="${option.value}" onclick="filterList('${normalizedKey}','${option.value}')"/>
<spring:message code="${option.name}"/>
</label>
</div>
</c:forEach>
</div>
<div style="margin-top: 3px">
<button class="btn btn-primary apply"><spring:message code="filter.apply"/></button>
</div>
</c:when>
<c:when test="${filter.filterType=='I18NLIST'}">
<div class="">
<c:forEach items="${filter.options}" var="option">
<div>
<label>
<input id="${option.value}_input" ${fn:contains(filters[filter.key], option.value)?'checked':''} i-key="${filter.key}${option.value}" type="checkbox" value="${option.value}" onclick="filterList('${filter.key}','${option.value}')"/>
<input id="${option.value}_input" ${fn:contains(filters[filter.key], option.value)?'checked':''} i-key="${normalizedKey}${option.value}" type="checkbox" value="${option.value}" onclick="filterList('${normalizedKey}','${option.value}')"/>
<spring:message code="${option.name}"/>
</label>
</div>
</c:forEach>
<div style="margin-top: 3px">
<button class="btn btn-primary apply"><spring:message code="filter.apply"/></button>
</div>
</div>
</c:when>
<c:when test="${filter.filterType=='AUTOCOMPLETE'}">
<div class="ui-front">
<div class="form-group input-group">
<span class="input-group-btn">
<input id="${filter.key}_input" class="span2 form-control autocomplete-filter" x-source="${filter.autocompleteUrl}" type="text"/>
<button class="btn notimportant" onclick="filterAuto('${filter.key}')">+</button>
<input id="${normalizedKey}_input" class="span2 form-control autocomplete-filter" x-source="${filter.autocompleteUrl}" type="text"/>
<button class="btn notimportant" onclick="filterAuto('${normalizedKey}')">+</button>
</span>
</div>
<div style="margin-top: 3px">
<button class="btn btn-primary apply"><spring:message code="filter.apply"/></button>
</div>
</div>
</c:when>
<c:when test="${filter.dataType=='NUMERIC'}">
<div class="form-group input-group">
<span class="input-group-btn">
<input id="${filter.key}_input_1" class="span5 form-control" type="text"/>
<input id="${filter.key}_input_2" class="span5 form-control" type="text"/>
<button class="btn notimportant" onclick="filterRange('${filter.key}')">+</button>
<input id="${normalizedKey}_input_1" class="span5 form-control" type="text"/>
<input id="${normalizedKey}_input_2" class="span5 form-control" type="text"/>
<button class="btn notimportant" onclick="filterRange('${normalizedKey}')">+</button>
</span>
</div>
<div style="margin-top: 3px">
<button class="btn btn-primary apply"><spring:message code="filter.apply"/></button>
</div>
</c:when>
<c:when test="${filter.dataType=='BOOLEAN'}">
<div class="">
<div><label><input type="checkbox" ${fn:contains(filters[filter.key], 'true')?'checked':''} class="bool-data" i-key="${filter.key}true" id="${filter.key}" value="true"><spring:message code="boolean.true"/></label></div>
<div><label><input type="checkbox" ${fn:contains(filters[filter.key], 'false')?'checked':''} class="bool-data" i-key="${filter.key}false" id="${filter.key}" value="false"><spring:message code="boolean.false"/></label></div>
<div><label><input type="checkbox" ${fn:contains(filters[filter.key], 'null')?'checked':''} class="bool-data" i-key="${filter.key}null" id="${filter.key}" value="null"><spring:message code="boolean.null"/></label></div>
<div><label><input type="checkbox" ${fn:contains(filters[filter.key], 'true')?'checked':''} class="bool-data" i-key="${normalizedKey}true" id="${normalizedKey}" value="true"><spring:message code="boolean.true"/></label></div>
<div><label><input type="checkbox" ${fn:contains(filters[filter.key], 'false')?'checked':''} class="bool-data" i-key="${normalizedKey}false" id="${normalizedKey}" value="false"><spring:message code="boolean.false"/></label></div>
<div><label><input type="checkbox" ${fn:contains(filters[filter.key], 'null')?'checked':''} class="bool-data" i-key="${normalizedKey}null" id="${normalizedKey}" value="null"><spring:message code="boolean.null"/></label></div>
</div>
<div style="margin-top: 3px">
<button class="btn btn-primary apply"><spring:message code="filter.apply"/></button>
</div>
</c:when>
<c:when test="${filter.name=='crop'}">
<div class="form-group input-group">
<span class="input-group-btn">
<select name="crop" id="cropselector" onclick="filterCrop('${filterKey}')" class="form-control">
<option value=""></option>
<c:forEach items="${crops}" var="c">
<option value="${c.shortName}" ${c.shortName== crop.shortName?'selected':''} ><c:out value="${c.getName(pageContext.response.locale)}" /></option>
</c:forEach>
</select>
</span>
</div>
</c:when>
<c:otherwise>
<div class="form-group input-group">
<span class="input-group-btn">
<input class="span2 form-control" id="${filter.key}_input" type="text"/>
<button class="btn notimportant" onclick="filterAuto('${filter.key}')">+</button>
<input class="span2 form-control" id="${normalizedKey}_input" type="text"/>
<button class="btn notimportant" onclick="filterAuto('${normalizedKey}')">+</button>
</span>
</div>
<div style="margin-top: 3px">
<button class="btn btn-primary apply"><spring:message code="filter.apply"/></button>
</div>
</c:otherwise>
</c:choose>
</div>
<div class="col-lg-4 filter-values" id="${filter.key}_value">
<a href="#" style="float: right" class="close">x</a>
<div>
<a href="#" style="float: right" class="close-fil glyphicon glyphicon-remove"></a>
<a href="#" style="float: right" class="edit-fil glyphicon glyphicon-pencil"></a>
</div>
<div class="col-lg-4 filter-values" id="${normalizedKey}_value">
<%--<a href="#" style="float: right" class="close-fil glyphicon glyphicon-remove"></a>--%>
<%--<a href="#" style="float: right" class="edit-fil glyphicon glyphicon-pencil"></a>--%>
<c:forEach items="${filters[filter.key]}" var="value">
<c:set var="string" value="${value}"/>
......@@ -148,18 +208,49 @@
<c:set var="string" value="${fn:replace(string,'}','')}"/>
</c:if>
<div class="filtval complex" x-key="${filter.key}${value}" id="${filter.key}">${string}</div>
<div class="filtval complex" x-key="${normalizedKey}${value}" id="${normalizedKey}">${string}</div>
</c:forEach>
</div>
</div>
</c:forEach>
<div class="row">
<div style="text-align: center">
<button id="apply" class="btn btn-green"><spring:message code="filter.apply"/></button>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel"><spring:message code="filter.additional"/></h4>
</div>
<div class="modal-body" style="overflow: auto;height: 200px">
<c:forEach items="${categories}" var="category">
<c:if test="${descriptors[category].size() gt 0}">
<h2><c:out value="${crop.getName(pageContext.request.locale)}:" /> <c:out value="${category.getName(pageContext.request.locale)}" /></h2>
<c:forEach items="${descriptors[category]}" var="descriptor">
<c:if test="${methods[descriptor.id].size() gt 0}">
<div class="row filter-block">
<div class="col-lg-3">
<div dir="ltr"><c:out value="${descriptor.title}" /></div>
</div>
<div class="col-lg-9">
<c:forEach items="${methods[descriptor.id]}" var="method">
<div><label><input id="gm_${method.id}_id" type="checkbox" style="margin-right: 1em;" onclick="enableFilter('gm_${method.id}')" value="gm:${method.id}" /><span dir="ltr"><c:out value="${method.method}" /></span></label></div>
</c:forEach>
</div>
</div>
</c:if>
</c:forEach>
</c:if>
</c:forEach>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal"><spring:message code="filter.apply"/></button>
</div>
</div>
</div>
</div>
<!--End modal-->
<%--Accessions--%>
<table class="accessions">
<thead>
......@@ -233,13 +324,33 @@
function enableFilter(key) {
var editId = "#" + key + "_filter";
$(editId).show();
var inputId = "#" + key + "_id";
var parent = $(editId).find(".filter-new");
parent.show();
var isAdditionalFilter = key.indexOf("gm") > -1;
var checked = $(inputId).is(":checked");
if (isAdditionalFilter) {
if (checked) {
$(editId).show();
} else {
$(editId).hide();
}
} else {
$(editId).show();
}
}
function appendHtml(key, value) {
var valueId = "#" + key + "_value";
var summaryViewId="#"+key+"_summary";
var div = "<div class='filtval complex' x-key='" + key + value + "' id='" + key + "'>" + value + "</div>"
$(valueId).append(div);
$(summaryViewId).append(div);
}
function collectData(key,value) {
......@@ -359,6 +470,20 @@
}
}
function filterCrop(key) {
var selectBox = document.getElementById("cropselector");
var value = selectBox.options[selectBox.selectedIndex].value;
delete jsonData[key];
$(selectBox).parent().parent().parent().parent().find('.complex').remove()
if(value!=''){
appendHtml(key, value);
jsonData[key] = collectData(key, value);
submitJson();
}
}
$(".bool-data").on("click", function () {
var value = $(this).val();
......@@ -376,11 +501,11 @@
}
});
$("#apply").click(function () {
$(".apply").click(function () {
submitJson()
});
$(".close").on("click", function () {
$(".close-fil").on("click", function () {
var parent = $(this).parent().parent();
var key = parent.attr("key");
console.log(key);
......@@ -388,6 +513,14 @@
parent.hide();
});
$(".edit-fil").on("click", function () {
var parent = $(this).parent().parent().find(".filter-new");
var key = parent.attr("key");
parent.toggle("fast", function() {
});
});
$("body").on("click", ".filtval", function (event) {
event.preventDefault();
......
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