Resolve relationships for duplicate items, rename contentObject to content in mapping function

This commit is contained in:
Mo Bitar
2017-11-04 18:05:01 -05:00
parent 9b0f802537
commit e547d344b7
13 changed files with 61 additions and 51 deletions

View File

@@ -80,7 +80,9 @@ angular.module('app.frontend')
this.showMenu = false;
if(this.selectedNote && this.selectedNote.dummy) {
_.remove(oldTag.notes, this.selectedNote);
if(oldTag) {
_.remove(oldTag.notes, this.selectedNote);
}
}
this.noteFilter.text = "";

View File

@@ -66,6 +66,7 @@ class Item {
reference.setDirty(true);
})
}
addObserver(observer, callback) {
if(!_.find(this.observers, observer)) {
this.observers.push({observer: observer, callback: callback});

View File

@@ -4,9 +4,9 @@ class SyncAdapter extends Item {
super(json_obj);
}
mapContentToLocalProperties(contentObject) {
super.mapContentToLocalProperties(contentObject)
this.url = contentObject.url;
mapContentToLocalProperties(content) {
super.mapContentToLocalProperties(content)
this.url = content.url;
}
structureParams() {

View File

@@ -12,22 +12,22 @@ class Component extends Item {
}
}
mapContentToLocalProperties(contentObject) {
super.mapContentToLocalProperties(contentObject)
this.url = contentObject.url;
this.name = contentObject.name;
mapContentToLocalProperties(content) {
super.mapContentToLocalProperties(content)
this.url = content.url;
this.name = content.name;
// the location in the view this component is located in. Valid values are currently tags-list, note-tags, and editor-stack`
this.area = contentObject.area;
this.area = content.area;
this.permissions = contentObject.permissions;
this.active = contentObject.active;
this.permissions = content.permissions;
this.active = content.active;
// custom data that a component can store in itself
this.componentData = contentObject.componentData || {};
this.componentData = content.componentData || {};
// items that have requested a component to be disabled in its context
this.disassociatedItemIds = contentObject.disassociatedItemIds || [];
this.disassociatedItemIds = content.disassociatedItemIds || [];
}
structureParams() {

View File

@@ -10,13 +10,13 @@ class Editor extends Item {
}
}
mapContentToLocalProperties(contentObject) {
super.mapContentToLocalProperties(contentObject)
this.url = contentObject.url;
this.name = contentObject.name;
this.data = contentObject.data || {};
this.default = contentObject.default;
this.systemEditor = contentObject.systemEditor;
mapContentToLocalProperties(content) {
super.mapContentToLocalProperties(content)
this.url = content.url;
this.name = content.name;
this.data = content.data || {};
this.default = content.default;
this.systemEditor = content.systemEditor;
}
structureParams() {

View File

@@ -80,21 +80,21 @@ class Extension extends Item {
})
}
mapContentToLocalProperties(contentObject) {
super.mapContentToLocalProperties(contentObject)
this.name = contentObject.name;
this.description = contentObject.description;
this.url = contentObject.url;
mapContentToLocalProperties(content) {
super.mapContentToLocalProperties(content)
this.name = content.name;
this.description = content.description;
this.url = content.url;
if(contentObject.encrypted !== null && contentObject.encrypted !== undefined) {
this.encrypted = contentObject.encrypted;
if(content.encrypted !== null && content.encrypted !== undefined) {
this.encrypted = content.encrypted;
} else {
this.encrypted = true;
}
this.supported_types = contentObject.supported_types;
if(contentObject.actions) {
this.actions = contentObject.actions.map(function(action){
this.supported_types = content.supported_types;
if(content.actions) {
this.actions = content.actions.map(function(action){
return new Action(action);
})
}

View File

@@ -8,10 +8,10 @@ class Note extends Item {
}
}
mapContentToLocalProperties(contentObject) {
super.mapContentToLocalProperties(contentObject)
this.title = contentObject.title;
this.text = contentObject.text;
mapContentToLocalProperties(content) {
super.mapContentToLocalProperties(content)
this.title = content.title;
this.text = content.text;
}
referenceParams() {

View File

@@ -8,9 +8,9 @@ class Tag extends Item {
}
}
mapContentToLocalProperties(contentObject) {
super.mapContentToLocalProperties(contentObject)
this.title = contentObject.title;
mapContentToLocalProperties(content) {
super.mapContentToLocalProperties(content)
this.title = content.title;
}
referenceParams() {

View File

@@ -4,10 +4,10 @@ class Theme extends Item {
super(json_obj);
}
mapContentToLocalProperties(contentObject) {
super.mapContentToLocalProperties(contentObject)
this.url = contentObject.url;
this.name = contentObject.name;
mapContentToLocalProperties(content) {
super.mapContentToLocalProperties(content)
this.url = content.url;
this.name = content.name;
}
structureParams() {

View File

@@ -4,9 +4,9 @@ class EncryptedStorage extends Item {
super(json_obj);
}
mapContentToLocalProperties(contentObject) {
super.mapContentToLocalProperties(contentObject)
this.storage = contentObject.storage;
mapContentToLocalProperties(content) {
super.mapContentToLocalProperties(content)
this.storage = content.storage;
}
structureParams() {

View File

@@ -9,7 +9,10 @@ class ModelManager {
this.itemsPendingRemoval = [];
this.items = [];
this._extensions = [];
this.acceptableContentTypes = ["Note", "Tag", "Extension", "SN|Editor", "SN|Theme", "SN|Component", "SF|Extension"];
this.acceptableContentTypes = [
"Note", "Tag", "Extension", "SN|Editor", "SN|Theme",
"SN|Component", "SF|Extension", "SN|UserPreferences"
];
}
resetLocalMemory() {
@@ -120,11 +123,6 @@ class ModelManager {
continue;
}
if(!json_obj.content && !item) {
// A new incoming item must have a content field. If not, something has set an invalid state.
console.error("Content is missing for new item.", json_obj);
}
var unknownContentType = !_.includes(this.acceptableContentTypes, json_obj["content_type"]);
if(json_obj.deleted == true || unknownContentType) {
if(item && !unknownContentType) {
@@ -217,6 +215,12 @@ class ModelManager {
return item;
}
createDuplicateItem(itemResponse, sourceItem) {
var dup = this.createItem(itemResponse);
this.resolveReferencesForItem(dup);
return dup;
}
addItems(items) {
items.forEach(function(item){
if(item.content_type == "Tag") {

View File

@@ -390,7 +390,7 @@ class SyncManager {
// We want a new uuid for the new item. Note that this won't neccessarily adjust references.
itemResponse.uuid = null;
var dup = this.modelManager.createItem(itemResponse);
var dup = this.modelManager.createDuplicateItem(itemResponse, item);
if(!itemResponse.deleted && JSON.stringify(item.structureParams()) !== JSON.stringify(dup.structureParams())) {
this.modelManager.addItem(dup);
dup.conflict_of = item.uuid;

View File

@@ -16,7 +16,10 @@
"ng-keyup" => "$event.keyCode == 13 && ctrl.saveTag($event, tag)", "mb-autofocus" => "true", "should-focus" => "ctrl.newTag || ctrl.editingTag == tag",
"ng-change" => "ctrl.tagTitleDidChange(tag)", "ng-blur" => "ctrl.saveTag($event, tag)", "spellcheck" => "false"}
.count {{ctrl.noteCount(tag)}}
.red.small.bold{"ng-if" => "tag.conflict_of"} Conflicted copy
.red.small.bold{"ng-if" => "tag.errorDecrypting"} Error decrypting
.menu{"ng-if" => "ctrl.selectedTag == tag"}
%a.item{"ng-click" => "ctrl.selectedRenameTag($event, tag)", "ng-if" => "!ctrl.editingTag"} Rename
%a.item{"ng-click" => "ctrl.saveTag($event, tag)", "ng-if" => "ctrl.editingTag"} Save