added delete_edge

Ugo Finnendahl 5 years ago
parent 05daae0152
commit 0d5778ada4
  1. 32
      frontend/assets/js/canvas.js
  2. 4
      frontend/index.html
  3. 9
      main.py

@ -202,6 +202,20 @@ function draw_new_edge(edge) {
return group;
}
function remove_canvas_edge(edge){
let konva_edge = stage.findOne('#' + edge["start"] + edge["end"]);
if (!konva_edge){
konva_edge = stage.findOne('#' + edge["end"] + edge["start"]);
}
if (konva_edge){
konva_edges.splice(konva_edges.indexOf(konva_edge),1);
graph_copy[edge["start"]].splice(graph_copy[edge["start"]].indexOf(edge["end"]),1);
graph_copy[edge["end"]].splice(graph_copy[edge["end"]].indexOf(edge["start"]),1);
konva_edge.remove();
edge_layer.draw();
}
}
function update_edge(konva_edge) {
let line = konva_edge.children[0];
let text = konva_edge.children[1];
@ -404,6 +418,24 @@ function find_path(data) {
.catch(error => console.error('Error:', error));
}
function delete_edge(data) {
if (data.length < 2) {
show_info("Select 2 nodes.");
return;
}
rest_req("DELETE", "edges/" + data[0].attrs.id + "/" + data[1].attrs.id, null)
.then(function(res) {
if (res["error"]) {
show_info(res["error"]);
} else {
remove_canvas_edge(res);
selected = [];
draw_selected_nodes();
}
})
.catch(error => console.error('Error:', error));
}
//-----------------------------------------------------------------------------
function save_graph() {

@ -25,6 +25,10 @@
<img src="{{ url_for('static', filename='imgs/share.svg') }}">
<h1>Find Path</h1>
</button>
<button type="button" onclick="delete_edge(selected)">
<img src="{{ url_for('static', filename='imgs/drawing.svg') }}">
<h1>Delete Edge</h1>
</button>
</nav>
<footer>
<div id="infobar"></div>

@ -122,6 +122,15 @@ def create_edge():
return jsonify(edge), 201
@app.route('/api/edges/<start>/<end>', methods=['DELETE'])
def delete_edge(start, end):
if start in graph and end in graph[start]:
del graph[start][end]
del graph[end][start]
return jsonify({"start":start,"end":end}), 200
@app.route("/save")
def save():
try:

Loading…
Cancel
Save