mirror of
https://github.com/zadam/trilium.git
synced 2025-10-29 09:16:45 +01:00
tree utils as a module
This commit is contained in:
@@ -1,61 +1,78 @@
|
||||
"use strict";
|
||||
|
||||
const treeEl = $("#tree");
|
||||
const treeUtils = (function() {
|
||||
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) {
|
||||
return treeEl.fancytree('getNodeByKey', noteId);
|
||||
}
|
||||
|
||||
function getNoteTitle(noteId) {
|
||||
const note = getNodeByKey(noteId);
|
||||
if (!note) {
|
||||
return;
|
||||
function getParentKey(node) {
|
||||
return (node.getParent() === null || node.getParent().key === "root_1") ? "root" : node.getParent().key;
|
||||
}
|
||||
|
||||
let noteTitle = note.title;
|
||||
|
||||
if (noteTitle.endsWith(" (clone)")) {
|
||||
noteTitle = noteTitle.substr(0, noteTitle.length - 8);
|
||||
function getParentEncryption(node) {
|
||||
return node.getParent() === null ? 0 : node.getParent().data.encryption;
|
||||
}
|
||||
|
||||
return noteTitle;
|
||||
}
|
||||
|
||||
function getFullName(noteId) {
|
||||
let note = getNodeByKey(noteId);
|
||||
|
||||
if (note === null) {
|
||||
return "[unknown]";
|
||||
function getNodeByKey(noteId) {
|
||||
return treeEl.fancytree('getNodeByKey', noteId);
|
||||
}
|
||||
|
||||
// why?
|
||||
if (note.data.is_clone) {
|
||||
return null;
|
||||
function activateNode(noteId) {
|
||||
const node = treeUtils.getNodeByKey(noteId);
|
||||
|
||||
node.setActive();
|
||||
}
|
||||
|
||||
const path = [];
|
||||
|
||||
while (note) {
|
||||
if (note.data.encryption > 0 && !encryption.isEncryptionAvailable()) {
|
||||
path.push("[encrypted]");
|
||||
}
|
||||
else {
|
||||
path.push(note.title);
|
||||
function getNoteTitle(noteId) {
|
||||
const note = treeUtils.getNodeByKey(noteId);
|
||||
if (!note) {
|
||||
return;
|
||||
}
|
||||
|
||||
note = note.getParent();
|
||||
let noteTitle = note.title;
|
||||
|
||||
if (noteTitle.endsWith(" (clone)")) {
|
||||
noteTitle = noteTitle.substr(0, noteTitle.length - 8);
|
||||
}
|
||||
|
||||
return noteTitle;
|
||||
}
|
||||
|
||||
// remove "root" element
|
||||
path.pop();
|
||||
function getFullName(noteId) {
|
||||
let note = treeUtils.getNodeByKey(noteId);
|
||||
|
||||
return path.reverse().join(" > ");
|
||||
}
|
||||
if (note === null) {
|
||||
return "[unknown]";
|
||||
}
|
||||
|
||||
// why?
|
||||
if (note.data.is_clone) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const path = [];
|
||||
|
||||
while (note) {
|
||||
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(" > ");
|
||||
}
|
||||
|
||||
return {
|
||||
getParentKey,
|
||||
getParentEncryption,
|
||||
getNodeByKey,
|
||||
activateNode,
|
||||
getNoteTitle,
|
||||
getFullName
|
||||
};
|
||||
})();
|
||||
Reference in New Issue
Block a user