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

#13778 Add chart for species,code moved to crophub.js

parent 3b75c161
......@@ -28,7 +28,10 @@ import javax.persistence.PrePersist;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.apache.commons.lang3.StringUtils;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.genesys2.server.model.GlobalVersionedAuditedModel;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.hibernate.annotations.Type;
......@@ -38,6 +41,7 @@ import org.hibernate.search.annotations.Indexed;
// Add index on all fields
@Table(name = "taxonomy2", uniqueConstraints = { @UniqueConstraint(columnNames = { "genus", "species", "spAuthor", "subtaxa", "subtAuthor" }) })
@Indexed
@JsonIgnoreProperties(ignoreUnknown=true)
public class Taxonomy2 extends GlobalVersionedAuditedModel {
private static final long serialVersionUID = 8881324404490162933L;
......@@ -66,6 +70,7 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel {
private Long taxSpecies;
@JsonIgnore
@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "taxonomy")
private List<CropTaxonomy> cropTaxonomies;
......
......@@ -16,10 +16,7 @@
package org.genesys2.spring.config;
import java.util.HashSet;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;
import java.util.*;
import org.genesys2.spring.AddStuffInterceptor;
import org.genesys2.spring.BetterSessionLocaleResolver;
......@@ -33,6 +30,8 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.validation.Validator;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
......@@ -64,6 +63,17 @@ public class SpringServletConfig extends WebMvcConfigurerAdapter {
registry.addResourceHandler("/html/**").addResourceLocations("/html/");
}
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(converter());
}
@Bean
public MappingJacksonHttpMessageConverter converter() {
MappingJacksonHttpMessageConverter converter = new MappingJacksonHttpMessageConverter();
return converter;
}
@Bean
public ViewResolver viewResolver() {
final org.springframework.web.servlet.view.InternalResourceViewResolver resolver = new org.springframework.web.servlet.view.InternalResourceViewResolver();
......
......@@ -39,7 +39,7 @@
<div class="">
<security:authorize access="hasRole('ADMINISTRATOR') or hasPermission(#faoInstitute, 'ADMINISTRATION')">
<a href="<c:url value="/acl/${faoInstitute.class.name}/${faoInstitute.id}/permissions"><c:param name="back">/wiews/${faoInstitute.code}</c:param></c:url>" class="close"> <spring:message code="edit-acl" /></a>
<%--<a href="<c:url value="/acl/${faoInstitute.class.name}/${faoInstitute.id}/permissions"><c:param name="back">/wiews/${faoInstitute.code}</c:param></c:url>" class="close"> <spring:message code="edit-acl" /></a>--%>
<a href="<c:url value="/wiews/${faoInstitute.code}/edit" />" class="close">
<spring:message code="edit" />
</a>
......@@ -181,73 +181,9 @@
_pageDim = { institute: '${faoInstitute.code}' };
</script>
<script>
jQuery(document).ready(function() {
function makeDataForFlot(data){
var dataFlot = [];
var other = 0;
$.each(data, function (idx, statistic) {
dataFlot[idx] = {
label: statistic[0],
data: statistic[1]
}
});
return dataFlot;
}
$.ajax("/wiews/${faoInstitute.code}/stat-genus", {
success: function (data) {
var placeholder = $('#chartStatsByGenus');
$("<div id='tooltip'></div>").css({
position: "absolute",
display: "none",
border: "1px solid #929292",
padding: "2px",
"background-color": "#929292",
opacity: 0.80
}).appendTo("body");
$.plot(placeholder, makeDataForFlot(data), {
series: {
pie: {
show: true,
label: {
show: false
}
}
},
grid: {
hoverable: true,
clickable: true
},
legend: {
show: false
}
});
placeholder.bind("plothover", function (event, pos, obj) {
if (obj != null) {
var str = obj.series.label + " (" + obj.datapoint[1][0][1] + ")";
$("#hoverdata").text(str);
$("#tooltip").html(str)
.css({top: pos.pageY - 25, left: pos.pageX + 5})
.show();
}else{
$("#tooltip").hide();
}
});
placeholder.bind("plotclick", function (event, pos, obj) {
if (obj != null) {
window.location.replace(window.location.href + "/t/" + obj.series.label);
}
});
},
error: function (error) {
console.log(error);
}
});
jQuery(document).ready(function () {
GenesysChart.chart("#chartStatsByGenus", "/wiews/${faoInstitute.code}/stat-genus", null);
GenesysChart.chart("#chartStatsBySpecies", "/wiews/${faoInstitute.code}/stat-species", null);
});
</script>
</content>
......
......@@ -96,6 +96,108 @@ GenesysMaps.BoundingBox.prototype.getBounds = function() {
return [[this.west, this.south],[this.east, this.north]];
};
GenesysChart = {
chart: function (placeholder, url, options) {
var defaultOptions = {
series: {
pie: {
show: true,
label: {
show: false
}
}
},
grid: {
hoverable: true,
clickable: true
},
legend: {
show: false
}
};
if(options!=null){
defaultOptions=options;
}
$.ajax(url, {
success: function (data) {
$.plot($(placeholder), GenesysChart.makeDataForFlot(data), defaultOptions);
$("<div class='tooltip-chart'></div>").css({
position: "absolute",
display: "none",
border: "1px solid #929292",
padding: "2px",
"background-color": "#929292",
opacity: 0.80
}).appendTo(placeholder);
$(placeholder).bind("plothover", function (event, pos, obj) {
if (obj != null) {
var height= $(placeholder).height();
var width=$(placeholder).width();
var radius = obj.series.pie.label.radius+99 ;
var halfAngle = ((obj.series.startAngle + obj.series.angle) + obj.series.startAngle) / 2;
var x = width/2 + Math.round(Math.cos(halfAngle) * radius);
var y = height/2 + Math.round(Math.sin(halfAngle) * radius);
var str = obj.series.label + " (" + obj.datapoint[1][0][1] + ")";
$($(this).find(".tooltip-chart")).html(str)
.css({top: y, left: x})
.show();
} else {
$($(this).find(".tooltip-chart")).hide();
}
});
$(placeholder).bind("plotclick", function (event, pos, obj) {
if (obj != null) {
var params = obj.series.label.split(" ");
if (typeof params[1] != "undefined") {
window.location.replace(window.location.href + "/t/" + params[0] + "/" + params[1]);
} else {
window.location.replace(window.location.href + "/t/" + params[0]);
}
}
});
},
error: function (error) {
console.log(error);
}
});
},
makeDataForFlot: function (data) {
var dataFlot = [];
$.each(data, function (idx, statistic) {
var label;
if(typeof statistic[0]=="object"){
label=statistic[0]["taxonName"];
}else if(typeof statistic[0]=="string"){
label=statistic[0];
}
dataFlot[idx] = {
label: label,
data: statistic[1]
}
});
return dataFlot;
}
};
GenesysFilter = {
normKey: function(key) {
return key.replace('.','-').replace(':','_');
......
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