This commit is contained in:
Mo Bitar
2018-07-03 12:41:12 -05:00
parent cfcac7008b
commit 8c9fd9308d
5 changed files with 58 additions and 12 deletions

View File

@@ -36,10 +36,6 @@ angular.module('app')
this.syncTakingTooLong = false;
}.bind(this));
$rootScope.$on("tag-changed", function(){
this.loadTagsString();
}.bind(this));
// Right now this only handles offline saving status changes.
this.syncStatusObserver = syncManager.registerSyncStatusObserver((status) => {
if(status.localError) {
@@ -80,6 +76,18 @@ angular.module('app')
this.loadTagsString();
});
modelManager.addItemSyncObserver("component-manager", "Tag", (allItems, validItems, deletedItems, source) => {
if(!this.note) { return; }
for(var tag of allItems) {
// If a tag is deleted then we'll have lost references to notes. Reload anyway.
if(this.note.savedTagsString == null || tag.deleted || tag.hasRelationshipWithItem(this.note)) {
this.loadTagsString();
return;
}
}
});
this.noteDidChange = function(note, oldNote) {
this.setNote(note, oldNote);
this.reloadComponentContext();
@@ -554,7 +562,7 @@ angular.module('app')
// Currently extensions are not notified of association until a full server sync completes.
// We need a better system for this, but for now, we'll manually notify observers
modelManager.notifySyncObserversOfModels([this.note], SFModelManager.MappingSourceLocalSaved);
modelManager.notifySyncObserversOfModels([tag], SFModelManager.MappingSourceLocalSaved);
}
}
@@ -564,7 +572,7 @@ angular.module('app')
// Currently extensions are not notified of association until a full server sync completes.
// We need a better system for this, but for now, we'll manually notify observers
modelManager.notifySyncObserversOfModels([this.note], SFModelManager.MappingSourceLocalSaved);
modelManager.notifySyncObserversOfModels([tag], SFModelManager.MappingSourceLocalSaved);
}
else if(action === "save-items" || action === "save-success" || action == "save-error") {

View File

@@ -180,7 +180,6 @@ angular.module('app')
}
tag.setDirty(true);
syncManager.sync().then(callback);
$rootScope.$broadcast("tag-changed");
modelManager.resortTag(tag);
}

View File

@@ -47,6 +47,10 @@ class DBManager {
}
};
request.onblocked = (event) => {
console.error("Request blocked error:", event.target.errorCode);
}
request.onupgradeneeded = (event) => {
var db = event.target.result;
@@ -106,7 +110,11 @@ class DBManager {
};
transaction.onerror = function(event) {
console.log("Transaction error:", event.target.errorCode);
console.error("Transaction error:", event.target.errorCode);
};
transaction.onblocked = function(event) {
console.error("Transaction blocked error:", event.target.errorCode);
};
transaction.onabort = function(event) {
@@ -127,12 +135,14 @@ class DBManager {
function putNext() {
if (i < items.length) {
var item = items[i];
itemObjectStore.put(item).onsuccess = putNext;
var request = itemObjectStore.put(item);
request.onerror = (event) => {
console.error("DB put error:", event.target.error);
}
request.onsuccess = putNext;
++i;
} else {
if(onsuccess){
onsuccess();
}
onsuccess && onsuccess();
}
}
}, null)