highlight access restriction spaces in editor geometries

This commit is contained in:
Laura Klünder 2024-12-11 13:54:37 +01:00
parent 8721cc3b1c
commit c44582c114
6 changed files with 57 additions and 29 deletions

View file

@ -107,6 +107,7 @@ def conditional_geojson(obj, update_cache_key_match):
result = obj.to_geojson()
result['properties']['changed'] = obj._affected_by_changeset
result['properties']['access_restriction'] = getattr(obj, "access_restriction_id", None)
return result

View file

@ -65,6 +65,7 @@ class EditorGeometriesPropertiesSchema(BaseSchema):
] = None
overlay: Optional[EditorID] = None
opacity: Optional[float] = None # todo: range
access_restriction: Optional[PositiveInt] = None
class EditorGeometriesGraphEdgePropertiesSchema(BaseSchema):

View file

@ -1045,8 +1045,15 @@ editor = {
editor._line_geometries.push(layer);
layer.length = Math.pow(Math.pow(layer._latlngs[0].lat - layer._latlngs[1].lat, 2) + Math.pow(layer._latlngs[0].lng - layer._latlngs[1].lng, 2), 0.5);
}
if (feature.properties.type === editor._highlight_type) {
var list_elem = $('#sidebar').find('[data-list] tr[data-pk=' + String(feature.properties.id) + ']');
if (feature.properties.type === editor._highlight_type
|| (editor._highlight_type == "accessrestriction" && feature.properties.access_restriction)) {
var highlight_id;
if (editor._highlight_type == "accessrestriction") {
highlight_id = feature.properties.access_restriction;
} else {
highlight_id = feature.properties.id;
}
var list_elem = $('#sidebar').find('[data-list] tr[data-pk=' + String(highlight_id) + ']');
if (list_elem.length === 0) return;
var highlight_layer = L.geoJSON(layer.feature, {
style: function () {
@ -1060,7 +1067,8 @@ editor = {
pointToLayer: editor._point_to_layer
}).getLayers()[0].addTo(editor._highlight_layer);
highlight_layer.list_elem = list_elem;
editor._highlight_geometries[feature.properties.id] = highlight_layer;
if (!editor._highlight_geometries[highlight_id]) editor._highlight_geometries[highlight_id] = [];
editor._highlight_geometries[highlight_id].push(highlight_layer);
highlight_layer.on('mouseover', editor._hover_geometry_layer)
.on('mouseout', editor._unhover_geometry_layer)
.on('click', editor._click_geometry_layer)
@ -1139,9 +1147,13 @@ editor = {
},
_click_mapitem_row: function () {
if (editor._loading_geometry) return;
var geometry = editor._highlight_geometries[parseInt($(this).parent().attr('data-pk'))];
if (geometry !== undefined) {
editor.map.flyToBounds(geometry.getBounds(), {
geometries = editor._highlight_geometries[parseInt($(this).parent().attr('data-pk'))];
if (geometries !== undefined) {
var bounds = geometries[0].getBounds();
for (let gemmetry of geometries.slice(1)) {
bounds = bounds.extend(geometry.getBounds());
}
editor.map.flyToBounds(bounds, { // todo fly to combined bounds
maxZoom: 4,
duration: 0.5,
padding: [20, 20]
@ -1151,12 +1163,12 @@ editor = {
_hover_geometry_layer: function (e) {
// hover callback for a geometry layer
if (editor._loading_geometry) return;
editor._highlight_geometry(e.target.feature.properties.id);
editor._highlight_geometry((editor._highlight_type == "accessrestriction") ? e.target.feature.properties.access_restriction : e.target.feature.properties.id);
},
_unhover_geometry_layer: function (e) {
// unhover callback for a geometry layer
if (editor._loading_geometry) return;
editor._unhighlight_geometry(e.target.feature.properties.id);
editor._unhighlight_geometry((editor._highlight_type == "accessrestriction") ? e.target.feature.properties.access_restriction : e.target.feature.properties.id);
},
_click_geometry_layer: function (e) {
// click callback for a geometry layer scroll the corresponding itemtable row into view if it exists
@ -1172,26 +1184,30 @@ editor = {
},
_highlight_geometry: function (id) {
// highlight a geometries layer and itemtable row if they both exist
var geometry = editor._highlight_geometries[id];
if (!geometry) return;
geometry.setStyle({
color: '#FFFFDD',
weight: 3,
opacity: 1,
fillOpacity: 0
});
geometry.list_elem.addClass('highlight');
var geometries = editor._highlight_geometries[id];
if (!geometries) return;
for (geometry of geometries) {
geometry.setStyle({
color: '#FFFFDD',
weight: 3,
opacity: 1,
fillOpacity: 0
});
geometry.list_elem.addClass('highlight');
}
},
_unhighlight_geometry: function (id) {
// unhighlight whatever is highlighted currently
var geometry = editor._highlight_geometries[id];
if (!geometry) return;
geometry.setStyle({
weight: 3,
opacity: 0,
fillOpacity: 0
});
geometry.list_elem.removeClass('highlight');
var geometries = editor._highlight_geometries[id];
if (!geometries) return;
for (geometry of geometries) {
geometry.setStyle({
weight: 3,
opacity: 0,
fillOpacity: 0
});
geometry.list_elem.removeClass('highlight');
}
},
// graph events

View file

@ -2,7 +2,9 @@
<ul data-levels>
{% for l in levels %}
<li>
<a data-id="{{ l.pk }}" href="{% if level_as_pk %}{% url level_url pk=l.id %}{% else %}{% url level_url level=l.id %}{% endif %}"{% if level.primary_level == l %} class="current"{% endif %}>{{ l.title }}</a>
<a data-id="{{ l.pk }}"
href="{% if level_geometry_urls %}/api/v2/editor/geometries/level/{{ l.id }}{% elif level_as_pk %}{% url level_url pk=l.id %}{% else %}{% url level_url level=l.id %}{% endif %}"
{% if level.primary_level == l %} class="current"{% endif %}>{{ l.title }}</a>
</li>
{% endfor %}
</ul>

View file

@ -34,7 +34,7 @@ class LevelChildEditUtils(DefaultEditUtils):
@property
def _geometry_url(self):
return '/api/v2/editor/geometries/level/' + str(self.level.primary_level_pk)
return '/api/v2/editor/geometries/level/' + str(self.level.primary_level_pk) # todo: resolve correctly
class SpaceChildEditUtils(DefaultEditUtils):
@ -54,4 +54,4 @@ class SpaceChildEditUtils(DefaultEditUtils):
@property
def _geometry_url(self):
return '/api/v2/editor/geometries/space/'+str(self.space.pk)
return '/api/v2/editor/geometries/space/'+str(self.space.pk) # todo: resolve correctly

View file

@ -21,7 +21,7 @@ from c3nav.editor.views.base import (APIHybridError, APIHybridFormTemplateRespon
APIHybridMessageRedirectResponse, APIHybridTemplateContextResponse,
editor_etag_func, sidebar_view, accesses_mapdata)
from c3nav.mapdata.models import Level, Space, LocationGroupCategory, GraphNode, GraphEdge
from c3nav.mapdata.models.access import AccessPermission
from c3nav.mapdata.models.access import AccessPermission, AccessRestriction
from c3nav.mapdata.utils.user import can_access_editor
@ -530,6 +530,14 @@ def list_objects(request, model=None, level=None, space=None, explicit_edit=Fals
'grouped_objects': grouped_objects,
})
if model is AccessRestriction:
levels = list(Level.objects.filter(Level.q_for_request(request), on_top_of__isnull=True))
ctx.update({
"levels": levels,
"level_geometry_urls": True,
"geometry_url": '/api/v2/editor/geometries/level/' + str(levels[0].pk) # todo: resolve correctly,
})
return APIHybridTemplateContextResponse('editor/list.html', ctx,
fields=('can_create', 'create_url', 'objects'))