Resolve relationships for duplicate items, rename contentObject to content in mapping function
This commit is contained in:
@@ -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 = "";
|
||||
|
||||
@@ -66,6 +66,7 @@ class Item {
|
||||
reference.setDirty(true);
|
||||
})
|
||||
}
|
||||
|
||||
addObserver(observer, callback) {
|
||||
if(!_.find(this.observers, observer)) {
|
||||
this.observers.push({observer: observer, callback: callback});
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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") {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user