Skip to content

Commit

Permalink
✨ [FEAT] Minor fixes for Annotation Categories in HD Views (refs #4032)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chatewgne committed Jul 30, 2024
1 parent 2937618 commit cf980b6
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 11 deletions.
1 change: 0 additions & 1 deletion geotrek/api/v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ def get_annotations(self, obj):
feature["properties"]['category'] = None

Check warning on line 410 in geotrek/api/v2/serializers.py

View check run for this annotation

Codecov / codecov/patch

geotrek/api/v2/serializers.py#L410

Added line #L410 was not covered by tests
return annotations


class Meta(TimeStampedSerializer.Meta):
model = common_models.HDViewPoint
fields = TimeStampedSerializer.Meta.fields + (
Expand Down
14 changes: 13 additions & 1 deletion geotrek/common/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,18 @@ def _init_layout(self):
formactions,
)

def clean_annotations_categories(self):
data = self.cleaned_data["annotations_categories"]
if data is None:
return {}
return data

Check warning on line 556 in geotrek/common/forms.py

View check run for this annotation

Codecov / codecov/patch

geotrek/common/forms.py#L556

Added line #L556 was not covered by tests

def clean_annotations(self):
data = self.cleaned_data["annotations"]
if data is None:
return {}

Check warning on line 561 in geotrek/common/forms.py

View check run for this annotation

Codecov / codecov/patch

geotrek/common/forms.py#L561

Added line #L561 was not covered by tests
return data

class Meta:
model = HDViewPoint
fields = ('annotations', 'annotations_categories' )
fields = ('annotations', 'annotations_categories')
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.13 on 2024-07-23 13:24
# Generated by Django 4.2.13 on 2024-07-30 09:01

from django.db import migrations, models

Expand All @@ -25,4 +25,9 @@ class Migration(migrations.Migration):
'ordering': ['label'],
},
),
migrations.AddField(
model_name='hdviewpoint',
name='annotations_categories',
field=models.JSONField(blank=True, default=dict),
),
]
16 changes: 14 additions & 2 deletions geotrek/common/static/common/js/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,21 @@ function initAnnotationsWidget(map) {
var category_selector = $('#id_annotation_category').clone();
category_selector.attr('for-annotation', id);
category_selector.on("change", update_annotation_category_event)
entry.find('.entry-name').after(category_selector);
entry.find('.entry-validate').before(category_selector);
}
entry.find('.entry-name').text(annotation.name());
if (query.editing == id) {
entry.find('.entry-adjust').hide();
entry.find('.entry-validate').show();
}
$('#annotationlist').append(entry);
if (annotation.type() == 'point' & $("#div_id_annotations_categories textarea").val() != "") {
var annotations_categories = JSON.parse($("#div_id_annotations_categories textarea").val());
previous_category = annotations_categories[id]
if (typeof previous_category !== 'undefined') {
$('#id_annotation_category[for-annotation="' + id + '"]').val(parseInt(previous_category))
}
}
});
$('#annotationheader').css(
'display', $('#annotationlist .entry').length <= 1 ? 'none' : 'block');
Expand All @@ -265,7 +272,11 @@ function initAnnotationsWidget(map) {
}

function update_annotation_category(annotation_id, category_id) {
var annotations_categories = JSON.parse($("#div_id_annotations_categories textarea").val())
if ($("#div_id_annotations_categories textarea").val() != "") {
var annotations_categories = JSON.parse($("#div_id_annotations_categories textarea").val())
} else {
var annotations_categories = {}
}
if (category_id == "") {
delete annotations_categories[annotation_id]
} else {
Expand Down Expand Up @@ -358,6 +369,7 @@ function initAnnotationsWidget(map) {
layer.mode(null);
layer.removeAllAnnotations();
layer.mode(mode);
$("#div_id_annotations_categories textarea").val("")
fromButtonSelect = false;
break;
}
Expand Down
5 changes: 4 additions & 1 deletion geotrek/common/static/common/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fieldset {
}

#id_annotation_category {
width: 25rem;
width: 20rem;
}

.loader-wrapper {
Expand Down Expand Up @@ -177,7 +177,10 @@ fieldset {

.entry {
margin-right: 10px;
margin-bottom: 5px;
overflow: auto;
}

.entry .entry-name {
margin-left: 10px;
margin-right: 10px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,10 @@
{% url 'common:hdviewpoint-drf-detail' object.pk as base_tile_url %}
{{object.annotations|json_script:"geojson_annotations"}}
<div id="hdviewpoint-map" class='large'><span class="loader-wrapper"><span class="loader"></span></span></div>
<script type="text/javascript" src="{% static 'common/js/annotations.js' %}"></script>
<script type="text/javascript" src="{% static 'common/js/hdviewpoint_viewer.js' %}"></script>
<script type="text/javascript" src="{% static 'common/js/geojs-1.10.17-min.js' %}"></script>
<script>
initializeViewer("{{base_tile_url}}", edit_annotations=true);
</script>
{% endblock mainpanel %}

{% block extrabody %}
{{ block.super}}
<script type="text/javascript" src="{% static 'common/js/annotations.js' %}"></script>
{% endblock extrabody %}
1 change: 1 addition & 0 deletions geotrek/common/templates/common/sql/post_90_defaults.sql
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ ALTER TABLE common_hdviewpoint ALTER COLUMN legend SET DEFAULT '';
ALTER TABLE common_hdviewpoint ALTER COLUMN author SET DEFAULT '';
ALTER TABLE common_hdviewpoint ALTER COLUMN uuid SET DEFAULT gen_random_uuid();
ALTER TABLE common_hdviewpoint ALTER COLUMN annotations SET DEFAULT '{}'::jsonb;
ALTER TABLE common_hdviewpoint ALTER COLUMN annotations_categories SET DEFAULT '{}'::jsonb;
ALTER TABLE common_hdviewpoint ALTER COLUMN date_insert SET DEFAULT now();
ALTER TABLE common_hdviewpoint ALTER COLUMN date_update SET DEFAULT now();

Expand Down

0 comments on commit cf980b6

Please sign in to comment.