Skip to content
Snippets Groups Projects
Commit 355a2a7b authored by Maximilian Giller's avatar Maximilian Giller :squid:
Browse files

Implemented deletion with selection box

parent 3a1890ec
No related branches found
No related tags found
No related merge requests found
Pipeline #52782 passed
...@@ -21,7 +21,7 @@ export default class DeleteTool extends Tool { ...@@ -21,7 +21,7 @@ export default class DeleteTool extends Tool {
onBoxSelect(left, bottom, top, right) { onBoxSelect(left, bottom, top, right) {
// Filter out selected nodes // Filter out selected nodes
const hitNodes = []; const selectedNodes = [];
const tl = renderer.screen2GraphCoords(left, top); const tl = renderer.screen2GraphCoords(left, top);
const br = renderer.screen2GraphCoords(right, bottom); const br = renderer.screen2GraphCoords(right, bottom);
graph.data[Graph.GRAPH_NODES].forEach((node) => { graph.data[Graph.GRAPH_NODES].forEach((node) => {
...@@ -31,13 +31,25 @@ export default class DeleteTool extends Tool { ...@@ -31,13 +31,25 @@ export default class DeleteTool extends Tool {
br.y > node.y && br.y > node.y &&
node.y > tl.y node.y > tl.y
) { ) {
hitNodes.push(node); selectedNodes.push(node);
} }
}); });
// Delete selected items after confirmation // Was anything even selected?
console.log("DELETE"); if (selectedNodes.length <= 0) {
console.log(hitNodes); return;
}
// Ask for confirmation to delete
var nodeNames = selectedNodes.map((n) => n[Graph.NODE_LABEL]);
//! Problem: If browser is not actually showing the alerts, it always returns false!
var shouldDelete = confirm("Do you wanna delete all these nodes:\n\n" + nodeNames.join("\n"))
// Delete if confirmed
if (shouldDelete) {
var nodeIds = selectedNodes.map((n) => n[Graph.NODE_ID]);
graph.deleteNodes(nodeIds);
}
} }
onNodeClick(node) { onNodeClick(node) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment