Skip to content

Commit

Permalink
[Fixes #6182] GNIP 77 - GetFeatureInfo Templating For GeoNode (#6184)
Browse files Browse the repository at this point in the history
 * Some minor improvements

(cherry picked from commit b720ab2)

# Conflicts:
#	geonode/proxy/views.py
  • Loading branch information
afabiani committed Jun 15, 2020
1 parent ea06995 commit 602ad2b
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 32 deletions.
18 changes: 18 additions & 0 deletions geonode/layers/migrations/0031_auto_20200612_1533.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.13 on 2020-06-12 15:33

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('layers', '0030_auto_20200610_0825'),
]

operations = [
migrations.AlterField(
model_name='attribute',
name='featureinfo_type',
field=models.CharField(choices=[('type_property', 'Label'), ('type_href', 'URL'), ('type_image', 'Image'), ('type_video_mp4', 'Video (mp4)'), ('type_video_ogg', 'Video (ogg)'), ('type_video_youtube', 'Video (YouTube - embed)'), ('type_audio', 'Audio'), ('type_iframe', 'IFRAME')], default='type_property', help_text='specifies if the attribute should be rendered with an HTML widget on GetFeatureInfo template.', max_length=255, verbose_name='featureinfo type'),
),
]
18 changes: 18 additions & 0 deletions geonode/layers/migrations/0032_auto_20200612_1544.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.13 on 2020-06-12 15:44

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('layers', '0031_auto_20200612_1533'),
]

operations = [
migrations.AlterField(
model_name='attribute',
name='featureinfo_type',
field=models.CharField(choices=[('type_property', 'Label'), ('type_href', 'URL'), ('type_image', 'Image'), ('type_video_mp4', 'Video (mp4)'), ('type_video_ogg', 'Video (ogg)'), ('type_video_webm', 'Video (webm)'), ('type_video_3gp', 'Video (3gp)'), ('type_video_flv', 'Video (flv)'), ('type_video_youtube', 'Video (YouTube/VIMEO - embedded)'), ('type_audio', 'Audio'), ('type_iframe', 'IFRAME')], default='type_property', help_text='specifies if the attribute should be rendered with an HTML widget on GetFeatureInfo template.', max_length=255, verbose_name='featureinfo type'),
),
]
20 changes: 15 additions & 5 deletions geonode/layers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,16 +455,26 @@ class Attribute(models.Model):
TYPE_PROPERTY = 'type_property'
TYPE_HREF = 'type_href'
TYPE_IMAGE = 'type_image'
TYPE_VIDEO = 'type_video'
TYPE_VIDEO_MP4 = 'type_video_mp4'
TYPE_VIDEO_OGG = 'type_video_ogg'
TYPE_VIDEO_WEBM = 'type_video_webm'
TYPE_VIDEO_3GP = 'type_video_3gp'
TYPE_VIDEO_FLV = 'type_video_flv'
TYPE_VIDEO_YOUTUBE = 'type_video_youtube'
TYPE_AUDIO = 'type_audio'
TYPE_IFRAME = 'type_iframe'

