Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save circuit alert - bug fix #536

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
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
7 changes: 5 additions & 2 deletions ArduinoFrontend/src/app/Libs/Workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -807,6 +808,7 @@ export class Workspace {
}
}

SimulatorComponent.tempversion = 'NEWDEL';
// get the component id
const uid = window.Selected.id;
const key = window.Selected.keyName;
Expand Down Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
</form>
</div>
<div class="confirm-buttons" mat-dialog-actions>
<button class="response-button" color="success" mat-button (click)="onSave()">Save temporary</button>
<button class="response-button" color="success" mat-button (click)="onSave()">Save</button>
<button class="response-button" color="primary" mat-button (click)="onCancel()">Cancel</button>
</div>
46 changes: 46 additions & 0 deletions ArduinoFrontend/src/app/simulator/simulator.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -537,6 +546,7 @@ export class SimulatorComponent implements OnInit, OnDestroy {

autoLayout() {
// this.isAutoLayoutInProgress = true;
SimulatorComponent.tempversion = 'NEWAUTO';
LayoutUtils.solveAutoLayout();
// this.isAutoLayoutInProgress = false;
}
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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!');
Expand Down Expand Up @@ -720,6 +732,7 @@ export class SimulatorComponent implements OnInit, OnDestroy {
/** Function clear variables in the Workspace */
ClearProject() {
Workspace.ClearWorkspace();
SimulatorComponent.tempversion = 'NEWCLEAR';
this.closeProject();
}
/**
Expand Down Expand Up @@ -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.',
() => {
Expand Down Expand Up @@ -846,6 +891,7 @@ export class SimulatorComponent implements OnInit, OnDestroy {
'Cancel'
);
}
}
/**
* Open Gallery Project
* @param index Gallery item index
Expand Down
Loading