Commit b0306e73 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge commit 'c7092da7' into staging

parents 9c1d0ad8 c7092da7
......@@ -22,6 +22,7 @@ import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.http.client.utils.URIBuilder;
import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.filters.CodedMethodFilter;
import org.genesys2.server.model.filters.GenesysFilter;
import org.genesys2.server.model.filters.I18nListFilter;
import org.genesys2.server.model.genesys.Method;
......@@ -49,6 +50,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.support.StringMultipartFileEditor;
import org.springframework.web.servlet.support.RequestContextUtils;
import javax.imageio.ImageIO;
......@@ -189,6 +191,7 @@ public class ExplorerController extends BaseController implements InitializingBe
selectedFilters = appliedFilters.getFilterNames();
final List<GenesysFilter> currentFilters = filterHandler.selectFilters(selectedFilters);
final Map<String, GenesysFilter> availableFilters = filterHandler.mapAvailableFilters();
final List<GenesysFilter> additionalFilters = getAdditionalFilters(selectedFilters);
//assign suggested values instead of all values to the list filters
GenesysFilter filter = availableFilters.get(FilterConstants.SAMPSTAT);
......@@ -241,13 +244,24 @@ public class ExplorerController extends BaseController implements InitializingBe
model.addAttribute("crops", getCrops(tempFilters));
model.addAttribute("pagedData", accessions);
model.addAttribute("appliedFilters", appliedFilters);
model.addAttribute("appliedFilters", getAppliedFilters(appliedFilters));
model.addAttribute("currentFilters", currentFilters);
model.addAttribute("additionalFilters", additionalFilters);
model.addAttribute("availableFilters", availableFilters);
return "/accession/explore2";
}
private AppliedFilters getAppliedFilters (AppliedFilters filters) {
AppliedFilters newAppliedFilters = new AppliedFilters();
for(AppliedFilter appliedFilter: filters) {
if(!appliedFilter.getValues().isEmpty()) {
newAppliedFilters.add(appliedFilter);
}
}
return newAppliedFilters;
}
@RequestMapping(value = "/explore/overview")
public String overview(
ModelMap model,
......@@ -304,17 +318,18 @@ public class ExplorerController extends BaseController implements InitializingBe
AppliedFilters appliedFilters2 = mapper.readValue(jsonFilter, AppliedFilters.class);
String[] selectedFilters = appliedFilters.getFilterNames();
final List<GenesysFilter> currentFilters = filterHandler.selectFilters(selectedFilters);
model.addAttribute("appliedFilters", appliedFilters2);
model.addAttribute("currentFilters", currentFilters);
final List<GenesysFilter> additionalFilters = getAdditionalFilters(selectedFilters);
final Map<?, ?> filters = mapper.readValue(appliedFilters.toString(), Map.class);
model.addAttribute("filters", filters);
final Map<String, GenesysFilter> availableFilters = filterHandler.mapAvailableFilters();
model.addAttribute("availableFilters", availableFilters);
AppliedFilters tempFilters = mapper.readValue(jsonFilter, AppliedFilters.class);
model.addAttribute("crops", getCrops(tempFilters));
model.addAttribute("filters", filters);
model.addAttribute("availableFilters", availableFilters);
model.addAttribute("crops", getCrops(tempFilters));
model.addAttribute("additionalFilters", additionalFilters);
model.addAttribute("appliedFilters", getAppliedFilters(appliedFilters2));
model.addAttribute("currentFilters", currentFilters);
model.addAttribute("jsonFilter", appliedFilters.toString());
return "/accession/map";
}
......@@ -417,7 +432,7 @@ public class ExplorerController extends BaseController implements InitializingBe
return getCrops(appliedFilters);
}
private Map<String, Map<String, Integer>> getCrops(AppliedFilters appliedFilters) throws SearchException {
private Map<String, Map<String, Integer> > getCrops(AppliedFilters appliedFilters) throws SearchException {
Map<String, Map<String, Integer>> crops = new HashMap<>();
appliedFilters.removeIf(appliedFilter -> appliedFilter.getKey().equals(FilterConstants.CROPS));
......@@ -607,6 +622,17 @@ public class ExplorerController extends BaseController implements InitializingBe
return "/accession/explore-es";
}
private List<GenesysFilter> getAdditionalFilters(String[] selectedFilters) {
List<String> gmFilterList = new ArrayList<>();
for (String filter : selectedFilters) {
if (filter.startsWith("gm:")) {
gmFilterList.add(filter);
}
}
String[] gmFilters = gmFilterList.toArray(new String[gmFilterList.size()]);
return filterHandler.selectFilters(gmFilters);
}
@RequestMapping(value = "/additional-filter", method = RequestMethod.GET)
public String getAdditionalFilters(ModelMap model, @RequestParam(value = "filter", required = true, defaultValue = "") String[] selectedFilters)
throws IOException {
......@@ -619,7 +645,7 @@ public class ExplorerController extends BaseController implements InitializingBe
model.addAttribute("crops", cropService.list(getLocale()));
}
return "/accession/additional-filter";
return "/accession/additional-filter2";
}
@RequestMapping(value = "/modal", method = RequestMethod.GET)
......
......@@ -289,7 +289,11 @@ var GenesysFilterUtil = {
//$(element).parents('.filter-block').find('.filter-values').append(div);
if (key === 'geo.latitude' || key === 'geo.longitude' || key === 'geo.elevation') {
$(element).parent().parent().after(div);
} else {
}
else if(key.startsWith('gm:')) {
$(element).parent().parent().parent().find('.filtersBtn').before(div);
}
else {
$(element).parent().parent().parent().find('button.applyBtn').before(div);
}
},
......@@ -339,11 +343,17 @@ var GenesysFilterUtil = {
data : 'filter=' + filter,
async: false,
success : function(data) {
jsonData[filter] = [];
$('#allfilters').append(data);
GenesysFilterUtil.registerAutocomplete('#allfilters', jsonData);
success: function (data) {
if (filter.startsWith('gm:')) {
$('#accordionFilterListForAdditional').append(data);
GenesysFilterUtil.registerAutocomplete('#accordionFilterListForAdditional', jsonData);
}
else {
$('#accordionFilterList').append(data);
GenesysFilterUtil.registerAutocomplete('#accordionFilterList', jsonData);
}
GenesysFilterUtil.showFilter(filterId);
jsonData[filter] = [];
},
error : function(error) {
console.log(error);
......@@ -508,13 +518,16 @@ var GenesysFilter = {
delete jsonData[key];
// Clear previous crop selection
element.parent().parent().find('.complex').remove();
var loc = location.pathname.toString();
if (value !== null) {
GenesysFilterUtil.appendHtml(key, value, value, element);
jsonData[key] = GenesysFilterUtil.collectData(key, value, jsonData);
$('#menu2').show();
if (loc.indexOf('overview') < 0) {
$('#panel_additional_id').show();
}
} else {
$('#menu2').hide();
$('#panel_additional_id').hide();
}
},
......
......@@ -1854,6 +1854,54 @@ h2.short {
.container-fluid {
padding-left: 0;
padding-right: 0;
.modal-dialog {
width: 40%;
font-family: arial, sans-serif;
@media (max-width: 1024px) {
width: 97%;
}
.modal-header {
background: #87bc38;
color: $white-color;
.modal-title {
font-weight: 600;
font-size: 25px;
}
.close {
color: $white-color;
opacity: 1;
text-shadow: none;
margin-top: 0px;
font-size: 38px;
}
}
.modal-body {
.sub-title {
background: #e6e0c5;
margin: 15px;
padding: 10px;
font-size: 23px;
}
}
.modal-footer {
text-align: left;
button {
background-color: #87bc38;
padding: 5px 40px;
font-size: 14px;
border: none;
border-radius: 4px;
display: block;
text-transform: none;
font-family: "Roboto-Regular";
}
}
}
}
.informative-h1 {
margin: 0;
......@@ -2035,6 +2083,16 @@ h2.short {
#collapseFilters > .panel-body {
/*border-top: 1px solid #d5d4d3;*/
padding: 7px 20px 15px 20px;
.addFiltersBtn {
background-color: #87bc38;
padding: 5px 40px;
font-size: 14px;
border: none;
display: block;
border-radius: 4px;
color: $white-color;
}
}
#collapseFilters .panel-body .panel-group .panel-default .panel-body {
padding: 0 0 15px 0;
......@@ -2068,6 +2126,14 @@ h2.short {
border: none;
display: block;
}
.removeFilterBtn {
background-color: #bebaa9;
padding: 5px 20px;
font-size: 14px;
border: none;
display: block;
color: #fff;
}
.filtval.complex {
display: inline-block;
min-width: 85px;
......@@ -6013,4 +6079,4 @@ table.accessions {
padding: 0 10px;
font-family: "Roboto-Bold";
font-size: 30px;
}
\ No newline at end of file
}
<%@ page contentType="charset=UTF-8" pageEncoding="UTF-8" language="java" %>
<%@ taglib prefix="filters" tagdir="/WEB-INF/tags/filters" %>
<filters:additional-filter additionalFilters="${additionalFilters}" appliedFilters="${appliedFilters}" />
......@@ -23,6 +23,14 @@
<!-- Begin page content -->
<div class="container-fluid">
<!-- 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>
</div>
</div>
<!--End modal-->
<div id="loading-popup-id" class="loading-popup">
<div class="loading-popup-content">
<p><spring:message code="prompt.loading-data" /></p>
......@@ -40,7 +48,8 @@
<div class="">
<!--Filters-->
<filters:filter-list availableFilters="${availableFilters}" filters="${filters}"
appliedFilters="${appliedFilters}" crops="${crops}" crop="${crop}"/>
additionalFilters="${additionalFilters}" appliedFilters="${appliedFilters}"
crops="${crops}" crop="${crop}"/>
<!--List-->
<div class="col-lg-10 col-md-9 col-sm-9 col-xs-12 main-col-header">
<div class="nav-header clearfix">
......@@ -138,6 +147,7 @@
</div>
<a class="btn btn-default" id="overviewLink"
style=${(empty additionalFilters)? "'display: inline'": "'display: none'" }
href="<c:url value="/explore/overview"><c:param name="filter">${jsonFilter}</c:param></c:url>">
<span class="glyphicon glyphicon-eye-open"></span>
<span><spring:message code="data-overview.short"/></span>
......@@ -288,6 +298,16 @@
$(document).ready(function () {
if (jsonData.crops != null && jsonData.crops.length > 0) {
$("#panel_additional_id").show();
}
$.each(jsonData, function(key) {
if(key.startsWith('gm:')) {
$("#panel_additional_id").show();
}
});
cropNames = function(){
var data = null;
$.ajax({
......@@ -302,18 +322,13 @@
$("body").on("keypress", ".string-type", function (e) {
if (e.keyCode == 13) {
console.log("press")
var btn = $(this).parent().find("button");
var selectedValue = $(this).parent().parent().find(".like-switcher option:selected").val();
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")
}
}
});
......@@ -336,8 +351,9 @@
BrowseUtil.enableFilter(this, jsonData);
}
var text = $(this).parent().text();
text = text.substring(0, text.indexOf('('));
GenesysFilter.filterList($(this), jsonData, text);
var text2 = $.trim(text);
var text3 = text2.substring(0, text2.indexOf('('));
GenesysFilter.filterList($(this), jsonData, text3);
});
$("body").on("click", ".filter-range", function () {
......@@ -359,8 +375,26 @@
});
$("body").on("click", ".applyBtn", function () {
var addFilterValueBtn = $(this).parent().find("button.filter-auto, button.filter-range");
addFilterValueBtn.trigger("click");
$(this).parent().parent().find("button.filter-auto, button.filter-range").trigger("click");
applyFilters();
BrowseUtil.applySuggestions(jsonData, messages);
});
$("body").on("click", ".removeFilterBtn", function () {
var className = $(this).parent().parent().attr("class");
var filterId = "#panel_" + className;
var filter = className.replace("gm_", "gm:").replace("_id", "");
delete jsonData[filter];
$(filterId).remove();
if (!isExistAdditionalFilters()) {
$("#overviewLink").show();
if (jsonData.crops == null || jsonData.crops.length == 0) {
$("#panel_additional_id").hide();
}
}
applyFilters();
BrowseUtil.applySuggestions(jsonData, messages);
......@@ -381,7 +415,46 @@
BrowseUtil.applySuggestions(jsonData, messages);
$(this).remove();
$('input[i-key=" + normKey + "][value=" + value + "]').prop('checked', false);
$('input[i-key="' + key + '"][value="' + value + '"]').prop('checked', false);
if (jsonData["crops"].length === 0) {
delete jsonData["crops"];
$("#panel_additional_id").hide();
}
});
$("body").on("click", ".addFiltersBtn", function () {
$.ajax("<c:url value="/modal" />", {
type: 'GET',
data: "shortName=" + jsonData.crops,
success: function (data) {
$(".modal-content").empty();
$(".modal-content").append(data);
for (var additionalFilterName in jsonData) {
$(".modal-body .filter-block label > input[value='" + additionalFilterName + "']").prop("checked", true);
}
},
error: function (error) {
console.log(error);
}
});
});
$("body").on("click", ".additional", function () {
var id = $(this).attr("id");
var filterId = "#panel_" + id.replace("_id", "");
var filter = id.replace("gm_", "gm:").replace("_id", "");
if ($(this).is(":checked")) {
GenesysFilterUtil.appendFilter(filter, filterId, jsonData);
$("#overviewLink").hide();
}
else {
delete jsonData[filter];
$(filterId).remove();
$("#overviewLink").show();
}
});
$("#menuShareLink").on("click", function () {
......@@ -439,10 +512,11 @@
$.each($('#collapseFilters').find("div.panel-collapse"), function () {
<c:forEach items="${appliedFilters}" var="appliedFilter">
var collapseDiv = $(this).find($("div[id*='${appliedFilter.key}']"));
if (collapseDiv[0] !== undefined) {
$(this).collapse("show");
}
<c:set var="normalizedAppliedFilter" value="${appliedFilter.key.replace(':', '_').replace('.','-')}"/>
var collapseDiv = $(this).find($("div[id*='${normalizedAppliedFilter}']"));
if (collapseDiv[0] !== undefined) {
$(this).collapse("show");
}
</c:forEach>
});
......@@ -499,6 +573,16 @@
}
});
function isExistAdditionalFilters() {
for(var filter in jsonData) {
if(filter.toString().startsWith("gm:")) {
return true;
}
}
return false;
}
function restoreHeaders() {
$.each($("select.column-changer"), function () {
var index = $(this).attr("x-id");
......@@ -576,9 +660,7 @@
function applyFilters (path) {
document.getElementById('loading-popup-id').style.display = "block";
BrowseUtil.cleanJsonData(jsonData);
var filter = JSON.stringify(jsonData);
console.log("filter: " , filter);
var requestUrl = '//' + location.host + location.pathname + "/json" +
(path !== undefined ? path : "?page=1&" + "filter=" + encodeURIComponent(filter));
requestUrl += "&results=" + results;
......@@ -591,7 +673,6 @@
success: function (response) {
renderData(response);
document.getElementById('loading-popup-id').style.display = "none";
// document.getElementById('error-loading-popup-id').style.display = "block";
$.each($("select.column-changer"), function () {
$(this).change();
});
......@@ -643,8 +724,8 @@
$("#mapLink").attr("href", $("#mapLink").attr("href").replace(re, "filter=" + encodeURIComponent(JSON.stringify(jsonData))));
}
function renderTableBody(pagedData) {
console.log(pagedData);
$("table").find("tbody").remove();
var tbody = $("<tbody/>");
rowsCopy = [];
......
......@@ -13,9 +13,18 @@
<div class="container-fluid">
<!-- 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>
</div>
</div>
<!--End modal-->
<div class="">
<filters:filter-list availableFilters="${availableFilters}" filters="${filters}"
appliedFilters="${appliedFilters}" crops="${crops}" crop="${crop}"/>
additionalFilters="${additionalFilters}" appliedFilters="${appliedFilters}"
crops="${crops}" crop="${crop}"/>
<div class="col-lg-10 col-md-9 col-sm-9 col-xs-12 main-col-header">
<div class="nav-header clearfix">
......@@ -43,6 +52,7 @@
<span class="glyphicon glyphicon-list"></span>
<span style="margin-left: 0.5em;"><spring:message code="view.accessions"/></span></a>
<a class="btn btn-default" id="overviewLink"
style=${(empty additionalFilters)? "'display: inline'": "'display: none'" }
href="<c:url value="/explore/overview"><c:param name="filter">${jsonFilter}</c:param></c:url>">
<span class="glyphicon glyphicon-eye-open"></span>
<span><spring:message code="data-overview.short"/></span>
......@@ -226,6 +236,17 @@
$(document).ready(function () {
BrowseUtil.applySuggestions(jsonData, messages);
$("#panel_additional_id").hide();
if (jsonData.crops != null && jsonData.crops.length > 0) {
$("#panel_additional_id").show();
}
$.each(jsonData, function(key) {
if(key.startsWith('gm:')) {
$("#panel_additional_id").show();
}
});
$(document.getElementsByClassName("btn btn-default btn-back")).on('click', function (event) {
event.preventDefault();
......@@ -242,7 +263,8 @@
$.each($('#collapseFilters').find("div.panel-collapse"), function () {
<c:forEach items="${appliedFilters}" var="appliedFilter">
var collapseDiv = $(this).find($("div[id*='${appliedFilter.key}']"));
<c:set var="normalizedAppliedFilter" value="${appliedFilter.key.replace(':', '_').replace('.','-')}"/>
var collapseDiv = $(this).find($("div[id*='${normalizedAppliedFilter}']"));
if (collapseDiv[0] !== undefined) {
$(this).collapse("show");
}
......@@ -316,6 +338,11 @@
$(this).remove();
$('input[i-key=" + normKey + "][value=" + value + "]').prop('checked', false);
if (jsonData["crops"].length === 0) {
delete jsonData["crops"];
$("#panel_additional_id").hide();
}
});
$("body").on("change", "#more-filters", function () {
......@@ -335,23 +362,62 @@
jsonData[key] = [];
});
$("body").on("click", ".filtval", function (event) {
event.preventDefault();
var key = $(this).attr("i-key");
var normKey = GenesysFilter.normKey(key);
var value = $(this).attr("x-key").replace(normKey, "");
$('#remember-map').on('click', function(e) {
e.preventDefault();
});
if (value == "null") value = null;
GenesysFilterUtil.removeValue(value, key, jsonData);
applyFilters();
BrowseUtil.applySuggestions(jsonData, messages);
$("body").on("click", ".addFiltersBtn", function () {
$.ajax("<c:url value="/modal" />", {
type: 'GET',
data: "shortName=" + jsonData.crops,
success: function (data) {
$(".modal-content").empty();
$(".modal-content").append(data);
$(this).remove();
$('input[i-key=" + normKey + "][value=" + value + "]').prop('checked', false);
for (var additionalFilterName in jsonData) {
$(".modal-body .filter-block label > input[value='" + additionalFilterName + "']").prop("checked", true);
}
},
error: function (error) {
console.log(error);
}
});
});
$('#remember-map').on('click', function(e) {
e.preventDefault();
$("body").on("click", ".additional", function () {
var id = $(this).attr("id");
var filterId = "#panel_" + id.replace("_id", "");
var filter = id.replace("gm_", "gm:").replace("_id", "");
if ($(this).is(":checked")) {
GenesysFilterUtil.appendFilter(filter, filterId, jsonData);
$("#overviewLink").hide();