Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions ArduinoFrontend/src/app/Libs/Workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class Workspace {
* If simulation is on progress or not
*/
static simulating = false;
static hasUnsavedChanges = true;
/**
* If circuit is loaded or not
*/
Expand Down Expand Up @@ -167,6 +168,7 @@ export class Workspace {
for (const fn of window.DragListeners) {
fn.fn(element);
}
Workspace.hasUnsavedChanges = true;
}

/**
Expand Down Expand Up @@ -266,8 +268,8 @@ export class Workspace {
* @param event Before Unload Event
*/
static BeforeUnload(event) {
event.preventDefault();
event.returnValue = 'did you save the stuff?';
event.preventDefault();
event.returnValue = 'did you save the stuff?';
}
/**
* Event Listener for mousemove on html body
Expand Down Expand Up @@ -577,6 +579,7 @@ export class Workspace {
window['scope'][classString].push(obj);
// Push dump to Undo stack & Reset
UndoUtils.pushChangeToUndoAndReset({ keyName: obj.keyName, event: 'add', element: obj.save() });
Workspace.hasUnsavedChanges = true;
}
/** Function updates the position of wires */
static updateWires() {
Expand Down Expand Up @@ -662,7 +665,6 @@ export class Workspace {
SaveOffline.Save(saveObj, callback);
}
});

}

/**
Expand All @@ -678,7 +680,6 @@ export class Workspace {
Workspace.translateX = data.canvas.x;
Workspace.translateY = data.canvas.y;
Workspace.scale = data.canvas.scale;

// Update the translation and scaling
window.queue = 0;
const ele = (window['canvas'].canvas as HTMLElement);
Expand Down Expand Up @@ -731,6 +732,7 @@ export class Workspace {
window.hideLoading();
}
}, 100);
Workspace.hasUnsavedChanges = false;
UndoUtils.resetStacks();
}
/** This function recreates the wire object */
Expand Down Expand Up @@ -884,6 +886,7 @@ export class Workspace {
} else {
window['showToast']('No Element Selected');
}
Workspace.hasUnsavedChanges = true;
}

/** Function to copy component fro Workspace */
Expand Down Expand Up @@ -919,6 +922,7 @@ export class Workspace {
const obj = new myClass(window['canvas'], pt.x, pt.y);
window['scope'][key].push(obj);
// obj.copy(Workspace.copiedItem)
Workspace.hasUnsavedChanges = true;
}
}

Expand Down
60 changes: 34 additions & 26 deletions ArduinoFrontend/src/app/simulator/simulator.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ export class SimulatorComponent implements OnInit, OnDestroy {
// Update Project to DB
SaveOnline.Save(this.projectTitle, this.description, this.api, branch, newVersionId, (out) => {
AlertService.showAlert('Updated');
Workspace.hasUnsavedChanges = false; // Set flag to false once saved
if (out['duplicate']) {
// TODO: if duplicate, refresh the route with same versionId and same branch
this.router.navigateByUrl('/', { skipLocationChange: true }).then(() => {
Expand Down Expand Up @@ -674,6 +675,7 @@ export class SimulatorComponent implements OnInit, OnDestroy {
}
);
});
Workspace.hasUnsavedChanges = false;
}
}
/** Function saves or updates the project offline */
Expand All @@ -686,6 +688,7 @@ export class SimulatorComponent implements OnInit, OnDestroy {
// Save circuit if id is not presenr
if (this.projectId) {
Workspace.SaveCircuit(this.projectTitle, this.description, callback, this.projectId);
Workspace.hasUnsavedChanges = false;
} else {
// save circuit and add query parameters
Workspace.SaveCircuit(this.projectTitle, this.description, (v) => {
Expand All @@ -706,6 +709,7 @@ export class SimulatorComponent implements OnInit, OnDestroy {
}
});
}
Workspace.hasUnsavedChanges = false; // Set flag to false once saved
}

/**
Expand Down Expand Up @@ -816,35 +820,39 @@ export class SimulatorComponent implements OnInit, OnDestroy {
* Handles routeLinks
*/
HandleRouter(callback) {
AlertService.showOptions(
'Save changes to the untitled circuit? Your changes will be lost if you do not save it.',
() => {
AlertService.showCustom(
SaveProjectDialogComponent,
{
onChangeProjectTitle: (e) => {
this.projectTitle = e.target.value || '';
return this.projectTitle;
if (!Workspace.hasUnsavedChanges || Workspace.checkIfWorkspaceEmpty()) {
callback();
} else {
AlertService.showOptions(
'Save changes to the untitled circuit? Your changes will be lost if you do not save it.',
() => {
AlertService.showCustom(
SaveProjectDialogComponent,
{
onChangeProjectTitle: (e) => {
this.projectTitle = e.target.value || '';
return this.projectTitle;
},
projectTitle: this.projectTitle,
},
projectTitle: this.projectTitle,
},
(value) => {
if (value) {
this.SaveProjectOff(() => {
callback();
});
(value) => {
if (value) {
this.SaveProjectOff(() => {
callback();
});
}
}
}
);
},
() => {
callback();
},
() => { },
'Save',
'Don\'t save',
'Cancel'
);
},
() => {
callback();
},
() => { },
'Save',
'Don\'t save',
'Cancel'
);
}
}
/**
* Open Gallery Project
Expand Down