Commit d5bb43eb authored by Maxym Borodenko's avatar Maxym Borodenko

Filter accessions by GeoRegion. Added 2d filter (Region of Holding Institute)

parent c8a04238
......@@ -85,5 +85,8 @@ public interface FilterConstants {
public static final String PDCI = "pdci";
public static final String REGION_ORIGIN = "regionOrigin";
public static final String REGION_HOLD_INSTITUTE= "regionHoldInst";
}
......@@ -81,6 +81,8 @@ public class FilterHandler {
this.availableFilters.add(new BasicFilter(FilterConstants.CROPNAME, DataType.STRING));
this.availableFilters.add(new BasicFilter(FilterConstants.LISTS, DataType.STRING));
this.availableFilters.add(new BasicFilter(FilterConstants.REGION_ORIGIN, DataType.STRING));
this.availableFilters.add(new BasicFilter(FilterConstants.REGION_HOLD_INSTITUTE, DataType.STRING));
this.availableFilters.add(new I18nListFilter<Integer>(FilterConstants.SAMPSTAT, DataType.NUMERIC).build("accession.sampleStatus",
new Integer[] { 100, 110, 120, 130, 200, 300, 400, 410, 411, 412, 413, 414, 415, 416, 420, 421, 422, 423, 500, 600, 999 }));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.TAXONOMY_GENUS, "/explore/ac/" + FilterConstants.TAXONOMY_GENUS));
......@@ -89,7 +91,7 @@ public class FilterHandler {
this.availableFilters.add(new AutocompleteFilter(FilterConstants.TAXONOMY_SCINAME, "/explore/ac/" + FilterConstants.TAXONOMY_SCINAME));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.ORGCTY_ISO3, "/explore/ac/" + FilterConstants.ORGCTY_ISO3));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.INSTITUTE_COUNTRY_ISO3, "/explore/ac/" + FilterConstants.ORGCTY_ISO3));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.INSTITUTE_COUNTRY_ISO3, "/explore/ac/" + FilterConstants.INSTITUTE_COUNTRY_ISO3));
this.availableFilters.add(new BasicFilter(FilterConstants.GEO_LATITUDE, DataType.NUMERIC));
this.availableFilters.add(new BasicFilter(FilterConstants.GEO_LONGITUDE, DataType.NUMERIC));
this.availableFilters.add(new BasicFilter(FilterConstants.GEO_ELEVATION, DataType.NUMERIC));
......
......@@ -236,19 +236,20 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
LOG.error("Error occurred during search", e);
}
if (termResult != null) {
for (final Country c : countries) {
String label = c.getCode3() + ", " + c.getName();
for (Term term : termResult.getTerms()) {
if (term.getTerm().equals(c.getCode3()) && term.getCount() > 0) {
label = label.concat(" (" + term.getCount() + ")");
completed.add(new LabelValue<String>(c.getCode3(), label));
break;
}
}
}
fillCountryCompleteListFromTerm(completed, termResult, countries);
} else if (FilterConstants.INSTITUTE_COUNTRY_ISO3.equalsIgnoreCase(filter)) {
final List<Country> countries = geoService.autocomplete(ac);
TermResult termResult = null;
try {
termResult = elasticService.termStatisticsAuto(filters, FilterConstants.INSTITUTE_COUNTRY_ISO3, 20000);
} catch (SearchException e) {
LOG.error("Error occurred during search", e);
}
} else if (FilterConstants.TAXONOMY_GENUS.equalsIgnoreCase(filter)) {
fillCountryCompleteListFromTerm(completed, termResult, countries);
}
else if (FilterConstants.TAXONOMY_GENUS.equalsIgnoreCase(filter)) {
final List<String> genera = taxonomyService.autocompleteGenus(ac, crop);
TermResult termResult = null;
try {
......@@ -257,18 +258,8 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
LOG.error("Error occurred during search", e);
}
if (termResult != null) {
for (final String value : genera) {
String label = value;
for (Term term : termResult.getTerms()) {
if (term.getTerm().equals(value) && term.getCount() > 0) {
label = label.concat(" (" + term.getCount() + ")");
completed.add(new LabelValue<String>(value, label));
break;
}
}
}
}
fillCompleteListFromTerm(completed, termResult, genera);
} else if (FilterConstants.TAXONOMY_SPECIES.equalsIgnoreCase(filter)) {
List<String> genus = new ArrayList<>();
......@@ -287,18 +278,8 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
LOG.error("Error occurred during search", e);
}
if (termResult != null) {
for (final String value : species) {
String label = value;
for (Term term : termResult.getTerms()) {
if (term.getTerm().equals(value) && term.getCount() > 0) {
label = label.concat(" (" + term.getCount() + ")");
completed.add(new LabelValue<String>(value, label));
break;
}
}
}
}
fillCompleteListFromTerm(completed, termResult, species);
} else if (FilterConstants.TAXONOMY_SUBTAXA.equalsIgnoreCase(filter)) {
List<String> genus = new ArrayList<>();
List<String> species = new ArrayList<>();
......@@ -324,18 +305,8 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
LOG.error("Error occurred during search", e);
}
if (termResult != null) {
for (final String value : subtaxa) {
String label = value;
for (Term term : termResult.getTerms()) {
if (term.getTerm().equals(value) && term.getCount() > 0) {
label = label.concat(" (" + term.getCount() + ")");
completed.add(new LabelValue<String>(value, label));
break;
}
}
}
}
fillCompleteListFromTerm(completed, termResult, subtaxa);
} else if (FilterConstants.TAXONOMY_SCINAME.equalsIgnoreCase(filter)) {
final List<String> taxa = taxonomyService.autocompleteTaxonomy(ac);
TermResult termResult = null;
......@@ -344,23 +315,41 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
} catch (SearchException e) {
LOG.error("Error occurred during search", e);
}
fillCompleteListFromTerm(completed, termResult, taxa);
} else {
throw new RuntimeException("No autocompleter for " + filter);
}
return completed;
}
private void fillCountryCompleteListFromTerm(final List<LabelValue<String>> completed, final TermResult termResult, final List<Country> countries) {
if (termResult != null) {
for (final Country c : countries) {
String label = c.getCode3() + ", " + c.getName();
for (Term term : termResult.getTerms()) {
if (term.getTerm().equals(c.getCode3()) && term.getCount() > 0) {
label = label.concat(" (" + term.getCount() + ")");
completed.add(new LabelValue<String>(c.getCode3(), label));
break;
}
}
}
}
}
if (termResult != null) {
for (final String taxonomy : taxa) {
String label = taxonomy;
for (Term term : termResult.getTerms()) {
if (term.getTerm().equals(taxonomy) && term.getCount() > 0) {
label = label.concat(" (" + term.getCount() + ")");
completed.add(new LabelValue<String>(taxonomy, label));
break;
}
private void fillCompleteListFromTerm(final List<LabelValue<String>> completed, final TermResult termResult, final List<String> list) {
if (termResult != null) {
for (final String val : list) {
String label = val;
for (Term term : termResult.getTerms()) {
if (term.getTerm().equals(val) && term.getCount() > 0) {
label = label.concat(" (" + term.getCount() + ")");
completed.add(new LabelValue<String>(val, label));
break;
}
}
}
} else {
throw new RuntimeException("No autocompleter for " + filter);
}
return completed;
}
public static class LabelValue<T> {
......
......@@ -431,6 +431,7 @@ filter.alias=Accession name
filter.crops=Crop name
filter.cropName=Provided crop name
filter.regionOfOrigin=Region of Origin
filter.regionOfHoldingInstitute=Region of Holding Institute
filter.orgCty.iso3=Country of Origin
filter.institute.code=Holding Institute name
filter.institute.country.iso3=Country of holding institute
......
......@@ -24,7 +24,7 @@
<div class="">
<filters:filter-list availableFilters="${availableFilters}" filters="${filters}"
additionalFilters="${additionalFilters}" appliedFilters="${appliedFilters}"
crops="${crops}" crop="${crop}"/>
crops="${crops}" crop="${crop}" geoRegions="${geoRegions}"/>
<div class="col-lg-10 col-md-9 col-sm-9 col-xs-12 main-col-header">
<div class="nav-header clearfix">
......@@ -272,6 +272,13 @@
}
});
$("body").on("change", ".geo-switcher", function () {
if (jsonData[$(this).attr("i-key")] === undefined) {
BrowseUtil.enableFilter(this, jsonData);
}
GenesysFilter.filterSelectList($(this), jsonData);
});
$("body").on("click", ".filter-list", function () {
if (jsonData[$(this).attr("i-key")] === undefined) {
BrowseUtil.enableFilter(this, jsonData);
......
......@@ -29,8 +29,9 @@
<div class="">
<%-- filter list --%>
<filters:filter-list availableFilters="${availableFilters}" filters="${filters}"
appliedFilters="${appliedFilters}" crops="${crops}" crop="${crop}"/>
<filters:filter-list availableFilters="${availableFilters}" filters="${filters}"
additionalFilters="${additionalFilters}" appliedFilters="${appliedFilters}"
crops="${crops}" crop="${crop}" geoRegions="${geoRegions}"/>
<div class="col-lg-10 col-md-9 col-sm-9 col-xs-12 main-col-header">
<div class="nav-header clearfix">
......@@ -187,20 +188,12 @@
$("body").on("keypress", ".string-type", function (e) {
if (e.keyCode == 13) {
console.log("press")
var btn = $(this).parent().find("button");
console.log("1")
var selectedValue = $(this).parent().parent().find(".like-switcher option:selected").val();
console.log("2")
if (selectedValue == "like") {
GenesysFilter.filterLike(btn, jsonData, BrowseUtil.i18nFilterMessage);
} else {
console.log("btn", btn)
console.log("jsonData", jsonData)
console.log("03")
GenesysFilter.filterAutocomplete(btn, jsonData);
console.log("04")
}
}
});
......@@ -218,6 +211,13 @@
}
});
$("body").on("change", ".geo-switcher", function () {
if (jsonData[$(this).attr("i-key")] === undefined) {
BrowseUtil.enableFilter(this, jsonData);
}
GenesysFilter.filterSelectList($(this), jsonData);
});
$("body").on("click", ".filter-list", function () {
if (jsonData[$(this).attr("i-key")] === undefined) {
BrowseUtil.enableFilter(this, jsonData);
......@@ -323,9 +323,7 @@
var stepValue = (parseInt(localStorage.getItem("historyStep")) + 1);
localStorage.setItem("historyStep", stepValue);
document.getElementById('loading-popup-id').style.display = "block";
console.log("json data appl1", jsonData);
BrowseUtil.cleanJsonData(jsonData);
console.log("json data appl2", jsonData);
var filter = JSON.stringify(jsonData);
var requestUrl = '//' + location.host + location.pathname + "/json" +
......
......@@ -45,6 +45,11 @@
appliedFilters="${appliedFilters}" type="autocomplete"/>
</filters:panel>
<filters:panel id="regionOfHoldingInstitute" title="filter.regionOfHoldingInstitute">
<filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="regionHoldInst"
appliedFilters="${appliedFilters}" type="geoSelect"/>
</filters:panel>
<filters:panel id="instcountry" title="filter.institute.country.iso3">
<filters:filter availableFilters="${availableFilters}" filterMap="${filters}"
filterKey="institute.country.iso3" appliedFilters="${appliedFilters}"
......@@ -106,8 +111,8 @@
</filters:panel>
<filters:panel id="regionOfOrigin" title="filter.regionOfOrigin">
<filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="cropName"
appliedFilters="${appliedFilters}" geoRegions="${geoRegions}" type="geoSelect"/>
<filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="regionOrigin"
appliedFilters="${appliedFilters}" type="geoSelect"/>
</filters:panel>
<filters:panel id="origcty" title="filter.orgCty.iso3">
......
......@@ -50,7 +50,7 @@
</c:when>
<c:when test="${type eq 'geoSelect'}">
<span class="glyphicon glyphicon-menu-down"></span>
<select class="form-control geo-switcher" i-key="geoRegions" >
<select class="form-control geo-switcher" i-key="${filterKey}" >
<option value="empty"></option>
<c:forEach items="${geoRegions}" var="geoRegion">
<c:if test="${geoRegion.parentRegion eq null}">
......@@ -176,16 +176,32 @@
<c:otherwise/>
</c:choose>
<c:if test="${type ne 'range'}">
<c:forEach items="${filterMap[appliedFilter.key]}" var="value">
<%@include file="filtval.jspf" %>
<%--<div class="filtval complex"--%>
<%--x-key="<c:out value="${normalizedKey}" /><c:out value="${value}"/>"--%>
<%--i-key="<c:out value="${filter.key}" />"><c:out value="${string}"/>--%>
<%--</div>--%>
<%--<c:remove var="string"/>--%>
</c:forEach>
</c:if>
<c:if test="${type ne 'range'}">
<c:choose>
<c:when test="${type eq 'geoSelect'}">
<c:forEach items="${filterMap[appliedFilter.key]}" var="value">
<c:set var="isoCode" value="${value}"/>
<c:forEach items="${geoRegions}" var="subRegion">
<c:if test="${subRegion.isoCode eq value}">
<c:set var="string" value="${subRegion.nameL}"/>
<c:set var="index" value="${fn:indexOf(string, localeCode )}"/>
<c:set var="string"
value="${fn:substring(subRegion.nameL, index, fn:length(subRegion.nameL))}"/>
<c:set var="string" value="${fn:substring(string, 6, fn:length(subRegion.nameL))}"/>
<c:set var="index" value="${fn:indexOf(string, '\"' )}"/>
<c:set var="value" value="${fn:substring(string, 0, index)}"/>
<%@include file="filtval.jspf" %>
</c:if>
</c:forEach>
</c:forEach>
</c:when>
<c:otherwise>
<c:forEach items="${filterMap[appliedFilter.key]}" var="value">
<%@include file="filtval.jspf" %>
</c:forEach>
</c:otherwise>
</c:choose>
</c:if>
......
......@@ -47,8 +47,18 @@
<spring:message code='accession.sampleStatus.${value}' var="string"/>
</c:if>
<div class="filtval complex"
x-key="<c:out value="${normalizedKey}" /><c:out value="${value}"/>"
i-key="<c:out value="${filter.key}" />"><c:out value="${string}"/>
</div>
<c:choose>
<c:when test="${type eq 'geoSelect'}">
<div class="filtval complex"
x-key="<c:out value="${normalizedKey}"/><c:out value="${isoCode}"/>"
i-key="<c:out value="${filter.key}" />"><c:out value="${string}"/>
</div>
</c:when>
<c:otherwise>
<div class="filtval complex"
x-key="<c:out value="${normalizedKey}" /><c:out value="${value}"/>"
i-key="<c:out value="${filter.key}" />"><c:out value="${string}"/>
</div>
</c:otherwise>
</c:choose>
<c:remove var="string"/>
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