2017-11-04 19:38:50 -04:00
|
|
|
"use strict";
|
|
|
|
|
2017-11-04 22:18:36 -04:00
|
|
|
const treeUtils = (function() {
|
|
|
|
const treeEl = $("#tree");
|
2017-11-04 19:28:49 -04:00
|
|
|
|
2017-11-18 17:05:50 -05:00
|
|
|
function getParentNoteTreeId(node) {
|
|
|
|
return node.note_pid;
|
2017-11-04 22:18:36 -04:00
|
|
|
}
|
2017-09-09 12:06:15 -04:00
|
|
|
|
2017-11-14 23:01:23 -05:00
|
|
|
function getParentProtectedStatus(node) {
|
2017-11-14 21:54:12 -05:00
|
|
|
return node.getParent() === null ? 0 : node.getParent().data.is_protected;
|
2017-11-04 22:18:36 -04:00
|
|
|
}
|
2017-09-09 12:06:15 -04:00
|
|
|
|
2017-11-18 17:05:50 -05:00
|
|
|
function getNodeByKey(key) {
|
|
|
|
return treeEl.fancytree('getNodeByKey', key);
|
2017-10-01 23:07:32 -04:00
|
|
|
}
|
|
|
|
|
2017-11-18 17:05:50 -05:00
|
|
|
function getNodeByNoteTreeId(noteTreeId) {
|
|
|
|
const key = noteTree.getKeyFromNoteTreeId(noteTreeId);
|
2017-10-01 23:07:32 -04:00
|
|
|
|
2017-11-18 17:05:50 -05:00
|
|
|
return getNodeByKey(key);
|
|
|
|
}
|
|
|
|
|
2017-11-19 12:06:48 -05:00
|
|
|
function getNoteIdFromNotePath(notePath) {
|
|
|
|
const path = notePath.split("/");
|
2017-10-01 23:07:32 -04:00
|
|
|
|
2017-11-19 12:06:48 -05:00
|
|
|
return path[path.length - 1];
|
|
|
|
}
|
2017-09-18 20:48:02 -04:00
|
|
|
|
2017-11-19 12:06:48 -05:00
|
|
|
function getFullNameForPath(notePath) {
|
|
|
|
const path = notePath.split("/");
|
|
|
|
const titlePath = path.map(noteId => noteTree.getNoteTitle(noteId));
|
2017-10-11 19:41:45 -04:00
|
|
|
|
2017-11-19 12:06:48 -05:00
|
|
|
return titlePath.join(" > ");
|
2017-09-18 20:48:02 -04:00
|
|
|
}
|
|
|
|
|
2017-11-18 17:05:50 -05:00
|
|
|
function getFullName(noteTreeId) {
|
|
|
|
let note = noteTree.getByNoteId(noteTreeId);
|
2017-09-09 12:06:15 -04:00
|
|
|
|
2017-11-04 22:18:36 -04:00
|
|
|
if (note === null) {
|
|
|
|
return "[unknown]";
|
2017-11-04 11:32:05 -04:00
|
|
|
}
|
2017-11-04 22:18:36 -04:00
|
|
|
|
|
|
|
const path = [];
|
|
|
|
|
|
|
|
while (note) {
|
2017-11-17 22:37:11 -05:00
|
|
|
path.push(note.note_title);
|
2017-11-04 22:18:36 -04:00
|
|
|
|
2017-11-17 22:37:11 -05:00
|
|
|
note = noteTree.getByNoteId(note.note_pid);
|
2017-11-04 22:18:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return path.reverse().join(" > ");
|
|
|
|
}
|
2017-09-09 12:06:15 -04:00
|
|
|
|
2017-11-19 08:47:22 -05:00
|
|
|
function getNotePath(node) {
|
|
|
|
const path = [];
|
|
|
|
|
|
|
|
while (node) {
|
2017-11-19 11:28:46 -05:00
|
|
|
if (node.data.note_id) {
|
|
|
|
path.push(node.data.note_id);
|
2017-11-19 08:47:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
node = node.getParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return path.reverse().join("/");
|
|
|
|
}
|
|
|
|
|
2017-11-04 22:18:36 -04:00
|
|
|
return {
|
2017-11-18 17:05:50 -05:00
|
|
|
getParentNoteTreeId,
|
2017-11-14 23:01:23 -05:00
|
|
|
getParentProtectedStatus,
|
2017-11-04 22:18:36 -04:00
|
|
|
getNodeByKey,
|
2017-11-18 17:05:50 -05:00
|
|
|
getNodeByNoteTreeId,
|
2017-11-19 08:47:22 -05:00
|
|
|
getFullName,
|
2017-11-19 12:06:48 -05:00
|
|
|
getFullNameForPath,
|
|
|
|
getNotePath,
|
|
|
|
getNoteIdFromNotePath
|
2017-11-04 22:18:36 -04:00
|
|
|
};
|
|
|
|
})();
|