Commit 7b5384db authored by Emmanuel René Huchim Puc's avatar Emmanuel René Huchim Puc

Merge branch 'dev' of gitlab.geoint.mx:mario.chirinos/GeoInt_SIDT into dev

parents 7b25002f a46e40a0
...@@ -121,6 +121,9 @@ USE_TZ = True ...@@ -121,6 +121,9 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/ # https://docs.djangoproject.com/en/1.10/howto/static-files/
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
STATIC_URL = '/static/' STATIC_URL = '/static/'
# Redirect to home URL after login (Default redirects to /accounts/profile/) # Redirect to home URL after login (Default redirects to /accounts/profile/)
......
// // Get the <datalist> and <input> elements.
// var input = document.getElementById('ajax-input');
// var value = input.value;
// var dataList = document.getElementById('polygon-list');
// console.log("VALUE:", value);
// // Create a new XMLHttpRequest.
// var request = new XMLHttpRequest();
//
// // Handle state changes for the request.
// request.onreadystatechange = function(response) {
// if (request.readyState === 4) {
// if (request.status === 200) {
// // Parse the JSON
// var jsonOptions = JSON.parse(request.responseText);
//
// // Loop over the JSON array.
// jsonOptions.forEach(function(item) {
// // Create a new <option> element.
// var option = document.createElement('option');
// // Set the value using the item in the JSON array.
// option.value = item;
// // Add the <option> element to the <datalist>.
// dataList.appendChild(option);
// });
//
// // Update the placeholder text.
// input.placeholder = "Search...";
// } else {
// // An error occured :(
// input.placeholder = "Couldn't load datalist options :(";
// }
// }
// };
//
// // Update the placeholder text.
// input.placeholder = "Loading options...";
//
// // Set up and make the request.
// request.open('POST', 'http://localhost:8080/catalog/searchsubmit/', true);
// request.send({
// value: value
// });
$(document).ready(function () {
var input = document.getElementById('ajax-input');
var dataList = document.getElementById('polygon-list');
$('#ajax-input').on('input', function(e) {
var value = $(this).val();
if (value === '') return;
console.log(value);
// console.log("TOKEN: ", document.getElementsByName('csrfmiddlewaretoken')[0].value);
$.ajax({
type: "POST",
url: "http://localhost:8080/catalog/searchsubmit/",
data: {
'csrfmiddlewaretoken': document.getElementsByName('csrfmiddlewaretoken')[0].value,
'value': value
},
dataType: 'json',
success: function(data) {
// console.log("DATA: ", data);
// data.forEach(function(polygon) {
// console.log(polygon);
// // Create a new <option> element
// var option = document.createElement('option');
// // Set the value using the item in the JSON array
// option.value = polygon.city + " " + polygon.state;
// // Add the <option> element to the <datalist>.
// dataList.appendChild(option);
// });
$('#ajax-input').autocomplete({
source: data
});
}
});
});
});
\ No newline at end of file
...@@ -195,7 +195,7 @@ ...@@ -195,7 +195,7 @@
<script src="{% static 'adminlte/dist/js/adminlte.min.js' %}"></script> <script src="{% static 'adminlte/dist/js/adminlte.min.js' %}"></script>
{% block scripts %}{% endblock %} {% block scripts %}{% endblock %}
<script src="{% static 'js/dataRetrieval.js' %}" type="text/javascript"></script>
</body> </body>
</html> </html>
{% extends "base_top.html" %} {% extends "base_top.html" %}
{% load static %} {% load staticfiles %}
{% block headMedia %} {% block headMedia %}
<link rel="stylesheet" href="{% static 'css/map.css'%}" type="text/css"> <link rel="stylesheet" href="{% static 'css/map.css'%}" type="text/css">
...@@ -119,19 +119,23 @@ ...@@ -119,19 +119,23 @@
{% block sidebar %} {% block sidebar %}
<div class="form-group "> <div class="form-group ">
<!-- search form --> <!-- search form -->
<form action="{% url 'regionSearched' %}" method="post" class="sidebar-form"> <form role="form" action="{% url 'search-submit' %}" method="post" class="sidebar-form">
{% csrf_token %} {% csrf_token %}
<div class="input-group"> <div class="input-group">
<input type="text" name="value" class="form-control" placeholder="Search..."> <input type="text" id="ajax-input" list="polygon-list" name="value" class="form-control" placeholder="Search...">
<span class="input-group-btn"> <datalist id="polygon-list">
<button type="submit" name="search" id="search-btn" class="btn btn-flat"><i class="fa fa-search"></i> {# <option value="merida">#}
</button> {# <option value="otro">#}
</span> </datalist>
</div> <span class="input-group-btn">
</form> <button type="submit" name="search" id="search-btn" class="btn btn-flat"><i class="fa fa-search"></i>
<!-- /.search form --> </button>
<!-- sidebar menu: : style can be found in sidebar.less --> </span>
</div>
</form>
<!-- /search form -->
<!-- sidebar menu: : style can be found in sidebar.less -->
<form role="form" target="catalogFrame" action="{% url 'productList' %}"> <form role="form" target="catalogFrame" action="{% url 'productList' %}">
<ul class="sidebar-menu" data-widget="tree"> <ul class="sidebar-menu" data-widget="tree">
<!-- <li class="header">Filters</li>--> <!-- <li class="header">Filters</li>-->
......
{% if searchValue %}
{% if data %}
<ul>
{% for pol in data %}
<li>{{ pol.name }}</li>
{% endfor %}
</ul>
{% endif %}
{% else %}
<h1>ERROR</h1>
{% endif %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
{% if searchValue %}
{% if data %}
{% include 'search_options.html' %}
{% endif %}
{% else %}
<h1>Nothing found.</h1>
{% endif %}
</body>
</html>
\ No newline at end of file
...@@ -5,7 +5,8 @@ from . import views ...@@ -5,7 +5,8 @@ from . import views
urlpatterns = [ urlpatterns = [
url(r'^$', views.map, name='map'), url(r'^$', views.map, name='map'),
url(r'^productlist/', views.productList, name='productList'), url(r'^productlist/$', views.productList, name='productList'),
url(r'^regionsearched/', views.regionSearched, name='regionSearched') url(r'^regionsearched/$', views.regionSearched, name='regionSearched'),
url(r'^searchsubmit/$', views.SearchSubmitView.as_view(), name='search-submit')
] ]
...@@ -4,10 +4,12 @@ from __future__ import unicode_literals ...@@ -4,10 +4,12 @@ from __future__ import unicode_literals
from django.shortcuts import render from django.shortcuts import render
from catalog.forms import ASFSearchForm from catalog.forms import ASFSearchForm
from catalog.models import Polygon from catalog.models import Polygon
from django.http import HttpResponseRedirect from django.http import HttpResponse
from django.urls import reverse from django.urls import reverse
from django.views.generic.base import View
from django.template import loader
from urllib import urlencode from urllib import urlencode
import requests import requests, json
# Create your views here. # Create your views here.
...@@ -47,6 +49,46 @@ def productList(request): ...@@ -47,6 +49,46 @@ def productList(request):
return render(request,'productList.html',{}) #"catalog":json[0]}) return render(request,'productList.html',{}) #"catalog":json[0]})
#-------------------------------------------------------------------------------
class SearchSubmitView(View):
template = 'map.html'
# template = 'search_submit.html'
state_parser = {'31': "Yucatán"}
def post(self, request):
template = loader.get_template(self.template)
searchValue = request.POST.get('value', '')
## A simple query for Polygon objects whose name is 'searchValue'
polygonList = Polygon.objects.filter(name=searchValue)
data = []
if len(polygonList) > 0:
for polygon in polygonList:
polygonInfo = json.loads(polygon.json_info)
# data.append({
# 'city' : polygon.name,
# 'state' : self.state_parser[polygonInfo['properties']['CVE_ENT']],
# 'geojson': polygon.json_info
# })
data.append({
'city': polygonInfo['properties']['NOMGEO'],
'state': self.state_parser[polygonInfo['properties']['CVE_ENT']],
'geojson': polygonInfo
})
# context = {
# 'searchValue': searchValue,
# 'data': json.dumps(data, ensure_ascii=True)
# }
# rendered_template = template.render(context, request)
print("DATA:", data)
# return HttpResponse(rendered_template, content_type='application/json')
return HttpResponse(json.dumps(data, ensure_ascii=True), content_type='application/json')
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def regionSearched(request): def regionSearched(request):
""" """
......
No preview for this file type
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