From e07542abc3ed40b3cf69d45b49f0e58ccdb15855 Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@nibio.no> Date: Fri, 13 Sep 2019 10:30:57 +0200 Subject: [PATCH] First version of observation masking --- VIPSWeb/views.py | 3 ++ .../static/observations/js/observationList.js | 37 +++++++++++++++---- .../templates/observations/detail.html | 3 +- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/VIPSWeb/views.py b/VIPSWeb/views.py index e4cb71dd..e12e45b2 100755 --- a/VIPSWeb/views.py +++ b/VIPSWeb/views.py @@ -83,6 +83,7 @@ def maintenance(request): @cache_page(60 * 10) @gzip_page def vipslogicproxy(request, path): + """ Proxy to use cross domain Ajax GET and POST requests request: Django request object @@ -96,6 +97,8 @@ def vipslogicproxy(request, path): else: return HttpResponseNotAllowed("Permitted methods are POST and GET") params = request.urlencode() + + #print "Params:" + params try: url = "%s://%s/%s" % (settings.VIPSLOGIC_PROTOCOL, settings.VIPSLOGIC_SERVER_NAME,path) diff --git a/observations/static/observations/js/observationList.js b/observations/static/observations/js/observationList.js index 054a89e2..4e849cf8 100644 --- a/observations/static/observations/js/observationList.js +++ b/observations/static/observations/js/observationList.js @@ -134,6 +134,10 @@ var initMap = function( { params.push("cropCategoryId=" + cropCategoryId); } + if(settings.userUuid != null) + { + params.push("userUUID=" + settings.userUuid); + } // Get observations from backend $.getJSON( "/vipslogicproxy/rest/observation/list/filter/" + organizationId + (params.length > 0 ? "?" + params.join("&") : ""), function( data ) { @@ -211,24 +215,40 @@ var displayFeatureDetails = function(pixel, coordinate) { var renderObservationFeatures = function() { var geoJSON = {"type":"FeatureCollection","features":[]}; + for(var i=0;i<allObservations.length;i++) { var observation = allObservations[i]; var obsFeatures = null; // Showing only publicly shared observations with geolocation information - if(!observation.locationIsPrivate && observation.geoInfo !== null && observation.geoInfo.trim() !== "") - { - obsFeatures = JSON.parse(observation.geoInfo).features; - } - else + if(observation.locationIsPrivate) { - continue; + continue; } - for(var j=0; j<obsFeatures.length; j++) + // Have we got geoInfo to show? + if(observation.geoInfo !== null && observation.geoInfo.trim() !== "") { - geoJSON.features.push(obsFeatures[j]); + obsFeatures = JSON.parse(observation.geoInfo).features; + if(obsFeatures !== null) + { + // We have parsed geoinfo successfully. + // If the observation has registered a polygonService, + // that means that the location should be masked by this + // service (for privacy reasons). Otherwise: Add as-is + //if(observation.polygonService !== undefined && observation.polygonService !== null) + //{ + // maskedFeatures.push(obsFeatures[0]); // Using only first feature for simplicity + //} + //else + //{ + for(var j=0; j<obsFeatures.length; j++) + { + geoJSON.features.push(obsFeatures[j]); + } + //} + } } } @@ -239,6 +259,7 @@ var renderObservationFeatures = function() }); observationLayer.getSource().clear(); observationLayer.getSource().addFeatures(drawnfeatures); + //console.info(maskedFeatures); } /** diff --git a/observations/templates/observations/detail.html b/observations/templates/observations/detail.html index 40f4aa9b..49015d4e 100755 --- a/observations/templates/observations/detail.html +++ b/observations/templates/observations/detail.html @@ -60,7 +60,8 @@ <script type="text/javascript" src="{% static "observations/js/observationViewMap.js" %}"></script> <script type="text/javascript"> $(document).ready(function() { - $.getJSON( "/vipslogicproxy/rest/observation/{{observation_id}}/" , function( observation ) { + var uuidParam = settings.userUuid != null ? "?userUUID=" + settings.userUuid : ""; + $.getJSON( "/vipslogicproxy/rest/observation/{{observation_id}}/" + uuidParam , function( observation ) { //console.log(observation); document.getElementById("organismName").innerHTML = getLocalizedOrganismName(observation.organism) + " <i>(" + observation.organism.latinName + ")</i>"; document.getElementById("cropOrganismName").innerHTML = getLocalizedOrganismName(observation.cropOrganism) + " <i>(" + observation.cropOrganism.latinName + ")</i>"; -- GitLab