diff --git a/frontend/assets/js/canvas.js b/frontend/assets/js/canvas.js index edc7ccb..7a59a7f 100644 --- a/frontend/assets/js/canvas.js +++ b/frontend/assets/js/canvas.js @@ -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() { diff --git a/frontend/index.html b/frontend/index.html index 784783c..c3fa9b2 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -25,6 +25,10 @@

Find Path

+