From e7e4844c23648953d3e1c39ac0885f8b170dac8e Mon Sep 17 00:00:00 2001 From: james-strauss-uwa Date: Thu, 7 Sep 2023 17:19:34 +1000 Subject: [PATCH 1/2] Changed storage of undo snapshot to LogicalGraph object instead of string --- src/Undo.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Undo.ts b/src/Undo.ts index cdb1a4371..8e2b80ef6 100644 --- a/src/Undo.ts +++ b/src/Undo.ts @@ -26,19 +26,16 @@ import * as ko from "knockout"; import {Config} from './Config'; import {Eagle} from './Eagle'; -import {Errors} from './Errors'; import {LogicalGraph} from './LogicalGraph'; -import {Repository} from './Repository'; -import {RepositoryFile} from './RepositoryFile'; import {Setting} from './Setting'; import {Utils} from './Utils'; class Snapshot { description: ko.Observable; - data : ko.Observable; // TODO: can we store the data as an object, must we go to JSON? + data : ko.Observable; - constructor(description: string, data: string){ + constructor(description: string, data: LogicalGraph){ this.description = ko.observable(description); this.data = ko.observable(data); } @@ -74,7 +71,7 @@ export class Undo { pushSnapshot = (eagle: Eagle, description: string) : void => { const previousIndex = (this.current() + Config.UNDO_MEMORY_SIZE - 1) % Config.UNDO_MEMORY_SIZE; const previousSnapshot : Snapshot = this.memory()[previousIndex]; - const newContent : string = LogicalGraph.toOJSJsonString(eagle.logicalGraph(), false); + const newContent : LogicalGraph = eagle.logicalGraph().clone(); // check if newContent matches old content, if so, no need to push // TODO: maybe speed this up with checksums? or maybe not required @@ -175,11 +172,9 @@ export class Undo { return; } - const dataObject = JSON.parse(snapshot.data()); - const errorsWarnings: Errors.ErrorsWarnings = {errors: [], warnings: []}; - const dummyFile: RepositoryFile = new RepositoryFile(Repository.DUMMY, "", ""); + const dataObject: LogicalGraph = snapshot.data(); - eagle.logicalGraph(LogicalGraph.fromOJSJson(dataObject, dummyFile, errorsWarnings)); + eagle.logicalGraph(dataObject); } static printTable = () : void => { From 02fadf6cc49fcda8b4bf753ae3e55a6bc74d0b6b Mon Sep 17 00:00:00 2001 From: james-strauss-uwa Date: Fri, 8 Sep 2023 11:28:18 +1000 Subject: [PATCH 2/2] Update Field clone function to also clone the nodeKey attribute. Added additional check to Node.isValid to make sure fields nodeKey attributes are correct. Added fix function. --- src/Field.ts | 1 + src/Node.ts | 8 ++++++++ src/Utils.ts | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/src/Field.ts b/src/Field.ts index 3a735edfd..1520a818e 100644 --- a/src/Field.ts +++ b/src/Field.ts @@ -287,6 +287,7 @@ export class Field { const f = new Field(this.id(), this.displayText(), this.value(), this.defaultValue(), this.description(), this.readonly(), this.type(), this.precious(), options, this.positional(), this.parameterType(), this.usage(), this.keyAttribute()); f.setIsEvent(this.isEvent()); + f.setNodeKey(this.nodeKey()); return f; } diff --git a/src/Node.ts b/src/Node.ts index bc41fb86b..b11675ec4 100644 --- a/src/Node.ts +++ b/src/Node.ts @@ -2175,6 +2175,14 @@ export class Node { } } + // check that all fields "key" attribute is the same as the key of the node they belong to + for (const field of node.getFields()){ + if (field.getNodeKey() !== node.getKey()) { + const issue: Errors.Issue = Errors.ShowFix("Node " + node.getKey() + " (" + node.getName() + ") has a field (" + field.getDisplayText() + ") whose key (" + field.getNodeKey() + ") doesn't match the node (" + node.getKey() + ")", function(){Utils.showNode(eagle, selectedLocation, node.getId())}, function(){Utils.fixFieldKey(eagle, node, field)}, "Set field node key correctly"); + errorsWarnings.errors.push(issue); + } + } + // check that multiple fields don't share the same name // NOTE: this code checks many pairs of fields twice for (let i = 0 ; i < node.getFields().length ; i++){ diff --git a/src/Utils.ts b/src/Utils.ts index 669e1877d..f02a60a38 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -1902,6 +1902,10 @@ export class Utils { field.setType(Daliuge.DataType.Object + "." + field.getType()); } + static fixFieldKey(eagle: Eagle, node: Node, field: Field){ + field.setNodeKey(node.getKey()); + } + static fixMoveEdgeToEmbeddedApplication(eagle: Eagle, edgeId: string){ const edge = eagle.logicalGraph().findEdgeById(edgeId); const srcNode = eagle.logicalGraph().findNodeByKey(edge.getSrcNodeKey());