fix import uuid change, export all items

This commit is contained in:
Mo Bitar
2017-04-29 12:24:44 -05:00
parent 0070c9e460
commit 80c723b400
6 changed files with 42 additions and 1 deletions

View File

@@ -121,6 +121,14 @@ class Item {
_.merge(this, _.omit(item, ["content"]));
}
informReferencesOfUUIDChange(oldUUID, newUUID) {
// optional override
}
potentialItemOfInterestHasChangedItsUUID(newItem, oldUUID, newUUID) {
// optional override
}
allReferencedObjects() {
// must override
return [];

View File

@@ -66,6 +66,13 @@ class Editor extends Item {
this.notes = [];
}
potentialItemOfInterestHasChangedItsUUID(newItem, oldUUID, newUUID) {
if(newItem.content_type === "Note" && _.find(this.notes, {uuid: oldUUID})) {
_.pull(this.notes, {uuid: oldUUID});
this.notes.push(newItem);
}
}
allReferencedObjects() {
return this.notes;
}

View File

@@ -76,6 +76,13 @@ class Note extends Item {
return filtered;
}
informReferencesOfUUIDChange(oldUUID, newUUID) {
for(var tag of this.tags) {
_.pull(tag.notes, {uuid: oldUUID});
tag.notes.push(this);
}
}
allReferencedObjects() {
return this.tags;
}

View File

@@ -71,6 +71,13 @@ class Tag extends Item {
super.isBeingRemovedLocally();
}
informReferencesOfUUIDChange(oldUUID, newUUID) {
for(var note of this.notes) {
_.pull(note.tags, {uuid: oldUUID});
note.tags.push(this);
}
}
get content_type() {
return "Tag";
}

View File

@@ -337,7 +337,7 @@ class AccountMenu {
}
$scope.itemsData = function(keys) {
var items = _.map(modelManager.allItemsMatchingTypes(["Tag", "Note"]), function(item){
var items = _.map(modelManager.allItems, function(item){
var itemParams = new ItemParams(item, keys);
return itemParams.paramsForExportFile();
}.bind(this));

View File

@@ -27,6 +27,8 @@ class ModelManager {
// we need to clone this item and give it a new uuid, then delete item with old uuid from db (you can't mofidy uuid's in our indexeddb setup)
var newItem = this.createItem(item);
newItem.uuid = Neeto.crypto.generateUUID();
newItem.informReferencesOfUUIDChange(item.uuid, newItem.uuid);
this.informModelsOfUUIDChangeForItem(newItem, item.uuid, newItem.uuid);
this.removeItemLocally(item, function(){
this.addItem(newItem);
newItem.setDirty(true);
@@ -35,6 +37,16 @@ class ModelManager {
}.bind(this));
}
informModelsOfUUIDChangeForItem(newItem, oldUUID, newUUID) {
// some models that only have one-way relationships might be interested to hear that an item has changed its uuid
// for example, editors have a one way relationship with notes. When a note changes its UUID, it has no way to inform the editor
// to update its relationships
for(var model of this.items) {
model.potentialItemOfInterestHasChangedItsUUID(newItem, oldUUID, newUUID);
}
}
allItemsMatchingTypes(contentTypes) {
return this.items.filter(function(item){
return (_.includes(contentTypes, item.content_type) || _.includes(contentTypes, "*")) && !item.dummy;