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

Offline #13

Merged
merged 5 commits into from
Jan 9, 2017
Merged
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
11 changes: 2 additions & 9 deletions app/assets/javascripts/app/frontend/controllers/_base.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
class BaseCtrl {
constructor($rootScope, modelManager) {
// $rootScope.resetPasswordSubmit = function() {
// var new_keys = Neeto.crypto.generateEncryptionKeysForUser($rootScope.resetData.password, $rootScope.resetData.email);
// var data = _.clone($rootScope.resetData);
// data.password = new_keys.pw;
// data.password_confirmation = new_keys.pw;
// $auth.updatePassword(data);
// apiController.setMk(new_keys.mk);
// }
constructor($rootScope, modelManager, apiController) {
apiController.getCurrentUser(function(){});
}
}

Expand Down
10 changes: 7 additions & 3 deletions app/assets/javascripts/app/frontend/controllers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ angular.module('app.frontend')
scope: {
save: "&",
remove: "&",
note: "=",
user: "="
note: "="
},
templateUrl: 'frontend/editor.html',
replace: true,
Expand Down Expand Up @@ -124,6 +123,11 @@ angular.module('app.frontend')
statusTimeout = $timeout(function(){
this.noteStatus = "All changes saved"
}.bind(this), 200)
} else {
if(statusTimeout) $timeout.cancel(statusTimeout);
statusTimeout = $timeout(function(){
this.noteStatus = "(Offline) — All changes saved"
}.bind(this), 200)
}
}.bind(this));
}
Expand All @@ -138,7 +142,7 @@ angular.module('app.frontend')
this.changesMade = function() {
this.note.hasChanges = true;
this.note.dummy = false;
if(this.user.uuid) {
if(apiController.isUserSignedIn()) {
// signed out users have local autosave, dont need draft saving
apiController.saveDraftToDisk(this.note);
}
Expand Down
39 changes: 29 additions & 10 deletions app/assets/javascripts/app/frontend/controllers/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ angular.module('app.frontend')
return {
restrict: 'E',
scope: {
user: "=",
logout: "&"
},
templateUrl: 'frontend/header.html',
Expand All @@ -21,6 +20,7 @@ angular.module('app.frontend')
})
.controller('HeaderCtrl', function ($state, apiController, modelManager, serverSideValidation, $timeout, extensionManager) {

this.user = apiController.user;
this.extensionManager = extensionManager;

this.changePasswordPressed = function() {
Expand Down Expand Up @@ -104,7 +104,7 @@ angular.module('app.frontend')
return;
}

apiController.changePassword(this.user, this.passwordChangeData.current_password, this.passwordChangeData.new_password, function(response){
apiController.changePassword(this.passwordChangeData.current_password, this.passwordChangeData.new_password, function(response){

})

Expand Down Expand Up @@ -193,24 +193,43 @@ angular.module('app.frontend')
link.click();
}

this.performImport = function(data, password) {
apiController.importJSONData(data, password, function(success, response){
console.log("import response", success, response);
if(success) {
this.importData = null;
} else {
alert("There was an error importing your data. Please try again.");
}
}.bind(this))
}

this.submitImportPassword = function() {
this.performImport(this.importData.data, this.importData.password);
}

this.importFileSelected = function(files) {
this.importData = {};

var file = files[0];
var reader = new FileReader();
reader.onload = function(e) {
apiController.importJSONData(e.target.result, function(success, response){
console.log("import response", success, response);
if(success) {
// window.location.reload();
var data = JSON.parse(e.target.result);
$timeout(function(){
if(data.auth_params) {
// request password
this.importData.requestPassword = true;
this.importData.data = data;
} else {
alert("There was an error importing your data. Please try again.");
this.performImport(data, null);
}
})
}
}.bind(this))
}.bind(this)

reader.readAsText(file);
}

this.onAuthSuccess = function(user) {
this.user.uuid = user.uuid;

// if(this.user.shouldMerge && this.hasLocalData()) {
// apiController.mergeLocalDataRemotely(this.user, function(){
Expand Down
41 changes: 15 additions & 26 deletions app/assets/javascripts/app/frontend/controllers/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,17 @@ angular.module('app.frontend')
.controller('HomeCtrl', function ($scope, $rootScope, $timeout, apiController, modelManager) {
$rootScope.bodyClass = "app-body-class";

var onUserSet = function() {
apiController.setUser($scope.defaultUser);
$scope.allTag = new Tag({all: true});
$scope.allTag.title = "All";
$scope.tags = modelManager.tags;
$scope.allTag.notes = modelManager.notes;

apiController.loadLocalItems();
$scope.allTag = new Tag({all: true});
$scope.allTag.title = "All";
$scope.tags = modelManager.tags;
$scope.allTag.notes = modelManager.notes;

apiController.sync(null);
// refresh every 30s
setInterval(function () {
apiController.sync(null);
// refresh every 30s
setInterval(function () {
apiController.sync(null);
}, 30000);
}

apiController.getCurrentUser(function(user){
if(user) {
$scope.defaultUser = user;
$rootScope.title = "Notes — Standard Notes";
onUserSet();
} else {
$scope.defaultUser = new User(apiController.loadLocalItemsAndUser());
onUserSet();
}
});
}, 30000);

/*
Tags Ctrl Callbacks
Expand Down Expand Up @@ -115,7 +102,10 @@ angular.module('app.frontend')

apiController.sync(function(response){
if(response && response.error) {
alert("There was an error saving your note. Please try again.");
if(!$scope.didShowErrorAlert) {
$scope.didShowErrorAlert = true;
alert("There was an error saving your note. Please try again.");
}
callback(false);
} else {
note.hasChanges = false;
Expand Down Expand Up @@ -147,8 +137,7 @@ angular.module('app.frontend')
*/

$scope.headerLogout = function() {
$scope.defaultUser = apiController.loadLocalItemsAndUser();
$scope.tags = $scope.defaultUser.tags;
apiController.clearLocalStorage();
}


Expand Down
3 changes: 1 addition & 2 deletions app/assets/javascripts/app/frontend/controllers/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ angular.module('app.frontend')
selectionMade: "&",
remove: "&",
tag: "=",
user: "=",
removeTag: "&"
},

Expand Down Expand Up @@ -71,7 +70,7 @@ angular.module('app.frontend')
this.selectedTagShare = function() {
this.showMenu = false;

if(!this.user.uuid) {
if(!apiController.isUserSignedIn()) {
alert("You must be signed in to share a tag.");
return;
}
Expand Down
1 change: 0 additions & 1 deletion app/assets/javascripts/app/frontend/controllers/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ angular.module('app.frontend')
save: "&",
tags: "=",
allTag: "=",
user: "=",
updateNoteTag: "&"
},
templateUrl: 'frontend/tags.html',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
angular.module('app.frontend')
.controller('UsernameModalCtrl', function ($scope, apiController, Restangular, user, callback, $timeout) {
.controller('UsernameModalCtrl', function ($scope, apiController, Restangular, callback, $timeout) {
$scope.formData = {};

$scope.saveUsername = function() {
apiController.setUsername(user, $scope.formData.username, function(response){
apiController.setUsername($scope.formData.username, function(response){
var username = response.username;
user.username = username;
callback(username);
$scope.closeThisDialog();
})
Expand Down
11 changes: 10 additions & 1 deletion app/assets/javascripts/app/frontend/models/api/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class Item {
}
}

alternateUUID() {
this.uuid = Neeto.crypto.generateUUID();
}

setDirty(dirty) {
this.dirty = dirty;

Expand Down Expand Up @@ -101,9 +105,14 @@ class Item {
_.merge(this, _.omit(item, ["content"]));
}

allReferencedObjects() {
// must override
return [];
}

referencesAffectedBySharingChange() {
// should be overriden to determine which references should be decrypted/encrypted
return null;
return [];
}

isPublic() {
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/app/frontend/models/app/note.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class Note extends Item {
return filtered;
}

allReferencedObjects() {
return this.tags;
}

referencesAffectedBySharingChange() {
return super.referencesAffectedBySharingChange();
}
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/app/frontend/models/app/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class Tag extends Item {
return "Tag";
}

allReferencedObjects() {
return this.notes;
}

referencesAffectedBySharingChange() {
return this.notes;
}
Expand Down
5 changes: 0 additions & 5 deletions app/assets/javascripts/app/frontend/models/app/user.js

This file was deleted.

Loading