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; this.showMenu = false;
if(this.selectedNote && this.selectedNote.dummy) { if(this.selectedNote && this.selectedNote.dummy) {
_.remove(oldTag.notes, this.selectedNote); if(oldTag) {
_.remove(oldTag.notes, this.selectedNote);
}
} }
this.noteFilter.text = ""; this.noteFilter.text = "";

View File

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

View File

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

View File

@@ -12,22 +12,22 @@ class Component extends Item {
} }
} }
mapContentToLocalProperties(contentObject) { mapContentToLocalProperties(content) {
super.mapContentToLocalProperties(contentObject) super.mapContentToLocalProperties(content)
this.url = contentObject.url; this.url = content.url;
this.name = contentObject.name; 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` // 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.permissions = content.permissions;
this.active = contentObject.active; this.active = content.active;
// custom data that a component can store in itself // 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 // items that have requested a component to be disabled in its context
this.disassociatedItemIds = contentObject.disassociatedItemIds || []; this.disassociatedItemIds = content.disassociatedItemIds || [];
} }
structureParams() { structureParams() {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -9,7 +9,10 @@ class ModelManager {
this.itemsPendingRemoval = []; this.itemsPendingRemoval = [];
this.items = []; this.items = [];
this._extensions = []; 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() { resetLocalMemory() {
@@ -120,11 +123,6 @@ class ModelManager {
continue; 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"]); var unknownContentType = !_.includes(this.acceptableContentTypes, json_obj["content_type"]);
if(json_obj.deleted == true || unknownContentType) { if(json_obj.deleted == true || unknownContentType) {
if(item && !unknownContentType) { if(item && !unknownContentType) {
@@ -217,6 +215,12 @@ class ModelManager {
return item; return item;
} }
createDuplicateItem(itemResponse, sourceItem) {
var dup = this.createItem(itemResponse);
this.resolveReferencesForItem(dup);
return dup;
}
addItems(items) { addItems(items) {
items.forEach(function(item){ items.forEach(function(item){
if(item.content_type == "Tag") { 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. // We want a new uuid for the new item. Note that this won't neccessarily adjust references.
itemResponse.uuid = null; 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())) { if(!itemResponse.deleted && JSON.stringify(item.structureParams()) !== JSON.stringify(dup.structureParams())) {
this.modelManager.addItem(dup); this.modelManager.addItem(dup);
dup.conflict_of = item.uuid; 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-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"} "ng-change" => "ctrl.tagTitleDidChange(tag)", "ng-blur" => "ctrl.saveTag($event, tag)", "spellcheck" => "false"}
.count {{ctrl.noteCount(tag)}} .count {{ctrl.noteCount(tag)}}
.red.small.bold{"ng-if" => "tag.conflict_of"} Conflicted copy .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"} .menu{"ng-if" => "ctrl.selectedTag == tag"}
%a.item{"ng-click" => "ctrl.selectedRenameTag($event, tag)", "ng-if" => "!ctrl.editingTag"} Rename %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 %a.item{"ng-click" => "ctrl.saveTag($event, tag)", "ng-if" => "ctrl.editingTag"} Save