From 66a394dfd6908c3897ce46368085077bc345874a Mon Sep 17 00:00:00 2001
From: Maximilian Giller <m.giller@tu-bs.de>
Date: Thu, 6 Jan 2022 14:27:51 +0100
Subject: [PATCH] Somewhat implemented storing data in graph on collective
 change

---
 editor/js/graph.js             | 30 +++++++++++++++++++++++-------
 editor/js/tools/collecttool.js | 19 ++++++++++---------
 2 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/editor/js/graph.js b/editor/js/graph.js
index 665a9e5..2703e77 100644
--- a/editor/js/graph.js
+++ b/editor/js/graph.js
@@ -203,19 +203,27 @@ export class Graph extends ManagedData {
         return false;
     }
 
-    changeDetails(selectionDetails) {
+    changeDetails(selectionDetails, storeChange = true) {
         if (selectionDetails.node === true) {
-            this.changeNodeDetails(selectionDetails[NODE_ID], selectionDetails);
+            this.changeNodeDetails(selectionDetails[NODE_ID], selectionDetails, storeChange);
         } else if (selectionDetails.link === true) {
             this.changeLinkDetails(
                 selectionDetails[LINK_SOURCE][NODE_ID],
                 selectionDetails[LINK_TARGET][NODE_ID],
-                selectionDetails
+                selectionDetails,
+                storeChange
             );
         }
     }
 
-    changeNodeDetails(nodeId, newDetails) {
+    changeDetailsOfCollection(collection) {
+        collection.forEach((el) => {
+            this.changeDetails(el, false);
+        });
+        this.storeCurrentData("Changed details of collection");
+    }
+
+    changeNodeDetails(nodeId, newDetails, storeChange = true) {
         var nodes = this.data[GRAPH_NODES];
         for (var i = 0; i < nodes.length; i++) {
             // Is relevant node?
@@ -226,13 +234,17 @@ export class Graph extends ManagedData {
             // Change details
             nodes[i] = Object.assign(nodes[i], newDetails);
 
+
             // All done
-            this.storeCurrentData("Changed node details");
+            if (storeChange) {
+                this.storeCurrentData("Changed node details");
+            }
+
             return;
         }
     }
 
-    changeLinkDetails(sourceId, targetId, newDetails) {
+    changeLinkDetails(sourceId, targetId, newDetails, storeChange = true) {
         var links = this.data[GRAPH_LINKS];
         for (var i = 0; i < links.length; i++) {
             // Is relevant link?
@@ -246,8 +258,12 @@ export class Graph extends ManagedData {
             // Change details
             links[i] = Object.assign(links[i], newDetails);
 
+
             // All done
-            this.storeCurrentData("Changed link details");
+            if (storeChange) {
+                this.storeCurrentData("Changed link details");
+            }
+
             return;
         }
     }
diff --git a/editor/js/tools/collecttool.js b/editor/js/tools/collecttool.js
index 2f8775e..8086033 100644
--- a/editor/js/tools/collecttool.js
+++ b/editor/js/tools/collecttool.js
@@ -20,8 +20,16 @@ export default class CollectTool extends Tool {
     }
 
     onMenuChange(key, value) {
-        if (key === COLLECTION_KEY) {
-            graph.changeDetails(value);
+        if (key !== COLLECTION_KEY) {
+            return;
+        }
+
+        if (value === undefined) {
+            // Clear items if menue says its empty
+            state.clearSelectedItems();
+            this.menu.value(COLLECTION_KEY, []);
+        } else {
+            graph.changeDetailsOfCollection(value);
         }
     }
 
@@ -89,13 +97,6 @@ export default class CollectTool extends Tool {
         this.menu.value(COLLECTION_KEY, state.selectedItems);
     }
 
-    onMenuChange(key, value) {
-        if (key === COLLECTION_KEY && value === undefined) {
-            state.clearSelectedItems();
-            this.menu.value(COLLECTION_KEY, []);
-        }
-    }
-
     setupBoxSelect() {
         window.addEventListener("load", () => {
             // Source: https://github.com/vasturiano/force-graph/issues/151#issuecomment-735850938
-- 
GitLab