Commit c21cc935 authored by igoshin's avatar igoshin Committed by Matija Obreza

#13466 save and load filters

parent e1e8147e
package org.genesys2.server.servlet.controller;
import org.genesys2.server.servlet.model.MapFilter;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@Component
@Scope("session")
public class FilterSelectionBean implements Serializable {
private static final long serialVersionUID = -1084615112110837714L;
private final List<MapFilter> filters = new ArrayList<>();
public List<MapFilter> getFilters(){
return filters;
}
public void addFilter(MapFilter filter){
filters.add(filter);
}
}
package org.genesys2.server.servlet.controller;
import org.genesys2.server.servlet.model.MapFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
@Scope("request")
@RequestMapping("/filter")
public class MapFilterController extends BaseController {
@Autowired
private FilterSelectionBean filterSelectionBean;
@RequestMapping(value = "/get", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<MapFilter> getMapFilters() {
return filterSelectionBean.getFilters();
}
@RequestMapping(value = "/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public void saveMapFilter(@RequestBody MapFilter filter) {
filterSelectionBean.addFilter(filter);
}
}
package org.genesys2.server.servlet.model;
import java.io.Serializable;
public class MapFilter implements Serializable {
private String title;
private String filter;
private String color;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getFilter() {
return filter;
}
public void setFilter(String filter) {
this.filter = filter;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
}
......@@ -316,6 +316,10 @@ selection.empty-list-warning=You have not added any accessions to the list.
selection.add-many=Check and add
selection.add-many.accessionIds=List accession IDs as used in Genesys separated by space or new line.
filters=Filters
filters.saved=Saved filters
filters.save=Save filter
filter.enter.title=Enter filter title
filters.page.title=Data filters
filters.view=Current filters
filter.filters-applied=You have applied filters.
......
......@@ -26,8 +26,46 @@
</div>
</div>
</div>
<div class="row">
<div class="applied-filters">
<ul class="nav nav-pills ">
<li class="active dropdown form-horizontal pull-right" id="get-filters">
<a class="dropdown-toggle" data-toggle="dropdown" href="#"><spring:message code="filters.saved"/></a>
<ul class="dropdown-menu"></ul>
</li>
<li style="margin-right: 5px" class="active form-horizontal pull-right" data-toggle="modal" data-target="#modal-dialog">
<a href="#"><spring:message code="filters.save"/></a>
</li>
</ul>
</div>
<!-- Modal -->
<div class="modal fade" id="modal-dialog" tabindex="-1" role="dialog" aria-labelledby="modal-label" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="modal-label"><spring:message code="filters.save"/></h4>
</div>
<div class="modal-body">
<input type="text" class="form-control" placeholder="<spring:message code="filter.enter.title"/>" id="filter-title">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><spring:message code="cancel"/></button>
<button id="save-filter" type="button" class="btn btn-primary" data-dismiss="modal"><spring:message code="save"/></button>
</div>
</div>
</div>
</div>
<%--End modal--%>
<div class="row">
<div class="col-sm-12">
<div id="map" class="gis-map gis-map-square"></div>
</div>
......@@ -36,7 +74,59 @@
<content tag="javascript">
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(document).ready(function() {
$("#save-filter").on("click", function(event) {
event.preventDefault();
var title = $("#filter-title").val();
var filter=${jsonFilter};
var color = "red";
$.ajax({
url : "/filter/save",
type : "post",
dataType : "json",
contentType: 'application/json; charset=utf-8',
data : JSON.stringify({
title : title,
filter : JSON.stringify(filter),
color:color
}),
success : function(data) {
},
error : function(error) {
console.log(error)
}
});
});
$("#get-filters").on("click", function(event) {
event.preventDefault();
$.ajax({
url: "/filter/get",
type: "get",
dataType: "json",
contentType: 'application/json; charset=utf-8',
success: function (data) {
console.log(data)
$.each(data, function (idx, filter) {
var li = "<li><a href='#'>" + filter.title + "</a></li>";
if ($(".dropdown-menu").is(":visible")) {
$(".dropdown-menu").append(li);
} else {
$(".dropdown-menu").empty();
}
});
},
error : function(error) {
console.log(error)
}
});
});
var map = L.map('map').setView([20,0], 2);
L.tileLayer('https://otile{s}-s.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.png', {
attribution: "MapQuest",
......
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