merge local on auth
This commit is contained in:
@@ -16,10 +16,11 @@ angular.module('app.frontend')
|
||||
}
|
||||
}
|
||||
})
|
||||
.controller('HeaderCtrl', function ($state, apiController, modelManager, $timeout, extensionManager) {
|
||||
.controller('HeaderCtrl', function ($state, apiController, modelManager, $timeout, extensionManager, dbManager) {
|
||||
|
||||
this.user = apiController.user;
|
||||
this.extensionManager = extensionManager;
|
||||
this.loginData = {mergeLocal: true};
|
||||
|
||||
this.changePasswordPressed = function() {
|
||||
this.showNewPasswordForm = !this.showNewPasswordForm;
|
||||
@@ -109,14 +110,14 @@ angular.module('app.frontend')
|
||||
}.bind(this))
|
||||
}
|
||||
|
||||
this.hasLocalData = function() {
|
||||
return modelManager.filteredNotes.length > 0;
|
||||
this.localNotesCount = function() {
|
||||
return modelManager.filteredNotes.length;
|
||||
}
|
||||
|
||||
this.mergeLocalChanged = function() {
|
||||
if(!this.user.shouldMerge) {
|
||||
if(!confirm("Unchecking this option means any locally stored tags and notes you have now will be deleted. Are you sure you want to continue?")) {
|
||||
this.user.shouldMerge = true;
|
||||
if(!this.loginData.mergeLocal) {
|
||||
if(!confirm("Unchecking this option means any of the notes you have written while you were signed out will be deleted. Are you sure you want to discard these notes?")) {
|
||||
this.loginData.mergeLocal = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,8 +140,13 @@ angular.module('app.frontend')
|
||||
this.lastSyncDate = new Date();
|
||||
}
|
||||
|
||||
this.handleLocalNotesOnAuthSubmit = function() {
|
||||
|
||||
}
|
||||
|
||||
this.loginSubmitPressed = function() {
|
||||
this.loginData.status = "Generating Login Keys...";
|
||||
|
||||
$timeout(function(){
|
||||
apiController.login(this.loginData.email, this.loginData.user_password, function(response){
|
||||
if(!response || response.error) {
|
||||
@@ -228,9 +234,19 @@ angular.module('app.frontend')
|
||||
}
|
||||
|
||||
this.onAuthSuccess = function(user) {
|
||||
window.location.reload();
|
||||
this.showLogin = false;
|
||||
this.showRegistration = false;
|
||||
var block = function(){
|
||||
window.location.reload();
|
||||
this.showLogin = false;
|
||||
this.showRegistration = false;
|
||||
}.bind(this);
|
||||
|
||||
if(!this.loginData.mergeLocal) {
|
||||
dbManager.clearAllItems(function(){
|
||||
block();
|
||||
});
|
||||
} else {
|
||||
block();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -21,14 +21,9 @@ angular.module('app.frontend')
|
||||
Tags Ctrl Callbacks
|
||||
*/
|
||||
|
||||
$scope.updateAllTag = function() {
|
||||
// $scope.allTag.notes = modelManager.notes;
|
||||
}
|
||||
|
||||
$scope.tagsWillMakeSelection = function(tag) {
|
||||
if(tag.all) {
|
||||
$scope.updateAllTag();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$scope.tagsSelectionMade = function(tag) {
|
||||
@@ -92,7 +87,6 @@ angular.module('app.frontend')
|
||||
|
||||
if(!$scope.selectedTag.all) {
|
||||
modelManager.createRelationshipBetweenItems($scope.selectedTag, note);
|
||||
$scope.updateAllTag();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,6 +126,11 @@ angular.module('app.frontend')
|
||||
return;
|
||||
}
|
||||
|
||||
apiController.sync(null);
|
||||
apiController.sync(function(){
|
||||
if(!apiController.user) {
|
||||
// when deleting items while ofline, we need to explictly tell angular to refresh UI
|
||||
$scope.$apply();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -221,24 +221,15 @@ angular.module('app.frontend')
|
||||
|
||||
var allDirtyItems = modelManager.getDirtyItems();
|
||||
|
||||
let submitLimit = 100;
|
||||
var dirtyItems = allDirtyItems.slice(0, submitLimit);
|
||||
if(dirtyItems.length < allDirtyItems.length) {
|
||||
// more items left to be synced, repeat
|
||||
this.repeatSync = true;
|
||||
} else {
|
||||
this.repeatSync = false;
|
||||
}
|
||||
|
||||
if(!this.isUserSignedIn()) {
|
||||
this.writeItemsToLocalStorage(dirtyItems, function(responseItems){
|
||||
this.writeItemsToLocalStorage(allDirtyItems, function(responseItems){
|
||||
// delete anything needing to be deleted
|
||||
dirtyItems.forEach(function(item){
|
||||
allDirtyItems.forEach(function(item){
|
||||
if(item.deleted) {
|
||||
modelManager.removeItemLocally(item);
|
||||
}
|
||||
}.bind(this))
|
||||
modelManager.clearDirtyItems(dirtyItems);
|
||||
modelManager.clearDirtyItems(allDirtyItems);
|
||||
if(callback) {
|
||||
callback();
|
||||
}
|
||||
@@ -248,6 +239,15 @@ angular.module('app.frontend')
|
||||
return;
|
||||
}
|
||||
|
||||
let submitLimit = 100;
|
||||
var dirtyItems = allDirtyItems.slice(0, submitLimit);
|
||||
if(dirtyItems.length < allDirtyItems.length) {
|
||||
// more items left to be synced, repeat
|
||||
this.repeatSync = true;
|
||||
} else {
|
||||
this.repeatSync = false;
|
||||
}
|
||||
|
||||
var request = Restangular.one("items/sync");
|
||||
request.limit = 150;
|
||||
request.sync_token = this.syncToken;
|
||||
|
||||
@@ -28,10 +28,10 @@
|
||||
%input.form-control.login-input{:autofocus => 'autofocus', :name => 'email', :placeholder => 'Email', :required => true, :type => 'email', 'ng-model' => 'ctrl.loginData.email'}
|
||||
.form-tag.has-feedback
|
||||
%input.form-control.login-input{:placeholder => 'Password', :name => 'password', :required => true, :type => 'password', 'ng-model' => 'ctrl.loginData.user_password'}
|
||||
-# .checkbox{"ng-if" => "ctrl.hasLocalData()"}
|
||||
-# %label
|
||||
-# %input{"type" => "checkbox", "ng-model" => "ctrl.user.shouldMerge", "ng-bind" => "true", "ng-change" => "ctrl.mergeLocalChanged()"}
|
||||
-# Merge local notes
|
||||
.checkbox{"ng-if" => "ctrl.localNotesCount() > 0"}
|
||||
%label
|
||||
%input{"type" => "checkbox", "ng-model" => "ctrl.loginData.mergeLocal", "ng-bind" => "true", "ng-change" => "ctrl.mergeLocalChanged()"}
|
||||
Merge local notes ({{ctrl.localNotesCount()}} notes)
|
||||
%button.btn.dark-button.half-button{"ng-click" => "ctrl.loginSubmitPressed()", "data-style" => "expand-right", "data-size" => "s", "state" => "buttonState"}
|
||||
%span Sign In
|
||||
%button.btn.dark-button.half-button{"ng-click" => "ctrl.submitRegistrationForm()", "data-style" => "expand-right", "data-size" => "s", "state" => "buttonState"}
|
||||
|
||||
Reference in New Issue
Block a user