This commit is contained in:
Mo Bitar
2016-12-26 01:11:40 -06:00
parent 3c2e6b37c3
commit e3ea390abd
15 changed files with 82 additions and 74 deletions

View File

@@ -39,5 +39,5 @@ angular.module('app.frontend', [
});
})
.config(['$qProvider', function ($qProvider) {
$qProvider.errorOnUnhandledRejections(false);
// $qProvider.errorOnUnhandledRejections(false);
}]);

View File

@@ -8,14 +8,6 @@ class BaseCtrl {
// $auth.updatePassword(data);
// apiController.setMk(new_keys.mk);
// }
// var note = new Note();
// note.content = {title: "hello", text: "world"};
// console.log("note content", note.content);
// console.log("note title", note.title);
// console.log("note json", JSON.stringify(note));
//
// console.log("Copy", _.cloneDeep(note));
}
}

View File

@@ -67,7 +67,7 @@ angular.module('app.frontend')
this.setNote = function(note, oldNote) {
this.editorMode = 'edit';
if(note.content.text.length == 0) {
if(note.content.text.length == 0 && note.dummy) {
this.focusTitle(100);
}
@@ -133,7 +133,10 @@ angular.module('app.frontend')
this.changesMade = function() {
this.note.hasChanges = true;
this.note.dummy = false;
apiController.saveDraftToDisk(this.note);
if(this.user.uuid) {
// signed out users have local autosave, dont need draft saving
apiController.saveDraftToDisk(this.note);
}
if(saveTimeout) $timeout.cancel(saveTimeout);
if(statusTimeout) $timeout.cancel(statusTimeout);

View File

@@ -74,6 +74,7 @@ angular.module('app.frontend')
$timeout(function(){
apiController.login(this.loginData.email, this.loginData.user_password, function(response){
if(response.errors) {
console.log("login error", response.errors);
this.loginData.status = response.errors[0];
} else {
this.onAuthSuccess(response.user);

View File

@@ -122,7 +122,7 @@ angular.module('app.frontend')
if(this.noteFilter.text.length == 0) {
note.visible = true;
} else {
note.visible = note.title.toLowerCase().includes(this.noteFilter.text) || note.text.toLowerCase().includes(this.noteFilter.text);
note.visible = note.content.title.toLowerCase().includes(this.noteFilter.text) || note.content.text.toLowerCase().includes(this.noteFilter.text);
}
return note.visible;
}.bind(this)

View File

@@ -13,7 +13,7 @@ angular.module('app.frontend')
if(!url) {
url = localStorage.getItem("server");
if(!url) {
url = location.protocol + "//" + domainName() + (location.port ? ':' + location.port: '');
url = "https://n3.standardnotes.org";
}
}
return url;
@@ -38,7 +38,7 @@ angular.module('app.frontend')
if(!url) {
url = localStorage.getItem("server");
if(!url) {
url = location.protocol + "//" + domainName() + (location.port ? ':' + location.port: '');
url = "https://n3.standardnotes.org";
this.setServer(url);
}
}
@@ -72,7 +72,6 @@ angular.module('app.frontend')
Restangular.one("users/current").get().then(function(response){
var plain = response.plain();
var items = plain.items;
console.log("Current user items", items);
this.decryptItemsWithLocalKey(items);
items = this.mapResponseItemsToLocalModels(items);
var user = _.omit(plain, ["items"]);
@@ -88,7 +87,6 @@ angular.module('app.frontend')
this.getAuthParamsForEmail(email, function(authParams){
Neeto.crypto.computeEncryptionKeysForUser(_.merge({email: email, password: password}, authParams), function(keys){
this.setMk(keys.mk);
console.log("Signing in with", authParams, "pw", keys);
var request = Restangular.one("auth/sign_in");
request.user = {password: keys.pw, email: email};
request.post().then(function(response){
@@ -215,6 +213,11 @@ angular.module('app.frontend')
}
this.saveItems = function(items, callback) {
if(!this.user.uuid) {
this.writeItemsToLocalStorage();
callback();
return;
}
var request = Restangular.one("users", this.user.uuid).one("items");
request.items = _.map(items, function(item){
return this.createRequestParamsForItem(item);
@@ -281,7 +284,7 @@ angular.module('app.frontend')
this.deleteItem = function(item, callback) {
if(!this.user.uuid) {
this.writeUserToLocalStorage(this.user);
this.writeItemsToLocalStorage();
callback(true);
} else {
Restangular.one("users", this.user.uuid).one("items", item.uuid).remove()
@@ -403,13 +406,11 @@ angular.module('app.frontend')
return JSON.parse(JSON.stringify(object));
}
this.writeUserToLocalStorage = function(user) {
var saveUser = _.cloneDeep(user);
saveUser.items = Item.filterDummyItems(saveUser.items);
saveUser.tags.forEach(function(tag){
tag.items = null;
}.bind(this))
this.writeToLocalStorage('user', saveUser);
this.writeItemsToLocalStorage = function() {
var items = _.map(modelManager.items, function(item){
return this.paramsForItem(item, false, ["created_at", "updated_at"], true)
}.bind(this));
this.writeToLocalStorage('items', items);
}
this.writeToLocalStorage = function(key, value) {
@@ -417,10 +418,11 @@ angular.module('app.frontend')
}
this.localUser = function() {
var user = JSON.parse(localStorage.getItem('user'));
if(!user) {
user = {items: [], tags: []};
}
var user = {};
var items = JSON.parse(localStorage.getItem('items'));
items = this.mapResponseItemsToLocalModels(items);
modelManager.items = items;
user.items = items;
user.shouldMerge = true;
return user;
}
@@ -430,7 +432,7 @@ angular.module('app.frontend')
*/
this.saveDraftToDisk = function(draft) {
// localStorage.setItem("draft", JSON.stringify(draft));
localStorage.setItem("draft", JSON.stringify(draft));
}
this.clearDraft = function() {

View File

@@ -32,6 +32,10 @@ class ItemManager {
});
}
addItem(item) {
this.items.push(item);
}
// returns dirty item references that need saving
deleteItem(item) {
var dirty = [];

View File

@@ -44,11 +44,13 @@ class ModelManager extends ItemManager {
addNote(note) {
if(!_.find(this.notes, {uuid: note.uuid})) {
this.notes.unshift(note);
this.addItem(note);
}
}
addTag(tag) {
this.tags.unshift(tag);
this.addItem(tag);
}
addTagToNote(tag, note) {