Commit c8a04238 authored by Maxym Borodenko's avatar Maxym Borodenko

WIP: Filter accessions by GeoRegion

parent cf377060
......@@ -7,6 +7,7 @@ import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
public interface GeoRegionService {
......@@ -18,6 +19,8 @@ public interface GeoRegionService {
List<GeoRegion> findAll();
List<GeoRegion> findAll(Locale locale);
void updateGeoRegionData() throws IOException, ParserConfigurationException, SAXException;
GeoRegion getRegion(Country country);
......
......@@ -2,7 +2,10 @@ package org.genesys2.server.service.impl;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.stream.Collectors;
......@@ -83,6 +86,18 @@ public class GeoRegionServiceImpl implements GeoRegionService {
return geoRegionRepository.findAll();
}
@Override
public List<GeoRegion> findAll(final Locale locale) {
final List<GeoRegion> all = findAll();
Collections.sort(all, new Comparator<GeoRegion>() {
@Override
public int compare(GeoRegion o1, GeoRegion o2) {
return o1.getName(locale).compareTo(o2.getName(locale));
}
});
return all;
}
@Override
@Transactional(readOnly = false)
public void updateGeoRegionData() throws IOException, ParserConfigurationException, SAXException {
......
......@@ -430,6 +430,7 @@ filter.seqNo=Detected sequential number
filter.alias=Accession name
filter.crops=Crop name
filter.cropName=Provided crop name
filter.regionOfOrigin=Region of Origin
filter.orgCty.iso3=Country of Origin
filter.institute.code=Holding Institute name
filter.institute.country.iso3=Country of holding institute
......
......@@ -77,6 +77,19 @@ var BrowseUtil = {
},
applySuggestions: function (jsonData, messages) {
$.ajax({
url: '/explore/transformedFilters',
method: 'get',
data: {
filter: JSON.stringify(jsonData)
},
success: function (response) {
BrowseUtil.refreshSuggestions(response, messages);
}
});
},
refreshSuggestions: function (jsonData, messages) {
$.ajax({
url: '/explore/listFilterSuggestions',
method: 'get',
......
......@@ -372,6 +372,21 @@ var GenesysFilterUtil = {
var GenesysFilter = {
normKey : GenesysFilterUtil.normKey,
// add filter with select option
filterSelectList: function (element, jsonData) {
var key = $(element).attr('i-key');
var optionSelected = element.find('option:selected');
var valueSelected = optionSelected.val();
var textSelected = optionSelected.text();
if (!GenesysFilterUtil.existInJson(valueSelected, key, jsonData)) {
GenesysFilterUtil.appendHtml(key, textSelected, valueSelected, element);
jsonData[key] = GenesysFilterUtil.collectData(key, valueSelected, jsonData);
$('.geo-switcher option').removeAttr('selected').filter('[value=empty]').attr('selected', true);
}
return jsonData;
},
// add filter with autocomplete or exact field
filterAutocomplete : function(element, jsonData) {
......
......@@ -49,7 +49,7 @@
<!--Filters-->
<filters:filter-list availableFilters="${availableFilters}" filters="${filters}"
additionalFilters="${additionalFilters}" appliedFilters="${appliedFilters}"
crops="${crops}" crop="${crop}"/>
crops="${crops}" crop="${crop}" geoRegions="${geoRegions}"/>
<!--List-->
<div class="col-lg-10 col-md-9 col-sm-9 col-xs-12 main-col-header">
<div class="nav-header clearfix">
......@@ -352,6 +352,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);
......
......@@ -11,6 +11,10 @@ var messages = new Array();
messages["geo.iso3166-3.<spring:message text='${country.getCode3()}' javaScriptEscape='true'/>"] = "<c:out value='${country.getName(locale)}'/>";
</c:forEach>
<c:forEach var="geoRegion" items="${geoRegions}">
messages["<spring:message text='${geoRegion.getName()}' javaScriptEscape='true'/>"] = "<c:out value='${geoRegion.getName(locale)}'/>";
</c:forEach>
<c:forEach items="${cropsNames}" var="cropName">
messages["${cropName.key}"] = "${cropName.value}";
</c:forEach>
\ No newline at end of file
......@@ -4,6 +4,7 @@
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ attribute name="geoRegions" required="true" type="java.util.List" %>
<%@ attribute name="additionalFilters" required="false" type="java.util.List" %>
<%@ attribute name="availableFilters" required="true" type="java.util.Map" %>
<%@ attribute name="filters" required="true" type="java.util.Map" %>
......@@ -104,6 +105,11 @@
appliedFilters="${appliedFilters}" type="option"/>
</filters:panel>
<filters:panel id="regionOfOrigin" title="filter.regionOfOrigin">
<filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="cropName"
appliedFilters="${appliedFilters}" geoRegions="${geoRegions}" type="geoSelect"/>
</filters:panel>
<filters:panel id="origcty" title="filter.orgCty.iso3">
<filters:filter availableFilters="${availableFilters}" filterMap="${filters}"
filterKey="orgCty.iso3"
......
......@@ -13,6 +13,7 @@
<%@ attribute name="type" required="true" type="java.lang.String" %>
<%@ attribute name="cropList" required="false" type="java.util.Map" %>
<%@ attribute name="currentCrop" required="false" type="org.genesys2.server.model.impl.Crop" %>
<%@ attribute name="geoRegions" required="false" type="java.util.List" %>
<spring:message code="filter.internal.message.between" var="between" arguments=" "/>
<spring:message code="filter.internal.message.and" var="varEnd" arguments=" "/>
......@@ -26,6 +27,7 @@
<c:set var="filter" value="${availableFilters[filterKey]}"/>
<c:set var="normalizedKey" value="${filter.key.replace('.', '-').replace(':', '_')}"/>
<c:set var="appliedFilter" value="${appliedFilters.get(filter.key)}"/>
<c:set var="localeCode" value='"${pageContext.response.locale}"' />
<div id="collapse_filt_${filterKey}" class="${filterKey} col-xs-12">
......@@ -46,6 +48,36 @@
</c:forEach>
<!-- </select> -->
</c:when>
<c:when test="${type eq 'geoSelect'}">
<span class="glyphicon glyphicon-menu-down"></span>
<select class="form-control geo-switcher" i-key="geoRegions" >
<option value="empty"></option>
<c:forEach items="${geoRegions}" var="geoRegion">
<c:if test="${geoRegion.parentRegion eq null}">
<c:set var="string" value="${geoRegion.nameL}"/>
<c:set var="index" value="${fn:indexOf(string, localeCode )}"/>
<c:set var="string" value="${fn:substring(geoRegion.nameL, index, fn:length(geoRegion.nameL))}" />
<c:set var="string" value="${fn:substring(string, 6, fn:length(geoRegion.nameL))}" />
<c:set var="index" value="${fn:indexOf(string, '\"' )}"/>
<c:set var="string" value="${fn:substring(string, 0, index)}" />
<optgroup label="${string}">
<c:forEach items="${geoRegions}" var="subRegion">
<c:remove var="string"/>
<c:if test="${subRegion.parentRegion.name eq geoRegion.name}">
<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="string" value="${fn:substring(string, 0, index)}" />
<option value="${subRegion.isoCode}">${string}</option>
</c:if>
</c:forEach>
</optgroup>
</c:if>
</c:forEach>
</select>
</c:when>
<c:when test="${type eq 'like'}">
<span class="glyphicon glyphicon-menu-down"></span>
<select class="form-control like-switcher">
......
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