editor note references
This commit is contained in:
@@ -52,8 +52,10 @@ angular.module('app.frontend')
|
||||
this.showMenu = false;
|
||||
this.loadTagsString();
|
||||
|
||||
if(note.editorUrl) {
|
||||
this.customEditor = this.editorForUrl(note.editorUrl);
|
||||
var editor = this.editorForNote(note);
|
||||
|
||||
if(editor) {
|
||||
this.customEditor = editor;
|
||||
this.postNoteToExternalEditor();
|
||||
} else {
|
||||
this.customEditor = null;
|
||||
@@ -75,16 +77,27 @@ angular.module('app.frontend')
|
||||
this.selectedEditor = function(editor) {
|
||||
this.showEditorMenu = false;
|
||||
if(editor.default) {
|
||||
if(this.customEditor) {
|
||||
this.customEditor.removeItemAsRelationship(this.note);
|
||||
this.customEditor.setDirty(true);
|
||||
}
|
||||
this.customEditor = null;
|
||||
} else {
|
||||
this.customEditor = editor;
|
||||
this.customEditor.addItemAsRelationship(this.note);
|
||||
this.customEditor.setDirty(true);
|
||||
}
|
||||
this.note.editorUrl = editor.url;
|
||||
}.bind(this)
|
||||
|
||||
this.editorForUrl = function(url) {
|
||||
this.editorForNote = function(note) {
|
||||
var editors = modelManager.itemsForContentType("SN|Editor");
|
||||
return editors.filter(function(editor){return editor.url == url})[0];
|
||||
for(var editor of editors) {
|
||||
// console.log(editor.notes, editor.references);
|
||||
if(_.includes(editor.notes, note)) {
|
||||
return editor;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
this.postNoteToExternalEditor = function() {
|
||||
|
||||
@@ -2,6 +2,9 @@ class Editor extends Item {
|
||||
|
||||
constructor(json_obj) {
|
||||
super(json_obj);
|
||||
if(!this.notes) {
|
||||
this.notes = [];
|
||||
}
|
||||
}
|
||||
|
||||
mapContentToLocalProperties(contentObject) {
|
||||
@@ -22,6 +25,44 @@ class Editor extends Item {
|
||||
return params;
|
||||
}
|
||||
|
||||
referenceParams() {
|
||||
var references = _.map(this.notes, function(note){
|
||||
return {uuid: note.uuid, content_type: note.content_type};
|
||||
})
|
||||
|
||||
return references;
|
||||
}
|
||||
|
||||
addItemAsRelationship(item) {
|
||||
if(item.content_type == "Note") {
|
||||
if(!_.find(this.notes, item)) {
|
||||
this.notes.push(item);
|
||||
}
|
||||
}
|
||||
super.addItemAsRelationship(item);
|
||||
}
|
||||
|
||||
removeItemAsRelationship(item) {
|
||||
if(item.content_type == "Note") {
|
||||
_.pull(this.notes, item);
|
||||
}
|
||||
super.removeItemAsRelationship(item);
|
||||
}
|
||||
|
||||
removeAllRelationships() {
|
||||
super.removeAllRelationships();
|
||||
this.notes = [];
|
||||
}
|
||||
|
||||
locallyClearAllReferences() {
|
||||
super.locallyClearAllReferences();
|
||||
this.notes = [];
|
||||
}
|
||||
|
||||
allReferencedObjects() {
|
||||
return this.notes;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {uuid: this.uuid}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class Note extends Item {
|
||||
_.pull(tag.notes, this);
|
||||
}.bind(this))
|
||||
this.tags = [];
|
||||
}
|
||||
}
|
||||
|
||||
isBeingRemovedLocally() {
|
||||
this.tags.forEach(function(tag){
|
||||
|
||||
@@ -16,7 +16,7 @@ class ItemParams {
|
||||
}
|
||||
|
||||
paramsForLocalStorage() {
|
||||
this.additionalFields = ["updated_at", "dirty", "editorUrl"];
|
||||
this.additionalFields = ["updated_at", "dirty"];
|
||||
this.forExportFile = true;
|
||||
return this.__params();
|
||||
}
|
||||
|
||||
@@ -59,7 +59,9 @@ class ModelManager {
|
||||
}
|
||||
|
||||
mapResponseItemsToLocalModelsOmittingFields(items, omitFields) {
|
||||
var models = [];
|
||||
var models = [], processedObjects = [];
|
||||
|
||||
// first loop should add and process items
|
||||
for (var json_obj of items) {
|
||||
json_obj = _.omit(json_obj, omitFields || [])
|
||||
var item = this.findItem(json_obj["uuid"]);
|
||||
@@ -80,11 +82,16 @@ class ModelManager {
|
||||
|
||||
this.addItem(item);
|
||||
|
||||
if(json_obj.content) {
|
||||
this.resolveReferencesForItem(item);
|
||||
}
|
||||
|
||||
models.push(item);
|
||||
processedObjects.push(json_obj);
|
||||
}
|
||||
|
||||
// second loop should process references
|
||||
for (var index in processedObjects) {
|
||||
var json_obj = processedObjects[index];
|
||||
if(json_obj.content) {
|
||||
this.resolveReferencesForItem(models[index]);
|
||||
}
|
||||
}
|
||||
|
||||
this.notifySyncObserversOfModels(models);
|
||||
@@ -174,6 +181,7 @@ class ModelManager {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for(var reference of contentObject.references) {
|
||||
var referencedItem = this.findItem(reference.uuid);
|
||||
if(referencedItem) {
|
||||
|
||||
@@ -187,7 +187,6 @@ class SyncManager {
|
||||
var saved = this.handleItemsResponse(response.saved_items, omitFields);
|
||||
|
||||
this.handleUnsavedItemsResponse(response.unsaved)
|
||||
|
||||
this.writeItemsToLocalStorage(saved, false, null);
|
||||
this.writeItemsToLocalStorage(retrieved, false, null);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user