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) { .config(['$qProvider', function ($qProvider) {
$qProvider.errorOnUnhandledRejections(false); // $qProvider.errorOnUnhandledRejections(false);
}]); }]);

View File

@@ -8,14 +8,6 @@ class BaseCtrl {
// $auth.updatePassword(data); // $auth.updatePassword(data);
// apiController.setMk(new_keys.mk); // 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.setNote = function(note, oldNote) {
this.editorMode = 'edit'; this.editorMode = 'edit';
if(note.content.text.length == 0) { if(note.content.text.length == 0 && note.dummy) {
this.focusTitle(100); this.focusTitle(100);
} }
@@ -133,7 +133,10 @@ angular.module('app.frontend')
this.changesMade = function() { this.changesMade = function() {
this.note.hasChanges = true; this.note.hasChanges = true;
this.note.dummy = false; 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(saveTimeout) $timeout.cancel(saveTimeout);
if(statusTimeout) $timeout.cancel(statusTimeout); if(statusTimeout) $timeout.cancel(statusTimeout);

View File

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

View File

@@ -122,7 +122,7 @@ angular.module('app.frontend')
if(this.noteFilter.text.length == 0) { if(this.noteFilter.text.length == 0) {
note.visible = true; note.visible = true;
} else { } 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; return note.visible;
}.bind(this) }.bind(this)

View File

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

View File

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

View File

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

View File

@@ -84,8 +84,7 @@
display: inline-block; display: inline-block;
a { a {
color: white; color: black;
// font-size: 12px;
} }
.public-link { .public-link {

View File

@@ -60,6 +60,7 @@
.panel { .panel {
position: absolute; position: absolute;
right: 0px; right: 0px;
bottom: 20px;
min-width: 300px; min-width: 300px;
z-index: 1000; z-index: 1000;
margin-top: 15px; margin-top: 15px;

View File

@@ -179,7 +179,9 @@ $section-header-height: 70px;
border-radius: 4px; border-radius: 4px;
font-weight: normal; font-weight: normal;
text-align: center; text-align: center;
position: absolute;
right: 12px;
&:hover { &:hover {
background-color: rgba(#e9e9e9, 0.8); background-color: rgba(#e9e9e9, 0.8);
} }

View File

@@ -19,8 +19,6 @@
margin-top: -6px; margin-top: -6px;
background-color: #d7d7d7 !important; background-color: #d7d7d7 !important;
float: right; float: right;
position: absolute;
right: 12px;
&:hover { &:hover {
background-color: rgba(#d7d7d7, 0.8) !important; background-color: rgba(#d7d7d7, 0.8) !important;

View File

@@ -10,6 +10,16 @@
.panel-body .panel-body
.account-items .account-items
.account-item.registration-login{"ng-if" => "!ctrl.user.email"} .account-item.registration-login{"ng-if" => "!ctrl.user.email"}
.account-item
.meta-container
.title Server
.desc Enter your <a href="http://standardfile.github.io" target="_blank">Standard File</a> server address, or use the default.
.action-container
%form.account-form{'ng-submit' => 'ctrl.changeServer()', 'name' => "serverChangeForm"}
.form-tag.has-feedback
%input.form-control{:name => 'server', :placeholder => 'Server URL', :required => true, :type => 'text', 'ng-model' => 'ctrl.serverData.url'}
%button.btn.dark-button.btn-block{:type => 'submit', "data-style" => "expand-right", "data-size" => "s", "state" => "buttonState"}
%span.ladda-label Set Server
.meta-container .meta-container
.title Sign in or Register .title Sign in or Register
.desc .desc
@@ -57,17 +67,6 @@
%span %span
Import Data from Archive Import Data from Archive
.account-item
.meta-container
.title Server
.desc Use a custom Standard Notes server to store and retrieve your account data.
.action-container
%form.account-form{'ng-submit' => 'ctrl.changeServer()', 'name' => "serverChangeForm"}
.form-tag.has-feedback
%input.form-control{:name => 'server', :placeholder => 'Server URL', :required => true, :type => 'text', 'ng-model' => 'ctrl.serverData.url'}
%button.btn.dark-button.btn-block{:type => 'submit', "data-style" => "expand-right", "data-size" => "s", "state" => "buttonState"}
%span.ladda-label Change Server
.links{"ng-if" => "ctrl.user.email"} .links{"ng-if" => "ctrl.user.email"}
.link-item .link-item
%a{"ng-click" => "ctrl.changePasswordPressed()"} Change Password %a{"ng-click" => "ctrl.changePasswordPressed()"} Change Password

View File

@@ -389,7 +389,7 @@ angular.module('app.frontend', ['ui.router', 'restangular', 'oc.lazyLoad', 'angu
}; };
}); });
}).config(['$qProvider', function ($qProvider) { }).config(['$qProvider', function ($qProvider) {
$qProvider.errorOnUnhandledRejections(false); // $qProvider.errorOnUnhandledRejections(false);
}]); }]);
;angular.module('app.frontend').config(function ($stateProvider, $urlRouterProvider, $locationProvider) { ;angular.module('app.frontend').config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
@@ -437,14 +437,6 @@ var BaseCtrl = function BaseCtrl($rootScope, modelManager) {
// apiController.setMk(new_keys.mk); // 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));
_classCallCheck(this, BaseCtrl); _classCallCheck(this, BaseCtrl);
}; };
@@ -516,7 +508,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
this.setNote = function (note, oldNote) { this.setNote = function (note, oldNote) {
this.editorMode = 'edit'; this.editorMode = 'edit';
if (note.content.text.length == 0) { if (note.content.text.length == 0 && note.dummy) {
this.focusTitle(100); this.focusTitle(100);
} }
@@ -582,7 +574,10 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
this.changesMade = function () { this.changesMade = function () {
this.note.hasChanges = true; this.note.hasChanges = true;
this.note.dummy = false; 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 (saveTimeout) $timeout.cancel(saveTimeout);
if (statusTimeout) $timeout.cancel(statusTimeout); if (statusTimeout) $timeout.cancel(statusTimeout);
@@ -773,6 +768,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
$timeout(function () { $timeout(function () {
apiController.login(this.loginData.email, this.loginData.user_password, function (response) { apiController.login(this.loginData.email, this.loginData.user_password, function (response) {
if (response.errors) { if (response.errors) {
console.log("login error", response.errors);
this.loginData.status = response.errors[0]; this.loginData.status = response.errors[0];
} else { } else {
this.onAuthSuccess(response.user); this.onAuthSuccess(response.user);
@@ -1123,7 +1119,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
if (this.noteFilter.text.length == 0) { if (this.noteFilter.text.length == 0) {
note.visible = true; note.visible = true;
} else { } 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; return note.visible;
}.bind(this); }.bind(this);
@@ -1495,7 +1491,7 @@ var User = function User(json_obj) {
if (!url) { if (!url) {
url = localStorage.getItem("server"); url = localStorage.getItem("server");
if (!url) { if (!url) {
url = location.protocol + "//" + domainName() + (location.port ? ':' + location.port : ''); url = "https://n3.standardnotes.org";
} }
} }
return url; return url;
@@ -1519,7 +1515,7 @@ var User = function User(json_obj) {
if (!url) { if (!url) {
url = localStorage.getItem("server"); url = localStorage.getItem("server");
if (!url) { if (!url) {
url = location.protocol + "//" + domainName() + (location.port ? ':' + location.port : ''); url = "https://n3.standardnotes.org";
this.setServer(url); this.setServer(url);
} }
} }
@@ -1552,7 +1548,6 @@ var User = function User(json_obj) {
Restangular.one("users/current").get().then(function (response) { Restangular.one("users/current").get().then(function (response) {
var plain = response.plain(); var plain = response.plain();
var items = plain.items; var items = plain.items;
console.log("Current user items", items);
this.decryptItemsWithLocalKey(items); this.decryptItemsWithLocalKey(items);
items = this.mapResponseItemsToLocalModels(items); items = this.mapResponseItemsToLocalModels(items);
var user = _.omit(plain, ["items"]); var user = _.omit(plain, ["items"]);
@@ -1567,7 +1562,6 @@ var User = function User(json_obj) {
this.getAuthParamsForEmail(email, function (authParams) { this.getAuthParamsForEmail(email, function (authParams) {
Neeto.crypto.computeEncryptionKeysForUser(_.merge({ email: email, password: password }, authParams), function (keys) { Neeto.crypto.computeEncryptionKeysForUser(_.merge({ email: email, password: password }, authParams), function (keys) {
this.setMk(keys.mk); this.setMk(keys.mk);
console.log("Signing in with", authParams, "pw", keys);
var request = Restangular.one("auth/sign_in"); var request = Restangular.one("auth/sign_in");
request.user = { password: keys.pw, email: email }; request.user = { password: keys.pw, email: email };
request.post().then(function (response) { request.post().then(function (response) {
@@ -1691,6 +1685,11 @@ var User = function User(json_obj) {
}; };
this.saveItems = function (items, callback) { this.saveItems = function (items, callback) {
if (!this.user.uuid) {
this.writeItemsToLocalStorage();
callback();
return;
}
var request = Restangular.one("users", this.user.uuid).one("items"); var request = Restangular.one("users", this.user.uuid).one("items");
request.items = _.map(items, function (item) { request.items = _.map(items, function (item) {
return this.createRequestParamsForItem(item); return this.createRequestParamsForItem(item);
@@ -1755,7 +1754,7 @@ var User = function User(json_obj) {
this.deleteItem = function (item, callback) { this.deleteItem = function (item, callback) {
if (!this.user.uuid) { if (!this.user.uuid) {
this.writeUserToLocalStorage(this.user); this.writeItemsToLocalStorage();
callback(true); callback(true);
} else { } else {
Restangular.one("users", this.user.uuid).one("items", item.uuid).remove().then(function (response) { Restangular.one("users", this.user.uuid).one("items", item.uuid).remove().then(function (response) {
@@ -1873,13 +1872,11 @@ var User = function User(json_obj) {
return JSON.parse(JSON.stringify(object)); return JSON.parse(JSON.stringify(object));
}; };
this.writeUserToLocalStorage = function (user) { this.writeItemsToLocalStorage = function () {
var saveUser = _.cloneDeep(user); var items = _.map(modelManager.items, function (item) {
saveUser.items = Item.filterDummyItems(saveUser.items); return this.paramsForItem(item, false, ["created_at", "updated_at"], true);
saveUser.tags.forEach(function (tag) {
tag.items = null;
}.bind(this)); }.bind(this));
this.writeToLocalStorage('user', saveUser); this.writeToLocalStorage('items', items);
}; };
this.writeToLocalStorage = function (key, value) { this.writeToLocalStorage = function (key, value) {
@@ -1887,10 +1884,11 @@ var User = function User(json_obj) {
}; };
this.localUser = function () { this.localUser = function () {
var user = JSON.parse(localStorage.getItem('user')); var user = {};
if (!user) { var items = JSON.parse(localStorage.getItem('items'));
user = { items: [], tags: [] }; items = this.mapResponseItemsToLocalModels(items);
} modelManager.items = items;
user.items = items;
user.shouldMerge = true; user.shouldMerge = true;
return user; return user;
}; };
@@ -1900,7 +1898,7 @@ var User = function User(json_obj) {
*/ */
this.saveDraftToDisk = function (draft) { this.saveDraftToDisk = function (draft) {
// localStorage.setItem("draft", JSON.stringify(draft)); localStorage.setItem("draft", JSON.stringify(draft));
}; };
this.clearDraft = function () { this.clearDraft = function () {
@@ -2034,6 +2032,11 @@ var ItemManager = function () {
return item.content_type == contentType; return item.content_type == contentType;
}); });
} }
}, {
key: 'addItem',
value: function addItem(item) {
this.items.push(item);
}
// returns dirty item references that need saving // returns dirty item references that need saving
@@ -2135,12 +2138,14 @@ var ModelManager = function (_ItemManager) {
value: function addNote(note) { value: function addNote(note) {
if (!_.find(this.notes, { uuid: note.uuid })) { if (!_.find(this.notes, { uuid: note.uuid })) {
this.notes.unshift(note); this.notes.unshift(note);
this.addItem(note);
} }
} }
}, { }, {
key: 'addTag', key: 'addTag',
value: function addTag(tag) { value: function addTag(tag) {
this.tags.unshift(tag); this.tags.unshift(tag);
this.addItem(tag);
} }
}, { }, {
key: 'addTagToNote', key: 'addTagToNote',

File diff suppressed because one or more lines are too long