offline mode

This commit is contained in:
Mo Bitar
2017-01-08 00:18:30 -06:00
parent 6823469062
commit 93e3a72d30
12 changed files with 269 additions and 323 deletions

View File

@@ -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(){});
}
}

View File

@@ -5,8 +5,7 @@ angular.module('app.frontend')
scope: {
save: "&",
remove: "&",
note: "=",
user: "="
note: "="
},
templateUrl: 'frontend/editor.html',
replace: true,
@@ -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));
}
@@ -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);
}

View File

@@ -3,7 +3,6 @@ angular.module('app.frontend')
return {
restrict: 'E',
scope: {
user: "=",
logout: "&"
},
templateUrl: 'frontend/header.html',
@@ -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() {
@@ -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){
})
@@ -210,7 +210,6 @@ angular.module('app.frontend')
}
this.onAuthSuccess = function(user) {
this.user.uuid = user.uuid;
// if(this.user.shouldMerge && this.hasLocalData()) {
// apiController.mergeLocalDataRemotely(this.user, function(){

View File

@@ -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
@@ -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;
@@ -147,8 +137,7 @@ angular.module('app.frontend')
*/
$scope.headerLogout = function() {
$scope.defaultUser = apiController.loadLocalItemsAndUser();
$scope.tags = $scope.defaultUser.tags;
apiController.clearLocalStorage();
}

View File

@@ -6,7 +6,6 @@ angular.module('app.frontend')
selectionMade: "&",
remove: "&",
tag: "=",
user: "=",
removeTag: "&"
},
@@ -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;
}

View File

@@ -9,7 +9,6 @@ angular.module('app.frontend')
save: "&",
tags: "=",
allTag: "=",
user: "=",
updateNoteTag: "&"
},
templateUrl: 'frontend/tags.html',

View File

@@ -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();
})