Commit dcac1d5c authored by Luis Ernesto Dominguez Uriostegui's avatar Luis Ernesto Dominguez Uriostegui

cambios de ulises realizados,boton historial de compras

parents 23298339 d55ba54d
# compiled code # project
*.pyc
*.pyc
.idea/ .idea/
__pycache__/
geosentinel/ geosentinel/
geosentinel
db.sqlite3-journal
# django stufff
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
db.sqlite3
media
# virtual env
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# pyenv
.python-version
...@@ -27,4 +27,5 @@ urlpatterns = [ ...@@ -27,4 +27,5 @@ urlpatterns = [
url(r'^reports/', include('reports.urls')), url(r'^reports/', include('reports.urls')),
url(r'^$', RedirectView.as_view(url='/catalog/', permanent=True)), url(r'^$', RedirectView.as_view(url='/catalog/', permanent=True)),
url(r'^accounts/', include('django.contrib.auth.urls')), url(r'^accounts/', include('django.contrib.auth.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) ]
#+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
from django.shortcuts import HttpResponseRedirect from django.shortcuts import HttpResponseRedirect
from django.urls import reverse from django.urls import reverse
# from django.core.urlresolvers import reverse # from django.core.urlresolvers import reverse
class AuthRequiredMiddleware(object): class AuthRequiredMiddleware(object):
def __init__(self, get_response): def __init__(self, get_response):
self.get_response = get_response self.get_response = get_response
def __call__(self, request): def __call__(self, request):
# Code to be executed for each request before # Code to be executed for each request before
# the view (and later middleware) are called. # the view (and later middleware) are called.
response = self.get_response(request) response = self.get_response(request)
print (request.path_info) print(request.path_info)
print (reverse('login')) print(reverse('login'))
# if request.path_info == reverse('ws-news-list2'): # if request.path_info == reverse('ws-news-list2'):
# return response # return response
if not request.user.is_authenticated() and request.path_info != reverse('login'): if not request.user.is_authenticated and request.path_info != reverse('login'):
return HttpResponseRedirect(reverse('login')) return HttpResponseRedirect(reverse('login'))
# Code to be executed for each request/response after # Code to be executed for each request/response after
# the view is called. # the view is called.
return response return response
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -26,33 +26,33 @@ var makeRequest = function (value) { ...@@ -26,33 +26,33 @@ var makeRequest = function (value) {
dataType : 'json', dataType : 'json',
success : function(data) { success : function(data) {
polygonList = data.polygonList; polygonList = data.polygonList;
while (pol_element.firstChild) { while (pol_element.firstChild) {
pol_element.removeChild(pol_element.firstChild); pol_element.removeChild(pol_element.firstChild);
} }
if (polygonList.length <= 0) { if (polygonList.length <= 0) {
var temp = document.querySelector('#city_list_template'); var temp = document.querySelector('#city_list_template');
// filling template // filling template
temp.content.querySelector('li').id = ''; temp.content.querySelector('li').id = '';
temp.content.querySelectorAll('span')[0].textContent = 'No cities matched your search. Try again.'; temp.content.querySelectorAll('span')[0].textContent = 'No cities matched your search. Try again.';
temp.content.querySelectorAll('span')[1].textContent = ''; temp.content.querySelectorAll('span')[1].textContent = '';
temp.content.querySelectorAll('div')[3].textContent = ''; temp.content.querySelectorAll('div')[3].textContent = '';
var clone = document.importNode(temp.content, true); var clone = document.importNode(temp.content, true);
document.querySelector('#polygon-list').appendChild(clone); document.querySelector('#polygon-list').appendChild(clone);
} else { } else {
data.polygonList.forEach(function (polygon) { data.polygonList.forEach(function (polygon) {
var temp = document.querySelector('#city_list_template'); var temp = document.querySelector('#city_list_template');
// filling template // filling template
temp.content.querySelector('li').id = polygon.id; temp.content.querySelector('li').id = polygon.id;
temp.content.querySelectorAll('span')[0].textContent = polygon.city + ", " + polygon.state; temp.content.querySelectorAll('span')[0].textContent = polygon.city + ", " + polygon.state;
temp.content.querySelectorAll('span')[1].textContent = polygon.description; temp.content.querySelectorAll('span')[1].textContent = polygon.description;
temp.content.querySelectorAll('div')[3].textContent = "Fuente: " + polygon.source; temp.content.querySelectorAll('div')[3].textContent = "Fuente: " + polygon.source;
var clone = document.importNode(temp.content, true); var clone = document.importNode(temp.content, true);
document.querySelector('#polygon-list').appendChild(clone); document.querySelector('#polygon-list').appendChild(clone);
}); });
...@@ -84,16 +84,16 @@ function drawPolygon(element) { ...@@ -84,16 +84,16 @@ function drawPolygon(element) {
osmap.removePolygon(); osmap.removePolygon();
// draw wkt polygon // draw wkt polygon
// osmap.addWKTPolygon(polygon.wkt_polygon); osmap.addWKTPolygon(polygon.wkt_polygon);
// format coords to draw // format coords to draw
var coords = osmap.formatCoords(polygon.geojson.geometry.coordinates); // var coords = osmap.formatCoords(polygon.geojson.geometry.coordinates);
// get the biggest area // get the biggest area
var biggest = osmap.getBiggestPolygon(coords); // var biggest = osmap.getBiggestPolygon(coords);
// draw coordsR // draw coordsR
osmap.addPolygon(biggest); // osmap.addPolygon(biggest);
} }
}) })
} }
...@@ -114,7 +114,7 @@ $("#id_polygon").on('keyup', function (e) { ...@@ -114,7 +114,7 @@ $("#id_polygon").on('keyup', function (e) {
// this function cleans list of available products // this function cleans list of available products
function erase_product_list_globe() { function erase_product_list_globe() {
prevfeature = null; prevfeature = new Map();
var pol_element = document.getElementById('product-list-globe'); var pol_element = document.getElementById('product-list-globe');
while (pol_element.firstChild) { while (pol_element.firstChild) {
pol_element.removeChild(pol_element.firstChild); pol_element.removeChild(pol_element.firstChild);
...@@ -140,21 +140,23 @@ function erase_product_list_cart() { ...@@ -140,21 +140,23 @@ function erase_product_list_cart() {
} }
var prevfeature = null; var prevfeature = new Map();
function drawApiResponse(element) { function drawApiResponse(element) {
var list_globe = document.getElementById('product-list-globe').children;
for (var i=0; i<list_globe.length; i++) {
var listElement = list_globe[i];
listElement.style.textDecoration = 'none';
}
for (var i=0; i<product_list.catalog.length; i++) { for (var i=0; i<product_list.catalog.length; i++) {
var data = product_list.catalog[i]; var data = product_list.catalog[i];
if (data.uuid === element.id.replace("-li", '')) { if (data.uuid === element.id.replace("-li", '')) {
element.style.textDecoration = 'underline';
console.log("footprint:\n", data.product.footprint); console.log("footprint:\n", data.product.footprint);
prevfeature = osmap.addfootprint(data.product.footprint, prevfeature); if (!prevfeature.has(data.uuid)){
element.style.textDecoration = 'underline';
prevfeature.set(data.uuid, osmap.addfootprint(data.product.footprint, prevfeature));
}else{
if (prevfeature.length != 0){
element.style.textDecoration = 'none';
osmap.deletefootprint(prevfeature.get(data.uuid));
prevfeature.delete(data.uuid);
}
}
} }
} }
} }
...@@ -162,7 +164,7 @@ function drawApiResponse(element) { ...@@ -162,7 +164,7 @@ function drawApiResponse(element) {
function createProductContainer() { function createProductContainer() {
var temp_1 = document.querySelector('#product_cart_1'); var temp_1 = document.querySelector('#product_cart_1');
// filling template // filling template
temp_1.content.querySelector('span').textContent = "Product"; temp_1.content.querySelector('span').textContent = "Product";
...@@ -178,7 +180,7 @@ $('#ajax-input').focus(function () { ...@@ -178,7 +180,7 @@ $('#ajax-input').focus(function () {
$('#option-list').show(); $('#option-list').show();
OPT_LIST_IS_HIDDEN = false; OPT_LIST_IS_HIDDEN = false;
} }
}).blur(function () { }).blur(function (event) {
INPUT_ON_FOCUS = false; INPUT_ON_FOCUS = false;
if (!OPT_LIST_IS_HIDDEN && $(this).val() && $(event.target).closest('#option-list').length) { if (!OPT_LIST_IS_HIDDEN && $(this).val() && $(event.target).closest('#option-list').length) {
$('#option-list').hide(); $('#option-list').hide();
...@@ -228,7 +230,7 @@ $(document).ready(function () { ...@@ -228,7 +230,7 @@ $(document).ready(function () {
var pol_element = document.getElementById('polygon-list'); var pol_element = document.getElementById('polygon-list');
var typingTimer; var typingTimer;
var typingInterval = 800; //milliseconds var typingInterval = 300; //milliseconds
var productListGlobe = []; var productListGlobe = [];
var cartProductList = []; // this array represent DB where products will be stored var cartProductList = []; // this array represent DB where products will be stored
var productsToObtain = []; var productsToObtain = [];
...@@ -243,17 +245,26 @@ $(document).ready(function () { ...@@ -243,17 +245,26 @@ $(document).ready(function () {
typingTimer = setTimeout(makeRequest.bind(null, value), typingInterval); typingTimer = setTimeout(makeRequest.bind(null, value), typingInterval);
} else { } else {
$('#option-list').hide(); $('#option-list').hide();
while (pol_element.firstChild) { while (pol_element.firstChild) {
pol_element.removeChild(pol_element.firstChild); pol_element.removeChild(pol_element.firstChild);
} }
OPT_LIST_IS_HIDDEN = true; OPT_LIST_IS_HIDDEN = true;
return return
} }
}); });
// disable enter in search input
$('#ajax-input').on('keyup keypress', function(event) {
var keyCode = event.keyCode || event.which;
if (keyCode === 13) {
event.preventDefault();
return false;
}
});
// var PRODUCT_IN_LIST = false; // var PRODUCT_IN_LIST = false;
// function for making POST request to productList in view.py // function for making POST request to productList in view.py
...@@ -304,7 +315,7 @@ $(document).ready(function () { ...@@ -304,7 +315,7 @@ $(document).ready(function () {
temp.content.querySelectorAll('span')[1].textContent = data.product.identifier; temp.content.querySelectorAll('span')[1].textContent = data.product.identifier;
temp.content.querySelectorAll('span')[2].textContent = data.product.size; temp.content.querySelectorAll('span')[2].textContent = data.product.size;
temp.content.querySelectorAll('span')[3].textContent = data.product.instrumentname; temp.content.querySelectorAll('span')[3].textContent = data.product.instrumentname;
var clone = document.importNode(temp.content, true); var clone = document.importNode(temp.content, true);
document.querySelector('#product-list-globe').appendChild(clone); document.querySelector('#product-list-globe').appendChild(clone);
} }
...@@ -397,7 +408,7 @@ $(document).ready(function () { ...@@ -397,7 +408,7 @@ $(document).ready(function () {
productsToObtain = []; productsToObtain = [];
data.product_list.forEach(function (product) { data.product_list.forEach(function (product) {
var temp_2 = document.querySelector('#product_cart_2'); var temp_2 = document.querySelector('#product_cart_2');
// filling template // filling template
temp_2.content.querySelector('li').id = product.uuid; temp_2.content.querySelector('li').id = product.uuid;
temp_2.content.querySelector('h4').id = product.uuid + "-h4"; temp_2.content.querySelector('h4').id = product.uuid + "-h4";
...@@ -424,7 +435,7 @@ $(document).ready(function () { ...@@ -424,7 +435,7 @@ $(document).ready(function () {
} }
}); });
// purchasing products in cart // purchasing products in cart
$('#purchased-product-form').submit(function (event) { $('#purchased-product-form').submit(function (event) {
event.preventDefault(); event.preventDefault();
......
...@@ -121,12 +121,13 @@ OpenStreetMapsClass.prototype.addWKTPolygon = function(wkt) ...@@ -121,12 +121,13 @@ OpenStreetMapsClass.prototype.addWKTPolygon = function(wkt)
document.getElementById("id_polygon").value = wkt; document.getElementById("id_polygon").value = wkt;
} }
OpenStreetMapsClass.prototype.addfootprint = function(wkt, prevFeature) OpenStreetMapsClass.prototype.deletefootprint = function (prevFeature) {
{ if (prevFeature){
if (prevFeature) {
this.vectorLayer.getSource().removeFeature(prevFeature); this.vectorLayer.getSource().removeFeature(prevFeature);
} }
}
OpenStreetMapsClass.prototype.addfootprint = function(wkt, prevFeature){
var format = new ol.format.WKT(); var format = new ol.format.WKT();
var feature = format.readFeature(wkt, { var feature = format.readFeature(wkt, {
...@@ -135,16 +136,16 @@ OpenStreetMapsClass.prototype.addfootprint = function(wkt, prevFeature) ...@@ -135,16 +136,16 @@ OpenStreetMapsClass.prototype.addfootprint = function(wkt, prevFeature)
}); });
var style = new ol.style.Style({ var style = new ol.style.Style({
stroke: new ol.style.Stroke({ stroke: new ol.style.Stroke({
color: '#dc7828', color: getRandomColor(),
width: 1 width: 1
}), }),
fill: new ol.style.Fill({ fill: new ol.style.Fill({
color: 'rgba(255,255,0,0.1)' color: 'rgba(255,255,0,0.1)'
}) })
}) })
feature.setStyle(style); feature.setStyle(style);
this.map.getView().fit(feature.getGeometry(), {duration: 1000, padding: [0, 0, 70, 0]}); this.map.getView().fit(feature.getGeometry(), {duration: 1000, padding: [0, 0, 70, 0]});
this.vectorLayer.getSource().addFeature(feature); this.vectorLayer.getSource().addFeature(feature);
...@@ -263,3 +264,11 @@ OpenStreetMapsClass.prototype.iconStyle = function(url,x,y) ...@@ -263,3 +264,11 @@ OpenStreetMapsClass.prototype.iconStyle = function(url,x,y)
} }
function getRandomColor() {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -12,5 +12,4 @@ urlpatterns = [ ...@@ -12,5 +12,4 @@ urlpatterns = [
url(r'^cartrequest/$', views.saveInCart, name='cart-rqst'), url(r'^cartrequest/$', views.saveInCart, name='cart-rqst'),
url(r'^fromcartrqst/$', views.getFromCart, name='from-cart-rqst'), url(r'^fromcartrqst/$', views.getFromCart, name='from-cart-rqst'),
url(r'^purchcartrqst/$', views.purchaseProduct, name='purch-prod-rqst'), url(r'^purchcartrqst/$', views.purchaseProduct, name='purch-prod-rqst'),
url(r'^scl/$', views.L2ASCL_data, name='L2ASCL-data')
] ]
...@@ -49,6 +49,7 @@ def requestToImage(request): ...@@ -49,6 +49,7 @@ def requestToImage(request):
img_link = request.GET['value'] img_link = request.GET['value']
r = requests.get(img_link, auth=("emmhp", "geoemm29"), stream=True) r = requests.get(img_link, auth=("emmhp", "geoemm29"), stream=True)
img_str = base64.b64encode(r.content) img_str = base64.b64encode(r.content)
img_str = img_str.decode('utf-8')
return JsonResponse({'img': img_str}) return JsonResponse({'img': img_str})
...@@ -89,8 +90,12 @@ def productList(request): ...@@ -89,8 +90,12 @@ def productList(request):
catalog = [] catalog = []
for p in products: for p in products:
# img_link = products[p]['link_icon'] # img_link = products[p]['link_icon']
# img_link = img_link[:img_link.find("/")+2] + "emmhp:geoemm29@" + img_link[img_link.find("/")+2:] # img_link = img_link[:img_link.find("/")+2] + "emmhp:geoemm29@" + img_link[img_link.find("/")+2:]
if products[p].get('tileid') is None:
titleid = products[p]['title'].split("_")
products[p]['tileid'] = titleid[5][1:]
catalog.append({ catalog.append({
'process' : process, 'process' : process,
'start_date' : init_date, 'start_date' : init_date,
...@@ -262,11 +267,11 @@ def purchaseProduct(request): ...@@ -262,11 +267,11 @@ def purchaseProduct(request):
## TODO: Add product L1C to Cart DB after product download. ## ## TODO: Add product L1C to Cart DB after product download. ##
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def L2ASCL_data(request): # def L2ASCL_data(request):
with open("/home/mchc/data.json") as f: # with open("/home/ulises/REPSAT_NAS/mario_repsat_test/T15QZD_sclData.json") as f:
json_data = json.load(f) # json_data = json.load(f)
print(json_data) # print(json_data)
return render(request, 'L2ASCL_data.html', {"labels":",".join([k for k in json_data]), "vegetation":[v["4"] for k,v in json_data.items()] }) # return render(request, 'L2ASCL_data.html', {"labels":",".join([k for k in json_data]), "vegetation":[v["4"] for k,v in json_data.items()] })
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# def purchaseProduct(request): # def purchaseProduct(request):
# """ # """
......
No preview for this file type
This diff is collapsed.
from django.conf.urls import url from django.conf.urls import url
from . import views from . import views
from reports import views
urlpatterns = [ urlpatterns = [
url(r'^$', views.report_L2ASCL, name='report'), url(r'^(?P<report>[\w\-]+)/$', views.report_L2ASCL, name='report'),
url(r'^(?P<report>\w+)$', views.report_L2ASCL, name='report'),
] ]
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
import io
from django.http import FileResponse
from reportlab.pdfgen import canvas
from django.shortcuts import render from django.shortcuts import render
# Create your views here. # Create your views here.
from collections import OrderedDict from collections import OrderedDict
import json import json
#-------------------------------------------------------------------------------
def report_L2ASCL(request, report=0):
with open("/home/mario/NAS_MarioCh/mario_repsat_test/T15QZD_sclData.json") as f: # -------------------------------------------------------------------------------
json_data = OrderedDict(json.load(f)) from reportlab.pdfgen import canvas
graphData = dict()
graphData['type']="line" from GeoInt_SIDT import settings
data=dict()
data['labels'] = [ k for k,v in sorted(json_data.items()) ] def report_L2ASCL(request, report):
# data['click']="chartOnClick" with open("/home/ulises/REPSAT_NAS/mario_repsat_test/"+report+".json") as f:
data['datasets'] = list() json_data = OrderedDict(json.load(f))
labels = set() graphData = dict()
for d in json_data: graphData['type'] = "line"
labels |= set(json_data[d].keys())
labels.remove('date') data = dict()
data['labels'] = [k for k, v in sorted(json_data.items())]
labelNames = ["No Data", "Saturated", "Shadows", "Cloud Shadows", "Vegetation", "Not-Vegetated", "Whater", "Unclassified", "Cloud Medium Probablilty", "Cloud Hight Probablilty", "Thin Cirrus", "Snow"] # data['click']="chartOnClick"
colors = ["Black", "Red", "DarkGray", "Brown", "Green", "Yellow", "Blue", "Grey", "LightGray", "White", "Aqua", "Pink"] data['datasets'] = list()
for l in labels: labels = set()
item = dict() for d in json_data:
item['label'] = labelNames[int(l)] labels |= set(json_data[d].keys())
if l == "0": labels.remove('date')
item['hidden'] = "true"
item['data'] = [ v[l] * 60*60/1000000. for k,v in sorted(json_data.items()) if l in v] labelNames = ["No Data", "Saturated", "Shadows", "Cloud Shadows", "Vegetation", "Not-Vegetated", "Whater",
item['backgroundColor']=colors[int(l)] "Unclassified", "Cloud Medium Probablilty", "Cloud Hight Probablilty", "Thin Cirrus", "Snow"]
data['datasets'].append(item) colors = ["Black", "Red", "DarkGray", "Brown", "Green", "Yellow", "Blue", "Grey", "LightGray", "White", "Aqua",
"Pink"]
graphData['data']=data for l in labels:
item = dict()
# graphData['options']['responsive']=True item['label'] = labelNames[int(l)]
# graphData['options']['maintainAspectRatio']=False # item['fill'] = "false"
print( json.dumps(graphData).encode("utf-8")) if l == "0":
return render(request, 'L2ASCL_data.html', {"graphData":json.dumps(graphData).encode("utf-8")}) item['hidden'] = "true"
item['data'] = [v[l] * 60 * 60 / 1000000. for k, v in sorted(json_data.items()) if l in v]
item['backgroundColor'] = colors[int(l)]
data['datasets'].append(item)
graphData['data'] = data
#print(settings.BASE_URL)
# graphData['options']['responsive']=True
# graphData['options']['maintainAspectRatio']=False
#print(json.dumps(graphData).encode("utf-8"))
return render(request, 'L2ASCL_data.html', {"graphData": json.dumps(graphData), "report_name": report})
# -------------------------------------------------------------------------------
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