handle sync error
This commit is contained in:
@@ -113,6 +113,14 @@ angular.module('app.frontend')
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$scope.safeApply = function(fn) {
|
||||||
|
var phase = this.$root.$$phase;
|
||||||
|
if(phase == '$apply' || phase == '$digest')
|
||||||
|
this.$eval(fn);
|
||||||
|
else
|
||||||
|
this.$apply(fn);
|
||||||
|
};
|
||||||
|
|
||||||
$scope.deleteNote = function(note) {
|
$scope.deleteNote = function(note) {
|
||||||
|
|
||||||
modelManager.setItemToBeDeleted(note);
|
modelManager.setItemToBeDeleted(note);
|
||||||
@@ -129,7 +137,9 @@ angular.module('app.frontend')
|
|||||||
apiController.sync(function(){
|
apiController.sync(function(){
|
||||||
if(!apiController.user) {
|
if(!apiController.user) {
|
||||||
// when deleting items while ofline, we need to explictly tell angular to refresh UI
|
// when deleting items while ofline, we need to explictly tell angular to refresh UI
|
||||||
$scope.$apply();
|
setTimeout(function () {
|
||||||
|
$scope.safeApply();
|
||||||
|
}, 50);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,21 +221,32 @@ angular.module('app.frontend')
|
|||||||
|
|
||||||
var allDirtyItems = modelManager.getDirtyItems();
|
var allDirtyItems = modelManager.getDirtyItems();
|
||||||
|
|
||||||
if(!this.isUserSignedIn()) {
|
// we want to write all dirty items to disk only if the user is not signed in, or if the sync op fails
|
||||||
|
// if the sync op succeeds, these items will be written to disk by handling the "saved_items" response from the server
|
||||||
|
var writeAllDirtyItemsToDisk = function(completion) {
|
||||||
this.writeItemsToLocalStorage(allDirtyItems, function(responseItems){
|
this.writeItemsToLocalStorage(allDirtyItems, function(responseItems){
|
||||||
// delete anything needing to be deleted
|
if(completion) {
|
||||||
allDirtyItems.forEach(function(item){
|
completion();
|
||||||
if(item.deleted) {
|
}
|
||||||
modelManager.removeItemLocally(item);
|
})
|
||||||
}
|
}.bind(this);
|
||||||
}.bind(this))
|
|
||||||
modelManager.clearDirtyItems(allDirtyItems);
|
|
||||||
if(callback) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}.bind(this))
|
|
||||||
|
|
||||||
|
if(!this.isUserSignedIn()) {
|
||||||
|
writeAllDirtyItemsToDisk(function(){
|
||||||
|
// delete anything needing to be deleted
|
||||||
|
allDirtyItems.forEach(function(item){
|
||||||
|
if(item.deleted) {
|
||||||
|
modelManager.removeItemLocally(item);
|
||||||
|
}
|
||||||
|
}.bind(this))
|
||||||
|
|
||||||
|
modelManager.clearDirtyItems(allDirtyItems);
|
||||||
|
|
||||||
|
}.bind(this))
|
||||||
this.syncOpInProgress = false;
|
this.syncOpInProgress = false;
|
||||||
|
if(callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,10 +301,14 @@ angular.module('app.frontend')
|
|||||||
}.bind(this))
|
}.bind(this))
|
||||||
.catch(function(response){
|
.catch(function(response){
|
||||||
console.log("Sync error: ", response);
|
console.log("Sync error: ", response);
|
||||||
|
|
||||||
|
writeAllDirtyItemsToDisk();
|
||||||
|
this.syncOpInProgress = false;
|
||||||
|
|
||||||
if(callback) {
|
if(callback) {
|
||||||
callback({error: "Sync error"});
|
callback({error: "Sync error"});
|
||||||
}
|
}
|
||||||
})
|
}.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sync = function(callback) {
|
this.sync = function(callback) {
|
||||||
|
|||||||
Reference in New Issue
Block a user