TYPES = ((TYPE_PROPERTY, _("Property-Label"),),
(TYPE_HREF, _("HREF-Link"),),
TYPES = ((TYPE_PROPERTY, _("Label"),),
(TYPE_HREF, _("URL"),),
(TYPE_IMAGE, _("Image",),),
(TYPE_VIDEO, _("Video",),),
(TYPE_VIDEO_MP4, _("Video (mp4)",),),
(TYPE_VIDEO_OGG, _("Video (ogg)",),),
(TYPE_VIDEO_WEBM, _("Video (webm)",),),
(TYPE_VIDEO_3GP, _("Video (3gp)",),),
(TYPE_VIDEO_FLV, _("Video (flv)",),),
(TYPE_VIDEO_YOUTUBE, _("Video (YouTube/VIMEO - embedded)",),),
(TYPE_AUDIO, _("Audio",),),
(TYPE_IFRAME, _("iFrame",),),
(TYPE_IFRAME, _("IFRAME",),),
)
featureinfo_type = models.CharField(
_('featureinfo type'),
Expand Down
2 changes: 2 additions & 0 deletions geonode/layers/templates/layers/layer_metadata_advanced.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ <h5>{% trans "Attributes" %}</h5>
<th>{% trans "Description" %}</th>
<th>{% trans "Display Order" %}</th>
<th>{% trans "Display Type" %}</th>
<th>{% trans "Visible" %}</th>
</tr>
{% for form in attribute_form.forms %}
{% if form.attribute %}
Expand All @@ -137,6 +138,7 @@ <h5>{% trans "Attributes" %}</h5>
<td>{{form.description}}</td>
<td>{{form.display_order}}</td>
<td>{{form.featureinfo_type}}</td>
<td>{{form.visible}}</td>
</tr>
{% endif %}
{% endfor %}
Expand Down
77 changes: 52 additions & 25 deletions geonode/layers/templates/layouts/panels.html
Original file line number Diff line number Diff line change
Expand Up @@ -531,32 +531,45 @@ <h4 class="modal-title" id="exampleModalLabel">{% trans "Message box" %}</h4>
<div>
<div style="padding: 15px">
<div>
{{ attribute_form.management_form }}
<table class="table table-striped table-bordered table-condensed">
<tr class="table-header">
<th style="width:25px;background: #efefef;"></th>
<th>{% trans "Attribute" %}</th>
<th>{% trans "Label" %}</th>
<th>{% trans "Description" %}</th>
<th>{% trans "Display Order" %}</th>
<th>{% trans "Display Type" %}</th>
</tr>
{% for form in attribute_form.forms %}
{% if form.attribute %}
<tr>
<td style="width:25px;background: #efefef;"> <span class="grippy"></span></td>
<td><div style="display:none">{{form.id}}</div>{{form.attribute}}</td>
<td>{{form.attribute_label}}</td>
<td>{{form.description}}</td>
<td>{{form.display_order}}</td>
<td>{{form.featureinfo_type}}</td>
</tr>
{% endif %}
{% endfor %}
</table>
<label>{% trans "Use a custom template?" %}</label>
{{layer_form.use_featureinfo_custom_template}}
{{layer_form.featureinfo_custom_template}}
<input type="checkbox" name="resource-use_featureinfo_custom_template" class="has-external-popover"
data-content="specifies wether or not use a custom GetFeatureInfo template." data-placement="right"
data-container="body" data-html="true" data-toggle="toggle"
placeholder="specifies wether or not use a custom GetFeatureInfo template."
id="id_resource-use_featureinfo_custom_template"
{% if resource.use_featureinfo_custom_template %}checked{% endif %}>
<div id="layer-attributes-panel"
{% if resource.use_featureinfo_custom_template %}style="visibility: collapse;" {% endif %}>
{{ attribute_form.management_form }}
<table class="table table-striped table-bordered table-condensed">
<tr class="table-header">
<th style="width:25px;background: #efefef;"></th>
<th>{% trans "Attribute" %}</th>
<th>{% trans "Label" %}</th>
<th>{% trans "Description" %}</th>
<th>{% trans "Display Order" %}</th>
<th>{% trans "Display Type" %}</th>
<th>{% trans "Visible" %}</th>
</tr>
{% for form in attribute_form.forms %}
{% if form.attribute %}
<tr>
<td style="width:25px;background: #efefef;"> <span class="grippy"></span></td>
<td><div style="display:none">{{form.id}}</div>{{form.attribute}}</td>
<td>{{form.attribute_label}}</td>
<td>{{form.description}}</td>
<td>{{form.display_order}}</td>
<td>{{form.featureinfo_type}}</td>
<td>{{form.visible}}</td>
</tr>
{% endif %}
{% endfor %}
</table>
</div>
<div id="layer-attributes-custom_template"
{% if not resource.use_featureinfo_custom_template %}style="visibility: collapse;" {% endif %}>
{{layer_form.featureinfo_custom_template}}
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -640,4 +653,18 @@ <h4 class="modal-title" id="exampleModalLabel">{% trans "Message box" %}</h4>
</div>
</div>
</div>

<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function (event) {
$('#id_resource-use_featureinfo_custom_template').on('change', function (event) {
if (this.checked) {
$('#layer-attributes-panel').css("visibility", "collapse");
$('#layer-attributes-custom_template').css("visibility", "visible");
} else {
$('#layer-attributes-panel').css("visibility", "visible");
$('#layer-attributes-custom_template').css("visibility", "collapse");
}
});
});
</script>
{% endblock %}
2 changes: 1 addition & 1 deletion geonode/layers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ def layer_metadata(
la = Attribute.objects.get(id=int(form['id'].id))
la.description = form["description"]
la.attribute_label = form["attribute_label"]
la.visible = True if form["attribute_label"] else False # form["visible"]
la.visible = form["visible"]
la.display_order = form["display_order"]
la.featureinfo_type = form["featureinfo_type"]
la.save()
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ django-recaptcha==2.0.6
geonode-oauth-toolkit==1.1.5.1

# GeoNode org maintained apps.
django_mapstore_adapter==2.0.4
django_mapstore_adapter==2.0.4.1
django-geonode-mapstore-client==2.0.5
django-geonode-client==1.0.9
geonode-user-messages==2.0.1
Expand Down

0 comments on commit 602ad2b

Please sign in to comment.