merge local on auth

This commit is contained in:
Mo Bitar
2017-01-15 11:01:21 -06:00
parent fff422ff69
commit 70b80c73af
4 changed files with 48 additions and 33 deletions

View File

@@ -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;