From a9ec0253106983886b3e4f1c7fd6c555394472f2 Mon Sep 17 00:00:00 2001 From: Mishtee Gandhi Date: Wed, 21 Feb 2024 21:47:56 +0530 Subject: [PATCH 1/6] Save circuit alert - bug fix --- .../src/app/simulator/simulator.component.ts | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/ArduinoFrontend/src/app/simulator/simulator.component.ts b/ArduinoFrontend/src/app/simulator/simulator.component.ts index 04c556c3..e488803d 100644 --- a/ArduinoFrontend/src/app/simulator/simulator.component.ts +++ b/ArduinoFrontend/src/app/simulator/simulator.component.ts @@ -154,6 +154,10 @@ export class SimulatorComponent implements OnInit, OnDestroy { * Currently loaded circuit's version */ version: string; + /** + * Currently loaded circuits temp version + */ + static tempversion: string; /** * Currently loaded circuit's save time */ @@ -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 From c3fcfd6a111b60ccee90c743dd159af606a1d1b8 Mon Sep 17 00:00:00 2001 From: Mishtee Gandhi Date: Wed, 21 Feb 2024 21:48:50 +0530 Subject: [PATCH 2/6] Save circuit alert - bug fix --- ArduinoFrontend/src/app/Libs/Workspace.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ArduinoFrontend/src/app/Libs/Workspace.ts b/ArduinoFrontend/src/app/Libs/Workspace.ts index f60ffadc..a36d6f07 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() { @@ -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 */ From d74748e1984f0e3d75b39898eba136574e118ec7 Mon Sep 17 00:00:00 2001 From: Mishtee Gandhi Date: Wed, 21 Feb 2024 21:49:23 +0530 Subject: [PATCH 3/6] Save circuit alert - bug fix --- .../save-project-dialog/save-project-dialog.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 809d8560..4e179909 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 @@
- +
From 7f53bf75d570f0a66d40bcba8ad8db6f1428faf4 Mon Sep 17 00:00:00 2001 From: Mishtee Gandhi Date: Wed, 21 Feb 2024 22:25:59 +0530 Subject: [PATCH 4/6] Save circuit alert - bug fix --- ArduinoFrontend/src/app/Libs/Workspace.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/Workspace.ts b/ArduinoFrontend/src/app/Libs/Workspace.ts index a36d6f07..4e251660 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 { SimulatorComponent, stopdrag } from '../simulator/simulator.component';; +import { SimulatorComponent, stopdrag } from '../simulator/simulator.component'; /** * Declare window so that custom created function don't throw error @@ -795,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 From e1d9e24430cab130374bb97eac5e0fbaf233e62f Mon Sep 17 00:00:00 2001 From: Mishtee Gandhi Date: Wed, 21 Feb 2024 22:26:27 +0530 Subject: [PATCH 5/6] Save circuit alert - bug fix --- .../src/app/simulator/simulator.component.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ArduinoFrontend/src/app/simulator/simulator.component.ts b/ArduinoFrontend/src/app/simulator/simulator.component.ts index e488803d..75037c12 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 */ @@ -154,10 +158,6 @@ export class SimulatorComponent implements OnInit, OnDestroy { * Currently loaded circuit's version */ version: string; - /** - * Currently loaded circuits temp version - */ - static tempversion: string; /** * Currently loaded circuit's save time */ @@ -829,9 +829,9 @@ export class SimulatorComponent implements OnInit, OnDestroy { * Handles routeLinks */ HandleRouter(callback) { - if (SimulatorComponent.tempversion.length == 20){ + if (SimulatorComponent.tempversion.length === 20) { callback(); - }else if(Login.getToken()){ + } 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.', () => { @@ -846,7 +846,7 @@ export class SimulatorComponent implements OnInit, OnDestroy { }, (value) => { if (value) { - this.SaveProject() + this.SaveProject(); callback(); } } @@ -860,7 +860,7 @@ export class SimulatorComponent implements OnInit, OnDestroy { 'Don\'t save', 'Cancel' ); - }else{ + } else { AlertService.showOptions( 'Save changes to the untitled circuit? Your changes will be lost if you do not save it.', () => { From cba9b90e5220b44ecd9a367eb7acab81da1010d6 Mon Sep 17 00:00:00 2001 From: Mishtee Gandhi Date: Wed, 21 Feb 2024 22:30:49 +0530 Subject: [PATCH 6/6] Save circuit alert - bug fix --- ArduinoFrontend/src/app/simulator/simulator.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ArduinoFrontend/src/app/simulator/simulator.component.ts b/ArduinoFrontend/src/app/simulator/simulator.component.ts index 75037c12..b78ebdc0 100644 --- a/ArduinoFrontend/src/app/simulator/simulator.component.ts +++ b/ArduinoFrontend/src/app/simulator/simulator.component.ts @@ -42,7 +42,7 @@ export let stopdrag = { value: false }; encapsulation: ViewEncapsulation.None }) export class SimulatorComponent implements OnInit, OnDestroy { - /** + /** * Currently loaded circuits temp version */ static tempversion: string; @@ -831,7 +831,7 @@ export class SimulatorComponent implements OnInit, OnDestroy { HandleRouter(callback) { if (SimulatorComponent.tempversion.length === 20) { callback(); - } else if(Login.getToken()) { + } 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.', () => {