Skip to content

Commit

Permalink
Use the graphConfig from the logicalGraph in the output Daliuge JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
james-strauss-uwa committed Aug 9, 2024
1 parent ca29436 commit 35ef5fd
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 27 deletions.
68 changes: 49 additions & 19 deletions src/GraphConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import * as ko from "knockout";
import { Eagle } from "./Eagle";
import { Errors } from "./Errors";
import { Field } from "./Field";
import { FileInfo } from "./FileInfo";
import { LogicalGraph } from "./LogicalGraph";
import { ParameterTable } from "./ParameterTable";
import { Utils } from "./Utils";

export class GraphConfigField {
private id: ko.Observable<string>;
Expand Down Expand Up @@ -182,22 +179,33 @@ export class GraphConfigNode {
}

export class GraphConfig {
fileInfo : ko.Observable<FileInfo>;
private name: ko.Observable<string>;
private description: ko.Observable<string>;

private isModified: ko.Observable<boolean>;
private isFavorite: ko.Observable<boolean>;

private nodes: ko.ObservableArray<GraphConfigNode>;

constructor(){
this.fileInfo = ko.observable(new FileInfo());
this.fileInfo().type = Eagle.FileType.GraphConfig;
this.fileInfo().readonly = false;
this.fileInfo().builtIn = false;
this.name = ko.observable("");
this.description = ko.observable("");

this.isModified = ko.observable(false);
this.isFavorite = ko.observable(false);

this.nodes = ko.observableArray([]);
}

clone = () : GraphConfig => {
const result : GraphConfig = new GraphConfig();

result.fileInfo(this.fileInfo().clone());
result.name(this.name());
result.description(this.description());

result.isModified(this.isModified());
result.isFavorite(this.isFavorite());

// copy nodes
for (const node of this.nodes()){
result.nodes.push(node.clone());
Expand All @@ -206,6 +214,19 @@ export class GraphConfig {
return result;
}

getName = (): string => {
return this.name();
}

setName = (name: string): GraphConfig => {
this.name(name);
return this;
}

setIsModified = (isModified: boolean): void => {
this.isModified(isModified);
}

getNodes = (): GraphConfigNode[] => {
return this.nodes();
}
Expand Down Expand Up @@ -275,6 +296,18 @@ export class GraphConfig {
static fromJson(data: any, errorsWarnings: Errors.ErrorsWarnings) : GraphConfig {
const result: GraphConfig = new GraphConfig();

if (typeof data.name !== 'undefined'){
result.name(data.name);
}

if (typeof data.description !== 'undefined'){
result.description(data.description);
}

if (typeof data.isFavorite !== 'undefined'){
result.isFavorite(data.isFavorite);
}

if (typeof data.nodes !== 'undefined'){
for (const nodeId in data.nodes){
const nodeData = data.nodes[nodeId];
Expand All @@ -287,11 +320,12 @@ export class GraphConfig {
return result;
}

static toJson(graphConfig: GraphConfig, graph: LogicalGraph) : object {
static toJson(graphConfig: GraphConfig) : object {
const result : any = {};

result.modelData = FileInfo.toOJSJson(graphConfig.fileInfo());
result.graphData = FileInfo.toOJSJson(graph.fileInfo());
// NOTE: we don't write isModified to JSON, it is run-time only
result.isFavorite = graphConfig.isFavorite();
result.description = graphConfig.description();

// add nodes
result.nodes = {};
Expand All @@ -303,17 +337,13 @@ export class GraphConfig {
return result;
}

static toJsonString(graphConfig: GraphConfig, graph: LogicalGraph) : string {
static toJsonString(graphConfig: GraphConfig) : string {
let result: string = "";

const json: any = GraphConfig.toJson(graphConfig, graph);
const json: any = GraphConfig.toJson(graphConfig);

// NOTE: manually build the JSON so that we can enforce ordering of attributes (modelData first)
result += "{\n";
result += '"modelData": ' + JSON.stringify(json.modelData, null, 4) + ",\n";
result += '"graphData": ' + JSON.stringify(json.graphData, null, 4) + ",\n";
result += '"nodes": ' + JSON.stringify(json.nodes, null, 4) + "\n";
result += "}\n";
result += JSON.stringify(json, null, 4);

return result;
}
Expand Down
24 changes: 16 additions & 8 deletions src/ParameterTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class ParameterTable {
return eagle.selectedNode()?.getFields();

case ParameterTable.Mode.GraphConfig:
const config: GraphConfig = eagle.graphConfig();
const config: GraphConfig = eagle.currentConfig();
const lg: LogicalGraph = eagle.logicalGraph();
const displayedFields: Field[] = [];

Expand Down Expand Up @@ -334,19 +334,27 @@ export class ParameterTable {
}

static requestAddField(currentField: Field): void {
const graphConfig: GraphConfig = Eagle.getInstance().graphConfig();
const graphConfig: GraphConfig = Eagle.getInstance().currentConfig();

graphConfig.addField(currentField);

if (graphConfig.fileInfo().name === ""){
if (graphConfig.getName() === ""){

ParameterTable.closeModal();

Utils.newDiagram(Eagle.FileType.GraphConfig, (name: string) => {
graphConfig.fileInfo().name = name;
graphConfig.fileInfo.valueHasMutated();

Utils.requestUserString("New Configuration", "Enter a name for the new configuration", "New Config", false, (completed : boolean, userString : string) : void => {
ParameterTable.openModal(ParameterTable.mode(), ParameterTable.SelectType.Normal);

if (!completed){
return;
}
if (userString === ""){
Utils.showNotification("Invalid name", "Please enter a name for the new object", "danger");
return;
}

graphConfig.setName(userString);
graphConfig.setIsModified(true);
});
}
}
Expand Down Expand Up @@ -375,7 +383,7 @@ export class ParameterTable {

static requestEditCommentInModal(currentField:Field) : void {
const currentNode: Node = Eagle.getInstance().logicalGraph().findNodeByKeyQuiet(currentField.getNodeKey());
const configField: GraphConfigField = Eagle.getInstance().graphConfig().findNodeById(currentNode.getId()).findFieldById(currentField.getId());
const configField: GraphConfigField = Eagle.getInstance().currentConfig().findNodeById(currentNode.getId()).findFieldById(currentField.getId());

//ParameterTable.openModal(ParameterTable.Mode.Unknown, ParameterTable.SelectType.Normal);
ParameterTable.closeModal();
Expand Down

0 comments on commit 35ef5fd

Please sign in to comment.