manage active node

This commit is contained in:
Laura Klünder 2017-07-26 14:39:15 +02:00
parent 047073f7a1
commit 04ffdce424
3 changed files with 60 additions and 1 deletions

View file

@ -162,6 +162,33 @@ editor = {
modal_close.remove();
}
var active_graph_node = content.find('[data-active-node]');
if (active_graph_node.length) {
var active_graph_node_id = active_graph_node.attr('data-active-node');
if (active_graph_node_id !== '') {
if (active_graph_node_id === 'null') {
editor._active_graph_node = null;
editor._active_graph_node_space_transfer = null;
editor._active_graph_node_html = null;
} else {
editor._active_graph_node = active_graph_node_id;
editor._active_graph_node_space_transfer = active_graph_node.is('data-space-transfer');
editor._active_graph_node_html = active_graph_node.html();
}
} else if (editor._active_graph_node_html !== null) {
active_graph_node.html(editor._active_graph_node_html);
} else {
active_graph_node.remove();
}
} else if (!editor._active_graph_node_space_transfer && !editor._in_modal) {
editor._active_graph_node = null;
editor._active_graph_node_space_transfer = null;
editor._active_graph_node_html = null;
}
if (editor._active_graph_node !== null) {
content.find('#id_active_node').val(editor._active_graph_node);
}
var geometry_url = content.find('[data-geometry-url]');
var $body = $('body');
if (geometry_url.length) {
@ -249,6 +276,9 @@ editor = {
_creating: false,
_next_zoom: true,
_graph_editing: null,
_active_graph_node: null,
_active_graph_node_space_transfer: null,
_active_graph_node_html: null,
init_geometries: function () {
// init geometries and edit listeners
editor._highlight_layer = L.layerGroup().addTo(editor.map);
@ -369,6 +399,11 @@ editor = {
style.fillOpacity = 0.5;
}
}
if (feature.properties.type === 'graphnode' && feature.properties.id === editor._active_graph_node) {
style.stroke = true;
style.weight = 3;
style.color = '#ffff00';
}
if (feature.geometry.type === 'LineString') {
style = editor._line_draw_geometry_style(style);
}

View file

@ -23,6 +23,18 @@
</p>
{% bootstrap_messages %}
{% if set_active_node %}
<div data-active-node="{% if active_node %}{{ active_node.pk }}{% else %}null{% endif %}"{% if active_node.space_transfer %} data-space-transfer{% endif %} class="well well-sm">
<strong>{% trans 'Active node:' %} {{ active_node.pk }}</strong>{% if active_node.space_transfer %} <em>({% trans 'space transfer node' %})</em>{% endif %}<br>
{% with space_title=active_node.space.title level_title=active_node.space.level.title %}
{% blocktrans %}in space {{ space_title }}{% endblocktrans %}<br>
{% blocktrans %}on level {{ level_title }}{% endblocktrans %}
{% endwith %}
</div>
{% else %}
<div data-active-node class="well well-sm"></div>
{% endif %}
<form action="{{ request.path }}" method="post" data-graph-editing="{{ graph_editing }}" {% if nozoom %}data-nozoom {% endif %}>
{% csrf_token %}

View file

@ -384,11 +384,17 @@ def graph_edit(request, level=None, space=None):
graph_action_form = GraphEditorActionForm(request=request, allow_clicked_position=allow_clicked_position,
data=request.POST)
if node_settings_form.is_valid() and edge_settings_form.is_valid() and graph_action_form.is_valid():
set_active_node = False
active_node = graph_action_form.cleaned_data['active_node']
clicked_node = graph_action_form.cleaned_data['clicked_node']
clicked_position = graph_action_form.cleaned_data.get('clicked_position')
if clicked_node is not None and clicked_position is None:
raise NotImplementedError
node_click_setting = graph_editing_settings['node_click']
if node_click_setting == 'connect_or_toggle':
set_active_node = True
active_node = clicked_node
else:
raise NotImplementedError
elif clicked_node is None and clicked_position is not None:
click_anywhere_setting = graph_editing_settings['click_anywhere']
if click_anywhere_setting != 'create_node_if_none_active' or active_node is None:
@ -403,6 +409,12 @@ def graph_edit(request, level=None, space=None):
messages.error(request, _('You can not edit changes on this changeset.'))
messages.success(request, _('New graph node created!'))
if set_active_node:
ctx.update({
'set_active_node': set_active_node,
'active_node': active_node,
})
ctx.update({
'nozoom': True,
})