Skip to content

Commit

Permalink
Merge pull request #96 from frg-fossee/ArduinoFrontend
Browse files Browse the repository at this point in the history
Update NGINX Config
  • Loading branch information
NavonilDas authored Jun 4, 2020
2 parents a508d45 + 859c57f commit b742d42
Show file tree
Hide file tree
Showing 27 changed files with 830 additions and 221 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ EMAIL_HOST=smtp.gmail.com
EMAIL_HOST_USER=youremail@gmail.com
EMAIL_HOST_PASSWORD=yourpassword
EMAIL_PORT=587
EMAIL_USE_TLS=True
EMAIL_USE_TLS=True
2 changes: 1 addition & 1 deletion ArduinoFrontend/src/app/Libs/CircuitElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export abstract class CircuitElement {
this.elements = window['canvas'].set();

if (filename) {
fetch(`/assets/jsons/${filename}`)
fetch(`./assets/jsons/${filename}`)
.then(v => v.json())
.then(obj => {
this.title = obj.name;
Expand Down
186 changes: 186 additions & 0 deletions ArduinoFrontend/src/app/Libs/SaveOffiline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
declare var window;

export class SaveOffline {
static Check(callback: any = null) {
if (window.indexedDB) {
// return true;
} else {
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction;
window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange;
}

if (window.indexedDB) {
const request = window.indexedDB.open('projects', 1);
request.onerror = () => {
// console.log('error: ');
alert('Error Occurred');
};
request.onsuccess = () => {
if (callback) {
callback(request.result);
}
};
request.onupgradeneeded = (event) => {
const datab = event.target.result;
if (!datab.objectStoreNames.contains('projects')) {
datab.createObjectStore('project', { keyPath: 'id' });
}
};
return true;
}

// IndexedDB not found
alert('Save Offline Feature Will Not Work');
return false;
}
static Save(mydata, callback: any = null) {
if (!SaveOffline.Check(db => {
db.transaction(['project'], 'readwrite')
.objectStore('project')
.add(mydata);
if (callback) {
callback(mydata);
}
alert('Done Saved');
})) {
return;
}
// let db;
// const request = window.indexedDB.open('projects', 1);
// request.onerror = () => {
// // console.log('error: ');
// alert('Error Occurred');
// };

// request.onsuccess = () => {
// db = request.result;
// };

// request.onupgradeneeded = (event) => {
// const datab = event.target.result;
// if (!datab.objectStoreNames.contains('projects')) {
// datab.createObjectStore('project', { keyPath: 'id' });
// }
// };
}


static ReadALL(callback: any = null) {
if (!SaveOffline.Check(db => {
const objectStore = db.transaction('project').objectStore('project');
const data = [];
objectStore.openCursor().onsuccess = (event) => {
const cursor = event.target.result;
if (cursor) {
data.push(cursor.value);
cursor.continue();
} else {
if (callback) {
callback(data);
}
}
};
})) {
return;
}
// let db;
// const request = window.indexedDB.open('projects', 1);
// request.onerror = (event) => {
// // console.log('error: ');
// alert('Error Occurred');
// };

// request.onsuccess = () => {
// db = request.result;
// console.log('success: ' + db);
// };
}

static Delete(id, callback: any = null) {
if (!SaveOffline.Check(db => {
const ok = db.transaction(['project'], 'readwrite')
.objectStore('project')
.delete(id);

ok.onsuccess = (_) => {
alert('Done Deleting');
if (callback) {
callback();
}
};
})) {
return;
}
// let db;
// const request = window.indexedDB.open('projects', 1);
// request.onerror = (_) => {
// // console.log('error: ');
// alert('Error Occurred');
// };

// request.onsuccess = (__) => {
// db = request.result;

// };
}

static Update(mydata, callback: any = null) {
if (!SaveOffline.Check(db => {
const ok = db.transaction(['project'], 'readwrite')
.objectStore('project')
.put(mydata);

ok.onsuccess = (_) => {
alert('Done Updating');
if (callback) {
callback(mydata);
}
};
})) {
return;
}
// let db;
// const request = window.indexedDB.open('projects', 1);
// request.onerror = (_) => {
// alert('Error Occurred');
// // console.log('error: ');
// };

// request.onsuccess = (__) => {
// db = request.result;


// };
}

static Read(id, callback: any = null) {
if (!SaveOffline.Check(db => {
const transaction = db.transaction(['project']);
const objectStore = transaction.objectStore('project');
const ok = objectStore.get(parseInt(id, 10));

ok.onerror = () => {
alert('Unable to retrieve data from database!');
};

ok.onsuccess = () => {
callback(ok.result);
};
})) {
return;
}
// let db;
// const request = window.indexedDB.open('projects', 1);
// request.onerror = () => {
// alert('Error Occurred');
// // console.log('error: ');
// };

// request.onsuccess = () => {
// db = request.result;


// };
}
}
137 changes: 10 additions & 127 deletions ArduinoFrontend/src/app/Libs/Workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Injector } from '@angular/core';
import { ApiService } from '../api.service';
import { Download, ImageType } from './Download';
import { isNull, isUndefined } from 'util';
import { SaveOffline } from './SaveOffiline';

declare var window;
declare var $; // For Jquery
Expand Down Expand Up @@ -395,7 +396,7 @@ export class Workspace {
}
}

static SaveCircuit(name: string = '', description: string = '', id: number = null) {
static SaveCircuit(name: string = '', description: string = '', callback: any = null, id: number = null) {
let toUpdate = false;
if (isNull(id)) {
id = Date.now();
Expand Down Expand Up @@ -430,135 +431,13 @@ export class Workspace {
saveObj.project['image'] = v;
console.log(saveObj);
if (toUpdate) {
Workspace.UpdateIDB(saveObj);
SaveOffline.Update(saveObj);
} else {
Workspace.SaveIDB(saveObj);
SaveOffline.Save(saveObj, callback);
}
});
}

static SaveIDB(mydata, callback: any = null) {
// window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;

// window.IDBTransaction = window.IDBTransaction ||
// window.webkitIDBTransaction || window.msIDBTransaction;
// window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange;
let db;
const request = window.indexedDB.open('projects', 1);
request.onerror = () => {
console.log('error: ');
};

request.onsuccess = () => {
db = request.result;
db.transaction(['project'], 'readwrite')
.objectStore('project')
.add(mydata);
if (callback) {
callback(mydata);
}
alert('Done Saved');
};
}

static readAll(callback: any = null) {
let db;
const request = window.indexedDB.open('projects', 1);
request.onerror = () => {
console.log('error: ');
};

request.onsuccess = () => {
db = request.result;
console.log('success: ' + db);
const objectStore = db.transaction('project').objectStore('project');
const data = [];
objectStore.openCursor().onsuccess = (event) => {
const cursor = event.target.result;
if (cursor) {
data.push(cursor.value);
cursor.continue();
} else {
if (callback) {
callback(data);
}
}
};
};
}

static DeleteIDB(id, callback: any = null) {
let db;
const request = window.indexedDB.open('projects', 1);
request.onerror = (_) => {
console.log('error: ');
};

request.onsuccess = (__) => {
db = request.result;

const ok = db.transaction(['project'], 'readwrite')
.objectStore('project')
.delete(id);

ok.onsuccess = (_) => {
alert('Done Deleting');
if (callback) {
callback();
}
};

};
}
static UpdateIDB(mydata, callback: any = null) {
let db;
const request = window.indexedDB.open('projects', 1);
request.onerror = (_) => {
console.log('error: ');
};

request.onsuccess = (__) => {
db = request.result;

const ok = db.transaction(['project'], 'readwrite')
.objectStore('project')
.put(mydata);

ok.onsuccess = (_) => {
alert('Done Updating');
if (callback) {
callback();
}
};

};
}

static readIDB(id, callback: any = null) {
let db;
const request = window.indexedDB.open('projects', 1);
request.onerror = () => {
console.log('error: ');
};

request.onsuccess = () => {
db = request.result;

const transaction = db.transaction(['project']);
const objectStore = transaction.objectStore('project');
const ok = objectStore.get(parseInt(id, 10));

ok.onerror = () => {
alert('Unable to retrieve daa from database!');
};

ok.onsuccess = () => {
callback(ok.result);
};

};
}

static Load(data) {
Workspace.translateX = data.canvas.x;
Workspace.translateY = data.canvas.y;
Expand Down Expand Up @@ -765,8 +644,12 @@ export class Workspace {
// Assign id
let gid = 0;
for (const wire of window.scope.wires) {
wire.start.gid = gid++;
wire.end.gid = gid++;
if (wire.start) {
wire.start.gid = gid++;
}
if (wire.end) {
wire.end.gid = gid++;
}
}
// Call init simulation
for (const key in window.scope) {
Expand Down
Loading

0 comments on commit b742d42

Please sign in to comment.