Skip to content

Commit

Permalink
Merge pull request #628 from ICRAR/eagle-1062
Browse files Browse the repository at this point in the history
Added check for file with newer version that running EAGLE, warn user
  • Loading branch information
james-strauss-uwa authored Aug 22, 2023
2 parents 2409d52 + 8eabcd9 commit a5ccc3d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 28 deletions.
56 changes: 32 additions & 24 deletions src/Eagle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@ export class Eagle {
// determine file extension
const fileExtension = Utils.getFileExtension(file.name);
let fileTypeLoaded: Eagle.FileType = Eagle.FileType.Unknown;
let dataObject = null;
let dataObject: any = null;

if (fileExtension !== "md"){
// attempt to parse the JSON
Expand All @@ -1751,30 +1751,18 @@ export class Eagle {
switch (fileTypeLoaded){
case Eagle.FileType.Graph:
// attempt to determine schema version from FileInfo
const schemaVersion: Daliuge.SchemaVersion = Utils.determineSchemaVersion(dataObject);

const errorsWarnings: Errors.ErrorsWarnings = {"errors":[], "warnings":[]};

// use the correct parsing function based on schema version
switch (schemaVersion){
case Daliuge.SchemaVersion.OJS:
case Daliuge.SchemaVersion.Unknown:
this.logicalGraph(LogicalGraph.fromOJSJson(dataObject, file, errorsWarnings));
break;
const eagleVersion: string = Utils.determineEagleVersion(dataObject);

// warn user if file newer than EAGLE
if (Utils.newerEagleVersion(eagleVersion, (<any>window).version)){
Utils.requestUserConfirm("Newer EAGLE Version", "File " + file.name + " was written with EAGLE version " + eagleVersion + ", whereas the current EAGLE version is " + (<any>window).version + ". Do you wish to load the file anyway?", "Yes", "No", "", (confirmed : boolean) : void => {
if (confirmed){
this._loadGraph(dataObject, file);
}
});
} else {
this._loadGraph(dataObject, file);
}

// show errors/warnings
this._handleLoadingErrors(errorsWarnings, file.name, file.repository.service);

// center graph
this.centerGraph();

// check graph
this.checkGraph();
this.undo().pushSnapshot(this, "Loaded " + file.name);

// if the fileType is the same as the current mode, update the activeFileInfo with details of the repository the file was loaded from
this.updateLogicalGraphFileInfo(file.repository.service, file.repository.name, file.repository.branch, file.path, file.name);
break;

case Eagle.FileType.Palette:
Expand All @@ -1793,6 +1781,26 @@ export class Eagle {
});
};

_loadGraph = (dataObject: any, file: RepositoryFile) : void => {
const errorsWarnings: Errors.ErrorsWarnings = {"errors":[], "warnings":[]};

// load graph
this.logicalGraph(LogicalGraph.fromOJSJson(dataObject, file, errorsWarnings));

// show errors/warnings
this._handleLoadingErrors(errorsWarnings, file.name, file.repository.service);

// center graph
this.centerGraph();

// check graph
this.checkGraph();
this.undo().pushSnapshot(this, "Loaded " + file.name);

// if the fileType is the same as the current mode, update the activeFileInfo with details of the repository the file was loaded from
this.updateLogicalGraphFileInfo(file.repository.service, file.repository.name, file.repository.branch, file.path, file.name);
}

insertRemoteFile = (file : RepositoryFile) : void => {
// flag file as being fetched
file.isFetching(true);
Expand Down
34 changes: 30 additions & 4 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1336,13 +1336,39 @@ export class Utils {
return Eagle.FileType.Unknown;
}

static determineEagleVersion(data: any): string {
if (typeof data.modelData !== 'undefined'){
if (typeof data.modelData.eagleVersion !== 'undefined'){
return data.modelData.eagleVersion;
}
}

return "v-1.-1.-1";
}

// return true iff version0 is newer than version1
static newerEagleVersion(version0: string, version1: string){
//console.log("version0", version0, "version1", version1);

if (version0 === "Unknown" || version1 === "Unknown"){
return false;
}

const v0 = version0.split('v')[1].split('.').map(Number);
const v1 = version1.split('v')[1].split('.').map(Number);

//console.log("v0", v0, "v1", v1);

return (
v0[0] > v1[0] ||
((v0[0] === v1[0]) && (v0[1] > v1[1])) ||
((v0[0] === v1[0]) && (v0[1] === v1[1]) && (v0[2] > v1[2]))
)
}

static determineSchemaVersion(data: any): Daliuge.SchemaVersion {
// appref
if (typeof data.modelData !== 'undefined'){
if (typeof data.modelData.schemaVersion !== 'undefined'){
if (data.modelData.schemaVersion === Daliuge.SchemaVersion.OJS){
return Daliuge.SchemaVersion.OJS;
}
return data.modelData.schemaVersion;
}
}
Expand Down

0 comments on commit a5ccc3d

Please sign in to comment.