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.user = apiController.user;
|
||||||
this.extensionManager = extensionManager;
|
this.extensionManager = extensionManager;
|
||||||
|
this.loginData = {mergeLocal: true};
|
||||||
|
|
||||||
this.changePasswordPressed = function() {
|
this.changePasswordPressed = function() {
|
||||||
this.showNewPasswordForm = !this.showNewPasswordForm;
|
this.showNewPasswordForm = !this.showNewPasswordForm;
|
||||||
@@ -109,14 +110,14 @@ angular.module('app.frontend')
|
|||||||
}.bind(this))
|
}.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hasLocalData = function() {
|
this.localNotesCount = function() {
|
||||||
return modelManager.filteredNotes.length > 0;
|
return modelManager.filteredNotes.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mergeLocalChanged = function() {
|
this.mergeLocalChanged = function() {
|
||||||
if(!this.user.shouldMerge) {
|
if(!this.loginData.mergeLocal) {
|
||||||
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?")) {
|
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.user.shouldMerge = true;
|
this.loginData.mergeLocal = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,8 +140,13 @@ angular.module('app.frontend')
|
|||||||
this.lastSyncDate = new Date();
|
this.lastSyncDate = new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.handleLocalNotesOnAuthSubmit = function() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
this.loginSubmitPressed = function() {
|
this.loginSubmitPressed = function() {
|
||||||
this.loginData.status = "Generating Login Keys...";
|
this.loginData.status = "Generating Login Keys...";
|
||||||
|
|
||||||
$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 || response.error) {
|
if(!response || response.error) {
|
||||||
@@ -228,9 +234,19 @@ angular.module('app.frontend')
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.onAuthSuccess = function(user) {
|
this.onAuthSuccess = function(user) {
|
||||||
window.location.reload();
|
var block = function(){
|
||||||
this.showLogin = false;
|
window.location.reload();
|
||||||
this.showRegistration = false;
|
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
|
Tags Ctrl Callbacks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$scope.updateAllTag = function() {
|
|
||||||
// $scope.allTag.notes = modelManager.notes;
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.tagsWillMakeSelection = function(tag) {
|
$scope.tagsWillMakeSelection = function(tag) {
|
||||||
if(tag.all) {
|
|
||||||
$scope.updateAllTag();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.tagsSelectionMade = function(tag) {
|
$scope.tagsSelectionMade = function(tag) {
|
||||||
@@ -92,7 +87,6 @@ angular.module('app.frontend')
|
|||||||
|
|
||||||
if(!$scope.selectedTag.all) {
|
if(!$scope.selectedTag.all) {
|
||||||
modelManager.createRelationshipBetweenItems($scope.selectedTag, note);
|
modelManager.createRelationshipBetweenItems($scope.selectedTag, note);
|
||||||
$scope.updateAllTag();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,6 +126,11 @@ angular.module('app.frontend')
|
|||||||
return;
|
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();
|
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()) {
|
if(!this.isUserSignedIn()) {
|
||||||
this.writeItemsToLocalStorage(dirtyItems, function(responseItems){
|
this.writeItemsToLocalStorage(allDirtyItems, function(responseItems){
|
||||||
// delete anything needing to be deleted
|
// delete anything needing to be deleted
|
||||||
dirtyItems.forEach(function(item){
|
allDirtyItems.forEach(function(item){
|
||||||
if(item.deleted) {
|
if(item.deleted) {
|
||||||
modelManager.removeItemLocally(item);
|
modelManager.removeItemLocally(item);
|
||||||
}
|
}
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
modelManager.clearDirtyItems(dirtyItems);
|
modelManager.clearDirtyItems(allDirtyItems);
|
||||||
if(callback) {
|
if(callback) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
@@ -248,6 +239,15 @@ angular.module('app.frontend')
|
|||||||
return;
|
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");
|
var request = Restangular.one("items/sync");
|
||||||
request.limit = 150;
|
request.limit = 150;
|
||||||
request.sync_token = this.syncToken;
|
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'}
|
%input.form-control.login-input{:autofocus => 'autofocus', :name => 'email', :placeholder => 'Email', :required => true, :type => 'email', 'ng-model' => 'ctrl.loginData.email'}
|
||||||
.form-tag.has-feedback
|
.form-tag.has-feedback
|
||||||
%input.form-control.login-input{:placeholder => 'Password', :name => 'password', :required => true, :type => 'password', 'ng-model' => 'ctrl.loginData.user_password'}
|
%input.form-control.login-input{:placeholder => 'Password', :name => 'password', :required => true, :type => 'password', 'ng-model' => 'ctrl.loginData.user_password'}
|
||||||
-# .checkbox{"ng-if" => "ctrl.hasLocalData()"}
|
.checkbox{"ng-if" => "ctrl.localNotesCount() > 0"}
|
||||||
-# %label
|
%label
|
||||||
-# %input{"type" => "checkbox", "ng-model" => "ctrl.user.shouldMerge", "ng-bind" => "true", "ng-change" => "ctrl.mergeLocalChanged()"}
|
%input{"type" => "checkbox", "ng-model" => "ctrl.loginData.mergeLocal", "ng-bind" => "true", "ng-change" => "ctrl.mergeLocalChanged()"}
|
||||||
-# Merge local notes
|
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"}
|
%button.btn.dark-button.half-button{"ng-click" => "ctrl.loginSubmitPressed()", "data-style" => "expand-right", "data-size" => "s", "state" => "buttonState"}
|
||||||
%span Sign In
|
%span Sign In
|
||||||
%button.btn.dark-button.half-button{"ng-click" => "ctrl.submitRegistrationForm()", "data-style" => "expand-right", "data-size" => "s", "state" => "buttonState"}
|
%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