Skip to content

Commit

Permalink
save CAM documents to indexedDB instead of firebase
Browse files Browse the repository at this point in the history
  • Loading branch information
nraynaud committed Jan 2, 2020
1 parent a8e2027 commit 7b9ef19
Show file tree
Hide file tree
Showing 27 changed files with 5,395 additions and 19,401 deletions.
35 changes: 35 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

498 changes: 490 additions & 8 deletions .idea/webgcode.iml

Large diffs are not rendered by default.

64 changes: 12 additions & 52 deletions webapp/cnc/app/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,6 @@
define(['Ember', 'cnc/cam/operations', 'cnc/util', 'cnc/cad/wabble', 'cnc/cam/text', 'cnc/app/job/jobController'],
function (Ember, Operations, util, Wabble, text, JobController) {
var wabble = new Wabble(13, 15, 1, 1, 5, 8, 3);
var LoginController = Ember.ObjectController.extend({
actions: {
loginWithToken: function (authData) {
var _this = this;
var service = this.get('model');
var payload;
if (service == 'twitter')
payload = {
user_id: authData.twitter.id,
oauth_token: authData.twitter.accessToken,
oauth_token_secret: authData.twitter.accessTokenSecret
};
else
payload = authData[service].accessToken;
this.get('firebase.firebase').authWithOAuthToken(service, payload, function () {
console.log(arguments);
_this.transitionToRoute('index').then(function () {
Visucam.reset();
});
});
}
}
});

var IndexController = Ember.ObjectController.extend({
needs: ['application'],
actions: {
Expand Down Expand Up @@ -74,28 +50,14 @@ define(['Ember', 'cnc/cam/operations', 'cnc/util', 'cnc/cad/wabble', 'cnc/cam/te
},
createJob: function () {
var job = this.store.createRecord('job');
job.saveAll();
this.transitionToRoute('job', job);
var _this = this;
return job.saveAll().then(function () {
_this.transitionToRoute('job', job);
});
}
}
});

var ApplicationController = Ember.ObjectController.extend({
authProviderIcon: function () {
var icons = {
facebook: 'fa fa-facebook',
twitter: 'fa fa-twitter',
github: 'fa fa-github',
google: 'fa fa-google-plus',
anonymous: 'fa fa-eye-slash'
};
return icons[this.get('firebase.auth.provider')];
}.property('firebase.auth.provider'),
authTitle: function () {
return 'Authenticated with ' + this.get('firebase.auth.provider');
}.property('firebase.auth.provider')
});

var ShapeController = Ember.ObjectController.extend({
init: function () {
var _this = this;
Expand All @@ -105,22 +67,22 @@ define(['Ember', 'cnc/cam/operations', 'cnc/util', 'cnc/cad/wabble', 'cnc/cam/te
},
shapeTypes: ['rectangle', 'circle', 'text', 'point', 'slice'],
isManual: function () {
return this.get('type') == 'manual';
return this.get('type') === 'manual';
}.property('type'),
isRectangle: function () {
return this.get('isManual') && this.get('manualDefinition.type') == 'rectangle';
return this.get('isManual') && this.get('manualDefinition.type') === 'rectangle';
}.property('isManual', 'manualDefinition.type'),
isCircle: function () {
return this.get('isManual') && this.get('manualDefinition.type') == 'circle';
return this.get('isManual') && this.get('manualDefinition.type') === 'circle';
}.property('isManual', 'manualDefinition.type'),
isText: function () {
return this.get('isManual') && this.get('manualDefinition.type') == 'text';
return this.get('isManual') && this.get('manualDefinition.type') === 'text';
}.property('isManual', 'manualDefinition.type'),
isPoint: function () {
return this.get('isManual') && this.get('manualDefinition.type') == 'point';
return this.get('isManual') && this.get('manualDefinition.type') === 'point';
}.property('isManual', 'manualDefinition.type'),
isSlice: function () {
return this.get('isManual') && this.get('manualDefinition.type') == 'slice';
return this.get('isManual') && this.get('manualDefinition.type') === 'slice';
}.property('isManual', 'manualDefinition.type'),
fonts: null,
fontChanged: function () {
Expand All @@ -144,7 +106,7 @@ define(['Ember', 'cnc/cam/operations', 'cnc/util', 'cnc/cad/wabble', 'cnc/cam/te
return shape.get('stlModel') == null;
}),
suitableShapes: function () {
if (this.get('type') == '3DlinearOperation')
if (this.get('type') === '3DlinearOperation')
return this.get('stlShapes');
return this.get('NonStlShapes');
}.property('stlShapes', 'NonStlShapes', 'type'),
Expand All @@ -154,7 +116,7 @@ define(['Ember', 'cnc/cam/operations', 'cnc/util', 'cnc/cad/wabble', 'cnc/cam/te
});
}.property(),
isVTool: function () {
return this.get('3d_toolType').indexOf('v') == 0;
return this.get('3d_toolType').indexOf('v') === 0;
}.property('3d_toolType'),
toolShapes: function () {
return [
Expand Down Expand Up @@ -240,9 +202,7 @@ define(['Ember', 'cnc/cam/operations', 'cnc/util', 'cnc/cad/wabble', 'cnc/cam/te
}.property('controllers.job.currentShape')
});
return {
LoginController: LoginController,
IndexController: IndexController,
ApplicationController: ApplicationController,
JobController: JobController,
ShapeController: ShapeController,
OperationController: OperationController,
Expand Down
115 changes: 115 additions & 0 deletions webapp/cnc/app/job/jobAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
"use strict";

define(['Ember', 'EmberData'], function (Ember, DS) {

// this adapter is also used for JobSummary.
// jobsummry is a model of job that just shows a few fields and doesn't trigger a full toolpath computation.
// it's used for the job list on the front page
// by using the same adapter, the same on disk data get either hydrated as a Job or a JobSummary
return DS.Adapter.extend({
init() {
return new Ember.RSVP.Promise(function (resolve, reject) {
var request = window.indexedDB.open("Jobs", 2);
request.onerror = function (event) {
reject(event.target.errorCode)
}
request.onupgradeneeded = function (event) {
var db = event.target.result;
db.createObjectStore("jobs", {autoIncrement: true});
}
request.onsuccess = function (event) {
resolve();
}
});
},
openDB() {
return new Ember.RSVP.Promise(function (resolve, reject) {
var request = window.indexedDB.open("Jobs", 2);
request.onerror = function (event) {
reject(event.target.errorCode)
}
request.onsuccess = function (event) {
event.target.result;
resolve(event.target.result);
}
});
},
makeQuery(idbQueryFunction) {
return this.openDB().then(function (db) {
let idbObjectStore = db.transaction(["jobs"], "readwrite").objectStore("jobs");
var request = idbQueryFunction(idbObjectStore);
return new Ember.RSVP.Promise(function (resolve, reject) {
request.onsuccess = function (event) {
resolve(event.target.result);
};
request.onerror = function (event) {
console.error('IndexedDB error: ' + event.target.errorCode);
reject(event);
};
});
});
},
find: function (store, type, id, opts) {
return this.makeQuery(function (objectStore) {
return objectStore.get(parseInt(id));
}).then(function (data) {
if (data)
data.id = id;
return data
});
},
findRecord: function (store, type, id, opts) {
console.log('JobAdapter.find()')
},
createRecord: function (store, type, snapshot) {
var data = this.serialize(snapshot);
return this.makeQuery(function (objectStore) {
return objectStore.add(data);
}).then(function (id) {
data.id = id;
return data
});
},
updateRecord: function (store, type, snapshot) {
var data = snapshot.serialize();
return this.makeQuery(function (objectStore) {
return objectStore.put(data, parseInt(snapshot.id));
}).then(function () {
data.id = snapshot.id;
return data;
});
},
deleteRecord: function (store, type, snapshot) {
return this.makeQuery(function (objectStore) {
return objectStore.delete(parseInt(snapshot.id));
}).then(function () {
return true;
});
},
findAll: function (store, type) {
var result = [];
return this.openDB().then(function (db) {
var request = db.transaction(["jobs"], "readonly").objectStore("jobs").openCursor();
return new Ember.RSVP.Promise(function (resolve, reject) {
request.onsuccess = function (event) {
let cursor = event.target.result;
if (cursor) {
result.push({...cursor.value, id: cursor.primaryKey + ''})
cursor.continue();
} else {
Ember.run(null, resolve, result);
}
};
request.onerror = function (event) {
console.log('IndexedDB error: ' + event.target.errorCode);
reject(event);
};
});
});
},
query: function (records, query) {
return []
}
});

});
21 changes: 11 additions & 10 deletions webapp/cnc/app/job/jobController.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ define(['Ember', 'jQuery', 'cnc/util', 'cnc/cam/cam'], function (Ember, $, util,
this._super();
var _this = this;
window.addEventListener("message", Ember.run.bind(this, function (event) {
if (event.data['type'] == 'gimme program') {
if (event.data['type'] === 'gimme program') {
_this.syncStartPoint();
var parameters = event.data.parameters;
var toolPath = _this.get('model').computeCompactToolPath();
Expand All @@ -24,15 +24,15 @@ define(['Ember', 'jQuery', 'cnc/util', 'cnc/cam/cam'], function (Ember, $, util,
});
console.timeEnd('postMessage');
}
if (event.data['type'] == 'toolPosition') {
if (event.data['type'] === 'toolPosition') {
var pos = event.data['position'];
var newPos = new util.Point(pos.x, pos.y, pos.z);
if (!_this.get('toolPosition') || _this.get('toolPosition').sqDistance(newPos)) {
_this.set('toolPosition', newPos);
Ember.run.debounce(_this, _this.syncStartPoint, 5000);
}
}
if (event.data['type'] == 'current operations') {
if (event.data['type'] === 'current operations') {
_this.set('runningOperations', event.data['operations']);
}
}), false);
Expand Down Expand Up @@ -76,11 +76,12 @@ define(['Ember', 'jQuery', 'cnc/util', 'cnc/cam/cam'], function (Ember, $, util,
},
'delete': function () {
var _this = this;
this.get('model.jobSummary').then(function (jobSummary) {
return Ember.RSVP.hash({
summary: jobSummary.destroyRecord(),
job: _this.get('model').destroyRecord()
});
var ops = this.get('operations').toArray();
return Ember.RSVP.all(ops.map(function (op) {
_this.get('operations').removeObject(op);
return op.destroyRecord();
})).finally(function () {
return _this.get('model').destroyRecord();
}).then(function () {
_this.transitionToRoute('index');
});
Expand All @@ -94,9 +95,9 @@ define(['Ember', 'jQuery', 'cnc/util', 'cnc/cam/cam'], function (Ember, $, util,
if (fragment.feedrate)
collector.changeWorkSpeed(fragment.feedrate);
var gotoFunc;
if (fragment.speedTag == 'normal')
if (fragment.speedTag === 'normal')
gotoFunc = collector.goToWorkSpeed.bind(collector);
if (fragment.speedTag == 'rapid')
if (fragment.speedTag === 'rapid')
gotoFunc = collector.goToTravelSpeed.bind(collector);
for (var j = 0; j < fragment.path.length; j++)
gotoFunc(fragment.path[j]);
Expand Down
Loading

0 comments on commit 7b9ef19

Please sign in to comment.