Skip to content

Commit

Permalink
Fixed the last of the compilation bugs after refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
james-strauss-uwa committed Aug 13, 2024
1 parent aabd99a commit 363ba87
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 60 deletions.
78 changes: 18 additions & 60 deletions src/Eagle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export class Eagle {

palettes : ko.ObservableArray<Palette>;
logicalGraph : ko.Observable<LogicalGraph>;
graphConfigs : ko.ObservableArray<GraphConfig>;
currentConfig : ko.Observable<GraphConfig>;
tutorial : ko.Observable<Tutorial>;

Expand Down Expand Up @@ -145,7 +144,6 @@ export class Eagle {

this.palettes = ko.observableArray();
this.logicalGraph = ko.observable(null);
this.graphConfigs = ko.observableArray();
this.currentConfig = ko.observable(new GraphConfig());
this.eagleIsReady = ko.observable(false);

Expand Down Expand Up @@ -1318,6 +1316,7 @@ export class Eagle {
loadLocalDaliugeFile = () : void => {
const daliugeFileInputElement : HTMLInputElement = <HTMLInputElement> document.getElementById("daliugeFileToLoad");
const fileFullPath : string = daliugeFileInputElement.value;
const errorsWarnings : Errors.ErrorsWarnings = {"errors":[], "warnings":[]};
const eagle: Eagle = this;

// abort if value is empty string
Expand All @@ -1335,11 +1334,17 @@ export class Eagle {
reader.onload = function (evt) {
const data: string = evt.target.result.toString();

eagle._loadDaliugeJSON(data, fileFullPath);

// TODO: should fineInfo(modelData) be in the LG or the EAGLE object
eagle.logicalGraph().fileInfo().repositoryService = Repository.Service.File;
eagle.logicalGraph().fileInfo.valueHasMutated();
eagle._loadGraphJSON(data, fileFullPath, (lg: LogicalGraph) : void => {
const parentNode: Node = new Node(Utils.uuidv4(), Utils.newKey(eagle.logicalGraph().getNodes()), lg.fileInfo().name, lg.fileInfo().getText(), Category.SubGraph);

eagle.insertGraph(lg.getNodes(), lg.getEdges(), parentNode, errorsWarnings);

// TODO: handle errors and warnings

eagle.checkGraph();
eagle.undo().pushSnapshot(eagle, "Insert Logical Graph");
eagle.logicalGraph.valueHasMutated();
});
}
reader.onerror = function (evt) {
console.error("error reading file", evt);
Expand All @@ -1350,47 +1355,6 @@ export class Eagle {
daliugeFileInputElement.value = "";
}

private _loadDaliugeJSON = (data: string, fileFullPath: string) => {
let dataObject;

// attempt to parse the JSON
try {
dataObject = JSON.parse(data);
}
catch(err){
Utils.showUserMessage("Error parsing file JSON", err.message);
return;
}

// determine file type
const loadedFileType : Eagle.FileType = Utils.determineFileType(dataObject);

// abort if not a daliuge file
if (loadedFileType !== Eagle.FileType.Daliuge){
Utils.showUserMessage("Error", "This is not a config file! Looks like a " + loadedFileType);
return;
}

const errorsWarnings: Errors.ErrorsWarnings = {"errors":[], "warnings":[]};
const logicalGraph: LogicalGraph = LogicalGraph.fromOJSJson(dataObject.graph, RepositoryFile.DUMMY, errorsWarnings);

const graphConfigs : GraphConfig[] = [];
for (const configObject of dataObject.configurations){
graphConfigs.push(GraphConfig.fromJson(dataObject, errorsWarnings));
}

// show errors (if found)
this._handleLoadingErrors(errorsWarnings, Utils.getFileNameFromFullPath(fileFullPath), Repository.Service.File);

// update attributes of eagle
this.graphConfigs(graphConfigs);

// show the left window
this.leftWindow().shown(true);

Utils.showNotification("Success", Utils.getFileNameFromFullPath(fileFullPath) + " has been loaded.", "success");
}

/**
* The following two functions allows the file selectors to be hidden and let tags 'click' them
*/
Expand Down Expand Up @@ -1755,11 +1719,12 @@ export class Eagle {

console.log("commitToGitAs()");
let fileInfo : ko.Observable<FileInfo>;
let obj : LogicalGraph | Palette | Eagle;
let obj : LogicalGraph | Palette;

// determine which object of the given filetype we are committing
switch (fileType){
case Eagle.FileType.Graph:
case Eagle.FileType.Daliuge:
fileInfo = this.logicalGraph().fileInfo;
obj = this.logicalGraph();
break;
Expand All @@ -1775,10 +1740,6 @@ export class Eagle {
obj = palette;
break;
}
case Eagle.FileType.Daliuge:
fileInfo = this.logicalGraph().fileInfo;
obj = this;
break;
default:
Utils.showUserMessage("Not implemented", "Not sure which fileType to commit :" + fileType);
reject("Not sure which fileType to commit:" + fileType);
Expand Down Expand Up @@ -1837,11 +1798,12 @@ export class Eagle {
*/
commitToGit = async (fileType : Eagle.FileType) : Promise<void> => {
let fileInfo : ko.Observable<FileInfo>;
let obj : LogicalGraph | Palette | Eagle;
let obj : LogicalGraph | Palette;

// determine which object of the given filetype we are committing
switch (fileType){
case Eagle.FileType.Graph:
case Eagle.FileType.Daliuge:
fileInfo = this.logicalGraph().fileInfo;
obj = this.logicalGraph();
break;
Expand All @@ -1858,10 +1820,6 @@ export class Eagle {
obj = palette;
break;
}
case Eagle.FileType.Daliuge:
fileInfo = this.logicalGraph().fileInfo;
obj = this;
break;
default:
Utils.showUserMessage("Not implemented", "Not sure which fileType is the right one to commit :" + fileType);
break;
Expand Down Expand Up @@ -1907,7 +1865,7 @@ export class Eagle {
this._commit(repository, fileType, fileInfo().path, fileInfo().name, fileInfo, commitMessage, obj);
}

_commit = (repository: Repository, fileType: Eagle.FileType, filePath: string, fileName: string, fileInfo: ko.Observable<FileInfo>, commitMessage: string, obj: LogicalGraph | Palette | Eagle) : void => {
_commit = (repository: Repository, fileType: Eagle.FileType, filePath: string, fileName: string, fileInfo: ko.Observable<FileInfo>, commitMessage: string, obj: LogicalGraph | Palette) : void => {
// check that repository was found, if not try "save as"!
if (repository === null){
this.commitToGitAs(fileType);
Expand All @@ -1920,7 +1878,7 @@ export class Eagle {
/**
* Saves a graph/palette file to the GitHub repository.
*/
saveDiagramToGit = (repository : Repository, fileType : Eagle.FileType, filePath : string, fileName : string, fileInfo: ko.Observable<FileInfo>, commitMessage : string, obj: LogicalGraph | Palette | Eagle) : void => {
saveDiagramToGit = (repository : Repository, fileType : Eagle.FileType, filePath : string, fileName : string, fileInfo: ko.Observable<FileInfo>, commitMessage : string, obj: LogicalGraph | Palette) : void => {
console.log("saveDiagramToGit() repositoryName", repository.name, "fileType", fileType, "filePath", filePath, "fileName", fileName, "commitMessage", commitMessage);

const clone: LogicalGraph | Palette | Eagle = obj.clone();
Expand Down
3 changes: 3 additions & 0 deletions src/LogicalGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { Edge } from './Edge';
import { Errors } from './Errors';
import { Field } from './Field';
import { FileInfo } from './FileInfo';
import { GraphConfig } from './GraphConfig';
import { GraphUpdater } from './GraphUpdater';
import { Node } from './Node';
import { RepositoryFile } from './RepositoryFile';
Expand All @@ -42,6 +43,7 @@ export class LogicalGraph {
fileInfo : ko.Observable<FileInfo>;
private nodes : ko.ObservableArray<Node>;
private edges : ko.ObservableArray<Edge>;
private graphConfigs : ko.ObservableArray<GraphConfig>;
private issues : ko.ObservableArray<{issue:Errors.Issue, validity:Errors.Validity}> //keeps track of higher level errors on the graph

constructor(){
Expand All @@ -51,6 +53,7 @@ export class LogicalGraph {
this.fileInfo().builtIn = false;
this.nodes = ko.observableArray([]);
this.edges = ko.observableArray([]);
this.graphConfigs = ko.observableArray([]);
this.issues = ko.observableArray([])
}

Expand Down

0 comments on commit 363ba87

Please sign in to comment.