@@ -606,6 +699,209 @@
{% trans "External service layer" %}
{% endif %}
+
+
+
{% if GEONODE_SECURITY_ENABLED %}
{% include "_permissions_form_js.html" %}
{% endif %}
diff --git a/geonode/layers/urls.py b/geonode/layers/urls.py
index 957901aa593..af1fdb4e08a 100644
--- a/geonode/layers/urls.py
+++ b/geonode/layers/urls.py
@@ -35,6 +35,7 @@
url(r'^upload$', 'layer_upload', name='layer_upload'),
url(r'^upload_metadata$', 'layer_metadata_upload', name='layer_metadata_upload'),
url(r'^upload_style$', 'layer_sld_upload', name='layer_sld_upload'),
+ url(r'^load_layer_data$', 'load_layer_data', name='load_layer_data'),
url(r'^(?P[^/]*)$', 'layer_detail', name="layer_detail"),
url(r'^(?P[^/]*)/metadata$', 'layer_metadata', name="layer_metadata"),
url(r'^(?P[^/]*)/metadata_advanced$', 'layer_metadata_advanced', name="layer_metadata_advanced"),
diff --git a/geonode/layers/views.py b/geonode/layers/views.py
index 58c2f9e751a..fe586517a09 100644
--- a/geonode/layers/views.py
+++ b/geonode/layers/views.py
@@ -29,6 +29,9 @@
from lxml import etree
from requests import Request
from itertools import chain
+from six import string_types
+from owslib.wfs import WebFeatureService
+from owslib.feature.schema import get_schema
from guardian.shortcuts import get_perms
from django.contrib import messages
@@ -428,14 +431,101 @@ def layer_detail(request, layername, template='layers/layer_detail.html'):
if settings.SOCIAL_ORIGINS:
context_dict["social_links"] = build_social_links(request, layer)
+ layers_names = layer.alternate
+ try:
+ if 'geonode' in layers_names:
+ workspace, name = layers_names.split(':', 1)
+ else:
+ name = layers_names
+ except:
+ print "Can not identify workspace type and layername"
+
+ context_dict["layer_name"] = json.dumps(layers_names)
+
+ try:
+ # get type of layer (raster or vector)
+ if layer.storeType == 'coverageStore':
+ context_dict["layer_type"] = "raster"
+ elif layer.storeType == 'dataStore':
+ context_dict["layer_type"] = "vector"
+
+ location = "{location}{service}".format(** {
+ 'location': settings.OGC_SERVER['default']['LOCATION'],
+ 'service': 'wms',
+ })
+ # get schema for specific layer
+ username = settings.OGC_SERVER['default']['USER']
+ password = settings.OGC_SERVER['default']['PASSWORD']
+ schema = get_schema(location, name, username=username, password=password)
+
+ # get the name of the column which holds the geometry
+ if 'the_geom' in schema['properties']:
+ schema['properties'].pop('the_geom', None)
+ elif 'geom' in schema['properties']:
+ schema['properties'].pop("geom", None)
+
+ # filter the schema dict based on the values of layers_attributes
+ layer_attributes_schema = []
+ for key in schema['properties'].keys():
+ layer_attributes_schema.append(key)
+
+ filtered_attributes = layer_attributes_schema
+ context_dict["schema"] = schema
+ context_dict["filtered_attributes"] = filtered_attributes
+
+ except:
+ print "Possible error with OWSLib. Turning all available properties to string"
# maps owned by user needed to fill the "add to existing map section" in template
if request.user.is_authenticated():
context_dict["maps"] = Map.objects.filter(owner=request.user)
-
return render_to_response(template, RequestContext(request, context_dict))
+# Loads the data using the OWS lib when the "Do you want to filter it" button is clicked.
+def load_layer_data(request, template='layers/layer_detail.html'):
+ context_dict = {}
+ data_dict = json.loads(request.POST.get('json_data'))
+ layername = data_dict['layer_name']
+ filtered_attributes = data_dict['filtered_attributes']
+ workspace, name = layername.split(':')
+ location = "{location}{service}".format(** {
+ 'location': settings.OGC_SERVER['default']['LOCATION'],
+ 'service': 'wms',
+ })
+
+ try:
+ username = settings.OGC_SERVER['default']['USER']
+ password = settings.OGC_SERVER['default']['PASSWORD']
+ wfs = WebFeatureService(location, version='1.1.0', username=username, password=password)
+ response = wfs.getfeature(typename=name, propertyname=filtered_attributes, outputFormat='application/json')
+ x = response.read()
+ x = json.loads(x)
+ features_response = json.dumps(x)
+ decoded = json.loads(features_response)
+ decoded_features = decoded['features']
+ properties = {}
+ for key in decoded_features[0]['properties']:
+ properties[key] = []
+
+ # loop the dictionary based on the values on the list and add the properties
+ # in the dictionary (if doesn't exist) together with the value
+ for i in range(len(decoded_features)):
+
+ for key, value in decoded_features[i]['properties'].iteritems():
+ if value != '' and isinstance(value, (string_types, int, float)):
+ properties[key].append(value)
+
+ for key in properties:
+ properties[key] = list(set(properties[key]))
+ properties[key].sort()
+
+ context_dict["feature_properties"] = properties
+ except:
+ print "Possible error with OWSLib."
+ return HttpResponse(json.dumps(context_dict), content_type="application/json")
+
+
def layer_feature_catalogue(
request,
layername,
diff --git a/geonode/static/geonode/css/base.css b/geonode/static/geonode/css/base.css
index fb7253362d6..a390c29638c 100644
--- a/geonode/static/geonode/css/base.css
+++ b/geonode/static/geonode/css/base.css
@@ -7802,3 +7802,79 @@ footer form {
.table-user-profile-attribute {
font-weight: bold;
}
+/* Download Layer Filtering Modal
+----------------------- */
+.gear {
+ -webkit-animation: rotation 6s infinite linear;
+ -moz-animation: rotation 6s infinite linear;
+ -o-animation: rotation 6s infinite linear;
+ animation: rotation 6s infinite linear;
+}
+@-webkit-keyframes "rotation" {
+ from {
+ -webkit-transform: rotate(0deg);
+ }
+ to {
+ -webkit-transform: rotate(359deg);
+ }
+}
+@-moz-keyframes "rotation" {
+ from {
+ -moz-transform: rotate(0deg);
+ }
+ to {
+ -moz-transform: rotate(359deg);
+ }
+}
+@-o-keyframes "rotation" {
+ from {
+ -o-transform: rotate(0deg);
+ }
+ to {
+ -o-transform: rotate(359deg);
+ }
+}
+@keyframes "rotation" {
+ from {
+ transform: rotate(0deg);
+ }
+ to {
+ transform: rotate(359deg);
+ }
+}
+form-inline {
+ display: inline-table;
+ vertical-align: middle;
+ width: auto;
+}
+.text_area {
+ visibility: hidden;
+}
+.dropdown-menu-attribute {
+ height: auto;
+ max-height: 200px;
+ overflow-x: hidden;
+}
+.dropdown-menu-operator {
+ height: auto;
+ max-height: 200px;
+ overflow-x: hidden;
+}
+.dropdown-menu-and-or {
+ height: auto;
+ max-height: 200px;
+ overflow-x: hidden;
+}
+#wrong-data-type {
+ color: #bd362f;
+ font-style: italic;
+}
+#hr_filter_layer {
+ width: 100%;
+ color: #757575;
+ height: 1px;
+}
+#missing-values {
+ color: #bd362f;
+ font-style: italic;
+}
diff --git a/geonode/static/geonode/less/base.less b/geonode/static/geonode/less/base.less
index 56e504155c4..10b296ab765 100644
--- a/geonode/static/geonode/less/base.less
+++ b/geonode/static/geonode/less/base.less
@@ -1099,3 +1099,80 @@ footer {
.table-user-profile-attribute {
font-weight: bold;
}
+
+/* Download Layer Filtering Modal
+----------------------- */
+.gear {
+ -webkit-animation: rotation 6s infinite linear;
+ -moz-animation: rotation 6s infinite linear;
+ -o-animation: rotation 6s infinite linear;
+ animation: rotation 6s infinite linear;
+}
+@-webkit-keyframes "rotation" {
+ from {
+ -webkit-transform: rotate(0deg);
+ }
+ to {
+ -webkit-transform: rotate(359deg);
+ }
+}
+@-moz-keyframes "rotation" {
+ from {
+ -moz-transform: rotate(0deg);
+ }
+ to {
+ -moz-transform: rotate(359deg);
+ }
+}
+@-o-keyframes "rotation" {
+ from {
+ -o-transform: rotate(0deg);
+ }
+ to {
+ -o-transform: rotate(359deg);
+ }
+}
+@keyframes "rotation" {
+ from {
+ transform: rotate(0deg);
+ }
+ to {
+ transform: rotate(359deg);
+ }
+}
+form-inline {
+ display: inline-table;
+ vertical-align: middle;
+ width: auto;
+}
+.text_area {
+ visibility: hidden;
+}
+.dropdown-menu-attribute {
+ height: auto;
+ max-height: 200px;
+ overflow-x: hidden;
+}
+.dropdown-menu-operator {
+ height: auto;
+ max-height: 200px;
+ overflow-x: hidden;
+}
+.dropdown-menu-and-or {
+ height: auto;
+ max-height: 200px;
+ overflow-x: hidden;
+}
+#wrong-data-type {
+ color: @red-dark;
+ font-style: italic;
+}
+#hr_filter_layer {
+ width: 100%;
+ color: @gray46;
+ height: 1px;
+}
+#missing-values {
+ color: @red-dark;
+ font-style: italic;
+}
diff --git a/geonode/static/geonode/less/variables.less b/geonode/static/geonode/less/variables.less
index 966be15a626..6b015ef8f51 100644
--- a/geonode/static/geonode/less/variables.less
+++ b/geonode/static/geonode/less/variables.less
@@ -19,6 +19,8 @@
@brand-info: #1fa0a0;
@brand-warning: #ff8f31;
@brand-danger: #af0900;
+@red-dark: #bd362f;
+@gray46 : #757575;
//== Scaffolding
//
diff --git a/geonode/static/lib/css/geonode_icon.png b/geonode/static/lib/css/geonode_icon.png
new file mode 100644
index 00000000000..9e9bb24b11f
Binary files /dev/null and b/geonode/static/lib/css/geonode_icon.png differ