more consistent handling of tree data structures when creating new note

This commit is contained in:
azivner 2017-12-09 21:53:21 -05:00
parent 3abbe2d970
commit 7483f11d10

View File

@ -91,6 +91,24 @@ const noteTree = (function() {
}); });
} }
function setParentChildRelation(noteTreeId, parentNoteId, childNoteId) {
const key = parentNoteId + "-" + childNoteId;
parentChildToNoteTreeId[key] = noteTreeId;
if (!parentToChildren[parentNoteId]) {
parentToChildren[parentNoteId] = [];
}
parentToChildren[parentNoteId].push(childNoteId);
if (!childToParents[childNoteId]) {
childToParents[childNoteId] = [];
}
childToParents[childNoteId].push(parentNoteId);
}
function prepareNoteTree(notes) { function prepareNoteTree(notes) {
parentToChildren = {}; parentToChildren = {};
childToParents = {}; childToParents = {};
@ -103,21 +121,7 @@ const noteTree = (function() {
delete note.note_title; // this should not be used. Use noteIdToTitle instead delete note.note_title; // this should not be used. Use noteIdToTitle instead
const key = note.note_pid + "-" + note.note_id; setParentChildRelation(note.note_tree_id, note.note_pid, note.note_id);
parentChildToNoteTreeId[key] = note.note_tree_id;
if (!parentToChildren[note.note_pid]) {
parentToChildren[note.note_pid] = [];
}
parentToChildren[note.note_pid].push(note.note_id);
if (!childToParents[note.note_id]) {
childToParents[note.note_id] = [];
}
childToParents[note.note_id].push(note.note_pid);
} }
return prepareNoteTreeInner('root'); return prepareNoteTreeInner('root');
@ -189,6 +193,8 @@ const noteTree = (function() {
let parentNoteId = 'root'; let parentNoteId = 'root';
console.log("Run path: ", runPath);
for (const childNoteId of runPath) { for (const childNoteId of runPath) {
const node = getNodesByNoteId(childNoteId).find(node => node.data.note_pid === parentNoteId); const node = getNodesByNoteId(childNoteId).find(node => node.data.note_pid === parentNoteId);
@ -606,9 +612,7 @@ const noteTree = (function() {
extraClasses: isProtected ? "protected" : "" extraClasses: isProtected ? "protected" : ""
}; };
parentToChildren[parentNoteId].push(result.note_id); setParentChildRelation(result.note_tree_id, parentNoteId, result.note_id);
parentToChildren[result.note_id] = [];
childToParents[result.note_id] = [ parentNoteId ];
noteIdToTitle[result.note_id] = newNoteName; noteIdToTitle[result.note_id] = newNoteName;