|
|
|
@ -5,7 +5,6 @@ const noteTree = (function() {
|
|
|
|
const parentListEl = $("#parent-list");
|
|
|
|
const parentListEl = $("#parent-list");
|
|
|
|
|
|
|
|
|
|
|
|
let startNoteTreeId = null;
|
|
|
|
let startNoteTreeId = null;
|
|
|
|
let treeLoadTime = null;
|
|
|
|
|
|
|
|
let notesTreeMap = {};
|
|
|
|
let notesTreeMap = {};
|
|
|
|
|
|
|
|
|
|
|
|
let parentToChildren = {};
|
|
|
|
let parentToChildren = {};
|
|
|
|
@ -14,32 +13,33 @@ const noteTree = (function() {
|
|
|
|
let parentChildToNoteTreeId = {};
|
|
|
|
let parentChildToNoteTreeId = {};
|
|
|
|
let noteIdToTitle = {};
|
|
|
|
let noteIdToTitle = {};
|
|
|
|
|
|
|
|
|
|
|
|
function getTreeLoadTime() {
|
|
|
|
|
|
|
|
return treeLoadTime;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getNoteTreeId(parentNoteId, childNoteId) {
|
|
|
|
function getNoteTreeId(parentNoteId, childNoteId) {
|
|
|
|
const key = parentNoteId + "-" + childNoteId;
|
|
|
|
const key = parentNoteId + "-" + childNoteId;
|
|
|
|
|
|
|
|
|
|
|
|
const noteTreeId = parentChildToNoteTreeId[key];
|
|
|
|
// this can return undefined and client code should deal with it somehow
|
|
|
|
|
|
|
|
|
|
|
|
if (!noteTreeId) {
|
|
|
|
|
|
|
|
console.trace();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
throw new Error("Can't find note tree id for parent=" + parentNoteId + ", child=" + childNoteId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return noteTreeId;
|
|
|
|
return parentChildToNoteTreeId[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getNoteTitle(notePath) {
|
|
|
|
function getNoteTitle(noteId, parentNoteId = null) {
|
|
|
|
const noteId = treeUtils.getNoteIdFromNotePath(notePath);
|
|
|
|
let title = noteIdToTitle[noteId];
|
|
|
|
const title = noteIdToTitle[noteId];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!title) {
|
|
|
|
if (!title) {
|
|
|
|
throw new Error("Can't find title for noteId='" + noteId + "'");
|
|
|
|
throw new Error("Can't find title for noteId='" + noteId + "'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (parentNoteId !== null) {
|
|
|
|
|
|
|
|
const noteTreeId = getNoteTreeId(parentNoteId, noteId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (noteTreeId) {
|
|
|
|
|
|
|
|
const noteTree = notesTreeMap[noteTreeId];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (noteTree.prefix) {
|
|
|
|
|
|
|
|
title = noteTree.prefix + ' - ' + title;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return title;
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -286,8 +286,12 @@ const noteTree = (function() {
|
|
|
|
function getNotePathTitle(notePath) {
|
|
|
|
function getNotePathTitle(notePath) {
|
|
|
|
const titlePath = [];
|
|
|
|
const titlePath = [];
|
|
|
|
|
|
|
|
|
|
|
|
for (const path of notePath.split('/')) {
|
|
|
|
let parentNoteId = 'root';
|
|
|
|
titlePath.push(getNoteTitle(path));
|
|
|
|
|
|
|
|
|
|
|
|
for (const noteId of notePath.split('/')) {
|
|
|
|
|
|
|
|
titlePath.push(getNoteTitle(noteId, parentNoteId));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parentNoteId = noteId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return titlePath.join(' / ');
|
|
|
|
return titlePath.join(' / ');
|
|
|
|
@ -476,7 +480,6 @@ const noteTree = (function() {
|
|
|
|
function loadTree() {
|
|
|
|
function loadTree() {
|
|
|
|
return server.get('tree').then(resp => {
|
|
|
|
return server.get('tree').then(resp => {
|
|
|
|
startNoteTreeId = resp.start_note_tree_id;
|
|
|
|
startNoteTreeId = resp.start_note_tree_id;
|
|
|
|
treeLoadTime = resp.tree_load_time;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (document.location.hash) {
|
|
|
|
if (document.location.hash) {
|
|
|
|
startNoteTreeId = document.location.hash.substr(1); // strip initial #
|
|
|
|
startNoteTreeId = document.location.hash.substr(1); // strip initial #
|
|
|
|
@ -531,7 +534,7 @@ const noteTree = (function() {
|
|
|
|
|
|
|
|
|
|
|
|
for (const childNoteId of parentToChildren[parentNoteId]) {
|
|
|
|
for (const childNoteId of parentToChildren[parentNoteId]) {
|
|
|
|
const childNotePath = (notePath ? (notePath + '/') : '') + childNoteId;
|
|
|
|
const childNotePath = (notePath ? (notePath + '/') : '') + childNoteId;
|
|
|
|
const childTitlePath = (titlePath ? (titlePath + ' / ') : '') + getNoteTitle(childNoteId);
|
|
|
|
const childTitlePath = (titlePath ? (titlePath + ' / ') : '') + getNoteTitle(childNoteId, parentNoteId);
|
|
|
|
|
|
|
|
|
|
|
|
autocompleteItems.push({
|
|
|
|
autocompleteItems.push({
|
|
|
|
value: childTitlePath + ' (' + childNotePath + ')',
|
|
|
|
value: childTitlePath + ' (' + childNotePath + ')',
|
|
|
|
@ -608,7 +611,6 @@ const noteTree = (function() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
getTreeLoadTime,
|
|
|
|
|
|
|
|
reload,
|
|
|
|
reload,
|
|
|
|
collapseTree,
|
|
|
|
collapseTree,
|
|
|
|
scrollToCurrentNote,
|
|
|
|
scrollToCurrentNote,
|
|
|
|
@ -623,6 +625,6 @@ const noteTree = (function() {
|
|
|
|
createNewTopLevelNote,
|
|
|
|
createNewTopLevelNote,
|
|
|
|
createNote,
|
|
|
|
createNote,
|
|
|
|
setPrefix,
|
|
|
|
setPrefix,
|
|
|
|
getNodesByNoteTreeId
|
|
|
|
getNotePathTitle
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
})();
|