trilium/public/javascripts/tree_utils.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

"use strict";
2017-11-05 10:18:36 +08:00
const treeUtils = (function() {
const treeEl = $("#tree");
2017-11-05 07:28:49 +08:00
2017-11-15 12:01:23 +08:00
function getParentProtectedStatus(node) {
return node.getParent() === null ? 0 : node.getParent().data.is_protected;
2017-11-05 10:18:36 +08:00
}
function getNodeByKey(key) {
return treeEl.fancytree('getNodeByKey', key);
}
2017-11-20 01:06:48 +08:00
function getNoteIdFromNotePath(notePath) {
const path = notePath.split("/");
2017-11-20 01:06:48 +08:00
return path[path.length - 1];
}
2017-11-20 01:06:48 +08:00
function getFullNameForPath(notePath) {
const path = notePath.split("/");
const titlePath = path.map(noteId => noteTree.getNoteTitle(noteId));
2017-11-20 01:06:48 +08:00
return titlePath.join(" > ");
}
2017-11-19 21:47:22 +08:00
function getNotePath(node) {
const path = [];
while (node) {
if (node.data.note_id) {
path.push(node.data.note_id);
2017-11-19 21:47:22 +08:00
}
node = node.getParent();
}
return path.reverse().join("/");
}
2017-11-05 10:18:36 +08:00
return {
2017-11-15 12:01:23 +08:00
getParentProtectedStatus,
2017-11-05 10:18:36 +08:00
getNodeByKey,
2017-11-20 01:06:48 +08:00
getFullNameForPath,
getNotePath,
getNoteIdFromNotePath
2017-11-05 10:18:36 +08:00
};
})();