Compare commits

...

1 Commits

Author SHA1 Message Date
Ugo Finnendahl 470fb700f4 added delete_edge 5 years ago
  1. 32
      frontend/assets/js/canvas.js
  2. 4
      frontend/index.html
  3. 9
      main.py

@ -207,6 +207,20 @@ function draw_new_edge(edge) {
return group; 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) { function update_edge(konva_edge) {
let line = konva_edge.children[0]; let line = konva_edge.children[0];
let text = konva_edge.children[1]; let text = konva_edge.children[1];
@ -411,6 +425,24 @@ function find_path(data) {
.catch(error => console.error('Error:', error)); .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() { function save_graph() {

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

@ -126,6 +126,15 @@ def create_edge():
return jsonify(edge), 201 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") @app.route("/save")
def save(): def save():
try: try:

Loading…
Cancel
Save