Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Wicenec committed Nov 7, 2024
2 parents e76731c + 7556112 commit 7fb3e9d
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 65 deletions.
13 changes: 2 additions & 11 deletions src/Eagle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,6 @@ export class Eagle {
// clone existing active config, assign new id
const c: GraphConfig = new GraphConfig
c.setId(Utils.generateGraphConfigId());


c.setName('newConfig');

Expand Down Expand Up @@ -1664,7 +1663,6 @@ export class Eagle {
// 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 Down Expand Up @@ -1743,7 +1741,6 @@ export class Eagle {
// 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 Down Expand Up @@ -1785,8 +1782,6 @@ export class Eagle {
Utils.showUserMessage('Error', 'Graph is not chosen! Open existing or create a new graph.');
} else if (fileType == Eagle.FileType.Palette) {
Utils.showUserMessage('Error', 'Palette is not chosen! Open existing or create a new palette.');
} else if (fileType === Eagle.FileType.Daliuge) {
Utils.showUserMessage('Error', 'Daliuge is not chosen! Open existing or create a new daliuge.');
}
return;
}
Expand Down Expand Up @@ -1826,7 +1821,6 @@ export class Eagle {

let jsonString: string = "";
switch (fileType){
case Eagle.FileType.Daliuge:
case Eagle.FileType.Graph:
jsonString = LogicalGraph.toOJSJsonString(<LogicalGraph>clone, false);
break;
Expand Down Expand Up @@ -2016,7 +2010,6 @@ export class Eagle {
}

switch (fileTypeLoaded){
case Eagle.FileType.Daliuge:
case Eagle.FileType.Graph: {
// attempt to determine schema version from FileInfo
const eagleVersion: string = Utils.determineEagleVersion(dataObject);
Expand Down Expand Up @@ -2417,7 +2410,7 @@ export class Eagle {
console.log("saveGraphToDisk()", graph.fileInfo().name, graph.fileInfo().type);

// check that the fileType has been set for the logicalGraph
if (graph.fileInfo().type !== Eagle.FileType.Graph && graph.fileInfo().type !== Eagle.FileType.Daliuge){
if (graph.fileInfo().type !== Eagle.FileType.Graph){
Utils.showUserMessage("Error", "Graph fileType not set correctly. Could not save file.");
return;
}
Expand Down Expand Up @@ -3924,7 +3917,7 @@ export class Eagle {
$('#editFieldModalTypeInput').val(newType).trigger("change");
}

tableDropdownClick = (newType:string, field: Field) : void => {
tableDropdownClick = (newType: Daliuge.DataType, field: Field) : void => {
// if the field contains no options, then it's value will be immediately set to undefined
// therefore, we add at least one option, so the value remains well defined
if (newType === Daliuge.DataType.Select){
Expand All @@ -3936,7 +3929,6 @@ export class Eagle {

// update the type of the field
field.setType(newType);

}

changeNodeParent = () : void => {
Expand Down Expand Up @@ -4828,7 +4820,6 @@ export namespace Eagle
}

export enum FileType {
Daliuge = "Daliuge",
Graph = "Graph",
Palette = "Palette",
JSON = "JSON",
Expand Down
12 changes: 6 additions & 6 deletions src/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class Field {
private defaultValue : ko.Observable<string>; // default value
private description : ko.Observable<string>;
private readonly : ko.Observable<boolean>;
private type : ko.Observable<string>;
private type : ko.Observable<Daliuge.DataType>; // NOTE: this is a little unusual (type can have more values than just the enum)
private precious : ko.Observable<boolean>; // indicates that the field is somehow important and should always be shown to the user
private options : ko.ObservableArray<string>;
private positional : ko.Observable<boolean>;
Expand All @@ -45,7 +45,7 @@ export class Field {

private issues : ko.ObservableArray<{issue:Errors.Issue, validity:Errors.Validity}>//keeps track of issues on the field

constructor(id: FieldId, displayText: string, value: string, defaultValue: string, description: string, readonly: boolean, type: string, precious: boolean, options: string[], positional: boolean, parameterType: Daliuge.FieldType, usage: Daliuge.FieldUsage){
constructor(id: FieldId, displayText: string, value: string, defaultValue: string, description: string, readonly: boolean, type: Daliuge.DataType, precious: boolean, options: string[], positional: boolean, parameterType: Daliuge.FieldType, usage: Daliuge.FieldUsage){
this.displayText = ko.observable(displayText);
this.value = ko.observable(value);
this.defaultValue = ko.observable(defaultValue);
Expand Down Expand Up @@ -176,7 +176,7 @@ export class Field {
this.readonly(!this.readonly())
}

getType = () : string => {
getType = () : Daliuge.DataType => {
return this.type();
}

Expand Down Expand Up @@ -204,7 +204,7 @@ export class Field {
this.defaultValue((!Utils.asBool(this.defaultValue())).toString());
}

setType = (type: string) : void => {
setType = (type: Daliuge.DataType) : void => {
this.type(type);
}

Expand Down Expand Up @@ -665,7 +665,7 @@ export class Field {
let name: string = "";
let description: string = "";
let readonly: boolean = false;
let type: string = Daliuge.DataType.Unknown;
let type: Daliuge.DataType = Daliuge.DataType.Unknown;
let value: string = "";
let defaultValue: string = "";
let precious: boolean = false;
Expand Down Expand Up @@ -754,7 +754,7 @@ export class Field {
static fromOJSJsonPort(data : any) : Field {
let name: string = "";
let event: boolean = false;
let type: string;
let type: Daliuge.DataType = Daliuge.DataType.Unknown;
let description: string = "";
let encoding: Daliuge.Encoding = Daliuge.Encoding.Pickle;

Expand Down
39 changes: 19 additions & 20 deletions src/LogicalGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class LogicalGraph {
this.nodes = ko.observableArray([]);
this.edges = ko.observableArray([]);
this.graphConfigs = ko.observableArray([]);
this.activeGraphConfigId = ko.observable()
this.activeGraphConfigId = ko.observable(null); // can be null, or an id (can't be undefined)
this.issues = ko.observableArray([])
}

Expand Down Expand Up @@ -127,12 +127,7 @@ export class LogicalGraph {
}

// saving the id of the active graph configuration
const activeGraphConfigId = Eagle.getInstance().logicalGraph().activeGraphConfigId()
if(activeGraphConfigId === undefined){
result.activeGraphConfigId = ''
}else{
result.activeGraphConfigId = activeGraphConfigId
}
result.activeGraphConfigId = Eagle.getInstance().logicalGraph().activeGraphConfigId();

return result;
}
Expand Down Expand Up @@ -220,15 +215,10 @@ export class LogicalGraph {
}

//if the saved 'activeGraphConfigId' is empty or missing, we use the last one in the array, else we set the saved one as active
if(dataObject["activeGraphConfigId"] === '' || dataObject["activeGraphConfigId"] === undefined){
// if graph has no configs, we can't use the last one in the array, so we'll set the active id to 'undefined'
if (result.graphConfigs().length === 0){
result.activeGraphConfigId(undefined);
} else {
result.activeGraphConfigId(result.graphConfigs()[result.graphConfigs().length - 1].getId() as GraphConfig.Id)
}
if(typeof dataObject.activeGraphConfigId === 'undefined' || dataObject.activeGraphConfigId === ''){
result.activeGraphConfigId(null);
}else{
result.activeGraphConfigId(dataObject["activeGraphConfigId"] as GraphConfig.Id)
result.activeGraphConfigId(dataObject.activeGraphConfigId);
}
}

Expand Down Expand Up @@ -370,7 +360,7 @@ export class LogicalGraph {

// duplicate, set active and graph as modified
this.addGraphConfig(clone)
this.setActiveGraphConfig(clone.getId())
this.activeGraphConfigId(clone.getId())
this.fileInfo().modified = true;

Utils.showNotification("Duplicated Config", "as '" + clone.getName() + "' and set to active config", "success");
Expand Down Expand Up @@ -398,15 +388,24 @@ export class LogicalGraph {
return;
}

// cache name of graph configuration
// cache name, id of graph configuration
const name: string = this.graphConfigs()[index].getName();
const id: GraphConfig.Id = this.graphConfigs()[index].getId();

// remove graph config
this.graphConfigs.splice(index, 1);

// if the removed graph config is also the active config, then we need to unset the active config
if (this.activeGraphConfigId() === id){
this.activeGraphConfigId(null);
}

// create undo snapshot
const eagle: Eagle = Eagle.getInstance();
eagle.undo().pushSnapshot(eagle, "Removed graph configuration " + name);

// check graph
eagle.checkGraph();
}

getActiveGraphConfig = (): GraphConfig => {
Expand Down Expand Up @@ -435,7 +434,7 @@ export class LogicalGraph {
this.nodes([]);
this.edges([]);
this.graphConfigs([]);
this.activeGraphConfigId(undefined)
this.activeGraphConfigId(null)
}

clone = () : LogicalGraph => {
Expand Down Expand Up @@ -970,15 +969,15 @@ export class LogicalGraph {
}

// check that active graph config id actually refers to a graph config in the graphConfigs dict
if (graph.activeGraphConfigId() !== undefined && graph.activeGraphConfigId() !== ""){
if (graph.activeGraphConfigId() !== null){
if (graph.getActiveGraphConfig() === null){
const issue: Errors.Issue = Errors.Fix(
"Active Graph Config Id (" + graph.activeGraphConfigId() + ") does not match a known graph config",
function(){
// if there are no graph config, set active id to undefined
// otherwise, just set the active id to the id of the first graph config in the list
if (graph.getGraphConfigs().length === 0){
graph.setActiveGraphConfig(undefined);
graph.setActiveGraphConfig(null);
} else {
graph.setActiveGraphConfig(graph.getGraphConfigs()[0].getId());
}
Expand Down
3 changes: 1 addition & 2 deletions src/Modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,7 @@ export class Modals {

const isValid = (fileType === Eagle.FileType.Unknown) ||
(fileType === Eagle.FileType.Graph && inputElement.val().toString().endsWith(".graph")) ||
(fileType === Eagle.FileType.Palette && inputElement.val().toString().endsWith(".palette")) ||
(fileType === Eagle.FileType.Daliuge && inputElement.val().toString().endsWith(".dlg"));
(fileType === Eagle.FileType.Palette && inputElement.val().toString().endsWith(".palette"));

Modals._setValidClasses(inputElement, isValid);
}
Expand Down
5 changes: 1 addition & 4 deletions src/Repositories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Repositories {
static selectFile(file : RepositoryFile) : void {
const eagle: Eagle = Eagle.getInstance();

if(file.type === Eagle.FileType.Graph || file.type === Eagle.FileType.JSON || file.type === Eagle.FileType.Daliuge){
if(file.type === Eagle.FileType.Graph || file.type === Eagle.FileType.JSON){
eagle.showEagleIsLoading()
}

Expand All @@ -50,9 +50,6 @@ export class Repositories {
case Eagle.FileType.JSON:
isModified = eagle.logicalGraph().fileInfo().modified;
break;
case Eagle.FileType.Daliuge:
isModified = eagle.logicalGraph().fileInfo().modified;
break;
}

// if the file is modified, get the user to confirm they want to overwrite changes
Expand Down
2 changes: 0 additions & 2 deletions src/RepositoryFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export class RepositoryFile {
return "palette";
case Eagle.FileType.JSON:
return "language";
case Eagle.FileType.Daliuge:
return "construction"; // TODO: better icon
default:
return this.type;
}
Expand Down
26 changes: 7 additions & 19 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,16 @@ export class Utils {
// NOTE: used for sorting files by filetype
static getFileTypeNum(fileType: Eagle.FileType) : number {
switch (fileType){
case Eagle.FileType.Daliuge:
return 0;
case Eagle.FileType.Palette:
return 1;
return 0;
case Eagle.FileType.Graph:
return 2;
return 1;
case Eagle.FileType.JSON:
return 3;
return 2;
case Eagle.FileType.Markdown:
return 4;
return 3;
case Eagle.FileType.Unknown:
return 5;
return 4;
}
}

Expand Down Expand Up @@ -240,8 +238,6 @@ export class Utils {
return "graph";
} else if (fileType == Eagle.FileType.Palette) {
return "palette";
} else if (fileType === Eagle.FileType.Daliuge) {
return "dlg";
} else {
console.error("Utils.getDiagramExtension() : Unknown file type! (" + fileType + ")");
return "";
Expand All @@ -264,9 +260,6 @@ export class Utils {
if (fileType.toLowerCase() === "json"){
return Eagle.FileType.JSON;
}
if (fileType.toLowerCase() === "daliuge" || fileType.toLowerCase() === "dlg"){
return Eagle.FileType.Daliuge;
}

return Eagle.FileType.Unknown;
}
Expand Down Expand Up @@ -1544,10 +1537,6 @@ export class Utils {
case Eagle.FileType.Palette:
valid = ajv.validate(Utils.ojsPaletteSchema, json) as boolean;
break;
case Eagle.FileType.Daliuge:
// TODO: more here for the other parts of the Daliuge file, or a new schema for the whole thing
valid = ajv.validate(Utils.ojsGraphSchema, json.graph) as boolean;
break;
default:
console.warn("Unknown fileType:", fileType, "version:", version, "Unable to validate JSON");
valid = true;
Expand Down Expand Up @@ -1658,7 +1647,6 @@ export class Utils {
return distance;
}


static async userChoosePalette(paletteNames : string[]) : Promise<string> {
return new Promise<string>((resolve, reject) => {

Expand Down Expand Up @@ -1906,7 +1894,7 @@ export class Utils {
}

// fix for redundant 'Complex' type
if (field.getType() === 'Complex'){
if (field.getType().toString() === 'Complex'){
field.setType(Daliuge.DataType.Object);
return;
}
Expand All @@ -1916,7 +1904,7 @@ export class Utils {
return;
}

field.setType(Daliuge.DataType.Object + "." + field.getType());
field.setType((Daliuge.DataType.Object + "." + field.getType()) as Daliuge.DataType);
}

static fixFieldNodeId(eagle: Eagle, node: Node, field: Field){
Expand Down
2 changes: 1 addition & 1 deletion templates/quickAction.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- ko if: $root.quickActionOpen() -->
<div id="quickActionContainer" style="display: none;">
<div id="quickActionInput">
<input type="text" id="quickActionSearchbar" placeholder="Search..." data-bind="event:{keyup: QuickActions.updateQuickActionSearchTerm}">
<input type="text" id="quickActionSearchbar" placeholder="Command Search... (e.g. 'save', or 'edge')" data-bind="event:{keyup: QuickActions.updateQuickActionSearchTerm}">
</div>
<div id="quickActionResults">
<div data-bind="foreach: QuickActions.findQuickActionResults()">
Expand Down

0 comments on commit 7fb3e9d

Please sign in to comment.