fix import uuid change, export all items
This commit is contained in:
@@ -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 [];
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user