Skip to content

Commit

Permalink
Merge pull request #634 from ICRAR/eagle-758
Browse files Browse the repository at this point in the history
Eagle 758
  • Loading branch information
james-strauss-uwa authored Sep 13, 2023
2 parents 0b90b84 + 02fadf6 commit fe26bd5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 8 additions & 0 deletions src/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++){
Expand Down
15 changes: 5 additions & 10 deletions src/Undo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
data : ko.Observable<string>; // TODO: can we store the data as an object, must we go to JSON?
data : ko.Observable<LogicalGraph>;

constructor(description: string, data: string){
constructor(description: string, data: LogicalGraph){
this.description = ko.observable(description);
this.data = ko.observable(data);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 => {
Expand Down
4 changes: 4 additions & 0 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit fe26bd5

Please sign in to comment.