trilium/public/javascripts/tree_utils.js

61 lines
1.2 KiB
JavaScript
Raw Normal View History

"use strict";
2017-11-05 07:28:49 +08:00
const treeEl = $("#tree");
function getParentKey(node) {
return (node.getParent() === null || node.getParent().key === "root_1") ? "root" : node.getParent().key;
}
function getParentEncryption(node) {
return node.getParent() === null ? 0 : node.getParent().data.encryption;
}
function getNodeByKey(noteId) {
2017-11-05 07:28:49 +08:00
return treeEl.fancytree('getNodeByKey', noteId);
}
function getNoteTitle(noteId) {
const note = getNodeByKey(noteId);
if (!note) {
return;
}
let noteTitle = note.title;
if (noteTitle.endsWith(" (clone)")) {
noteTitle = noteTitle.substr(0, noteTitle.length - 8);
}
return noteTitle;
}
function getFullName(noteId) {
let note = getNodeByKey(noteId);
if (note === null) {
return "[unknown]";
}
// why?
if (note.data.is_clone) {
return null;
}
const path = [];
while (note) {
2017-11-05 06:18:55 +08:00
if (note.data.encryption > 0 && !encryption.isEncryptionAvailable()) {
path.push("[encrypted]");
}
else {
path.push(note.title);
}
note = note.getParent();
}
// remove "root" element
path.pop();
return path.reverse().join(" > ");
}