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

@@ -163,4 +163,7 @@ module.exports = function(grunt) {
grunt.registerTask('default', ['haml', 'ngtemplates', 'sass', 'concat:app', 'babel', 'browserify',
'concat:lib', 'concat:dist', 'ngAnnotate', 'concat:css', 'uglify']);
grunt.registerTask('vendor', ['concat:app', 'babel', 'browserify',
'concat:lib', 'concat:dist', 'ngAnnotate', 'concat:css', 'uglify']);
};

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)

View File

@@ -157,6 +157,32 @@ describe("notes and tags", () => {
expect(tag.notes.length).to.equal(0);
});
it.only('resets cached note tags string when tag is renamed', () => {
let modelManager = Factory.createModelManager();
let pair = createRelatedNoteTagPair();
let noteParams = pair[0];
let tagParams = pair[1];
modelManager.mapResponseItemsToLocalModels([noteParams, tagParams]);
let note = modelManager.allItemsMatchingTypes(["Note"])[0];
let tag = modelManager.allItemsMatchingTypes(["Tag"])[0];
expect(note.tagsString()).to.equal(`#${tagParams.content.title}`);
var title = Math.random();
// Saving involves modifying local state first, then syncing with omitting content.
tag.title = title;
tagParams.content.title = title;
// simulate a save, which omits `content`
modelManager.mapResponseItemsToLocalModelsOmittingFields([tagParams], ['content']);
// should be null
expect(note.savedTagsString).to.not.be.ok;
expect(note.tagsString()).to.equal(`#${title}`);
});
it('handles removing relationship between note and tag', () => {
let modelManager = Factory.createModelManager();