diff --git a/ArduinoFrontend/src/app/Libs/Workspace.ts b/ArduinoFrontend/src/app/Libs/Workspace.ts index f60ffadc6..4e2516606 100644 --- a/ArduinoFrontend/src/app/Libs/Workspace.ts +++ b/ArduinoFrontend/src/app/Libs/Workspace.ts @@ -8,7 +8,7 @@ import { SaveOffline } from './SaveOffiline'; import { Point } from './Point'; import { UndoUtils } from './UndoUtils'; import { EventEmitter } from '@angular/core'; -import { stopdrag } from '../simulator/simulator.component'; +import { SimulatorComponent, stopdrag } from '../simulator/simulator.component'; /** * Declare window so that custom created function don't throw error @@ -577,6 +577,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() }); + SimulatorComponent.tempversion = 'NEWADD'; } /** Function updates the position of wires */ static updateWires() { @@ -794,7 +795,7 @@ export class Workspace { Workspace.circuitLoadStatus.emit(true); } - /** Function to delete component fro Workspace */ + /** Function to delete component from Workspace */ static DeleteComponent(undoReset = true) { // Save Dump of current Workspace // Check if component is selected @@ -807,6 +808,7 @@ export class Workspace { } } + SimulatorComponent.tempversion = 'NEWDEL'; // get the component id const uid = window.Selected.id; const key = window.Selected.keyName; @@ -921,6 +923,7 @@ export class Workspace { window['scope'][key].push(obj); // obj.copy(Workspace.copiedItem) } + SimulatorComponent.tempversion = 'NEWPASTE'; } /** Function called to clear output in console */ diff --git a/ArduinoFrontend/src/app/simulator/save-project-dialog/save-project-dialog.component.html b/ArduinoFrontend/src/app/simulator/save-project-dialog/save-project-dialog.component.html index 809d85604..4e1799093 100644 --- a/ArduinoFrontend/src/app/simulator/save-project-dialog/save-project-dialog.component.html +++ b/ArduinoFrontend/src/app/simulator/save-project-dialog/save-project-dialog.component.html @@ -7,6 +7,6 @@
diff --git a/ArduinoFrontend/src/app/simulator/simulator.component.ts b/ArduinoFrontend/src/app/simulator/simulator.component.ts index 04c556c3b..b78ebdc07 100644 --- a/ArduinoFrontend/src/app/simulator/simulator.component.ts +++ b/ArduinoFrontend/src/app/simulator/simulator.component.ts @@ -42,6 +42,10 @@ export let stopdrag = { value: false }; encapsulation: ViewEncapsulation.None }) export class SimulatorComponent implements OnInit, OnDestroy { + /** + * Currently loaded circuits temp version + */ + static tempversion: string; /** * Raphael Paper */ @@ -237,6 +241,8 @@ export class SimulatorComponent implements OnInit, OnDestroy { , 100); return; } + this.version = this.getRandomString(20); + SimulatorComponent.tempversion = this.version; // if gallery query parameter is present if (v.gallery) { this.OpenGallery(v.gallery, v.proId); @@ -430,6 +436,7 @@ export class SimulatorComponent implements OnInit, OnDestroy { * @param elem Code Editor Parent Div */ toggleCodeEditor(elem: HTMLElement) { + SimulatorComponent.tempversion = 'NEWCODE'; elem.classList.toggle('show-code-editor'); this.toggle = !this.toggle; this.openCodeEditor = !this.openCodeEditor; @@ -495,6 +502,7 @@ export class SimulatorComponent implements OnInit, OnDestroy { // check if textbox is empty if it is change title back to Untitled const el = evt.target; if (el.value === '') { + SimulatorComponent.tempversion = 'NEWTITLE'; el.value = 'Untitled'; } this.projectTitle = el.value; @@ -519,6 +527,7 @@ export class SimulatorComponent implements OnInit, OnDestroy { if (!this.isAddComponentEnabled) { event.preventDefault(); } else { + SimulatorComponent.tempversion = 'NEWDRAG'; event.dataTransfer.dropEffect = 'copyMove'; event.dataTransfer.setData('text', key); } @@ -537,6 +546,7 @@ export class SimulatorComponent implements OnInit, OnDestroy { autoLayout() { // this.isAutoLayoutInProgress = true; + SimulatorComponent.tempversion = 'NEWAUTO'; LayoutUtils.solveAutoLayout(); // this.isAutoLayoutInProgress = false; } @@ -603,6 +613,7 @@ export class SimulatorComponent implements OnInit, OnDestroy { const branch = params.branch; const versionId = params.version; const newVersionId = this.getRandomString(20); + SimulatorComponent.tempversion = newVersionId; // Update Project to DB SaveOnline.Save(this.projectTitle, this.description, this.api, branch, newVersionId, (out) => { AlertService.showAlert('Updated'); @@ -678,6 +689,7 @@ export class SimulatorComponent implements OnInit, OnDestroy { } /** Function saves or updates the project offline */ SaveProjectOff(callback = null) { + SimulatorComponent.tempversion = this.version; // if Project is UUID if (SaveOnline.isUUID(this.projectId)) { AlertService.showAlert('Project is already Online!'); @@ -720,6 +732,7 @@ export class SimulatorComponent implements OnInit, OnDestroy { /** Function clear variables in the Workspace */ ClearProject() { Workspace.ClearWorkspace(); + SimulatorComponent.tempversion = 'NEWCLEAR'; this.closeProject(); } /** @@ -816,6 +829,38 @@ export class SimulatorComponent implements OnInit, OnDestroy { * Handles routeLinks */ HandleRouter(callback) { + if (SimulatorComponent.tempversion.length === 20) { + callback(); + } else if (Login.getToken()) { + AlertService.showOptions( + 'Save changes to the untitled circuit on cloud? 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, + }, + (value) => { + if (value) { + this.SaveProject(); + callback(); + } + } + ); + }, + () => { + callback(); + }, + () => { }, + 'Save', + 'Don\'t save', + 'Cancel' + ); + } else { AlertService.showOptions( 'Save changes to the untitled circuit? Your changes will be lost if you do not save it.', () => { @@ -846,6 +891,7 @@ export class SimulatorComponent implements OnInit, OnDestroy { 'Cancel' ); } +} /** * Open Gallery Project * @param index Gallery item index