mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
tree utils as a module
This commit is contained in:
parent
900f169dab
commit
30df3cba1c
@ -4,7 +4,7 @@ const contextMenu = (function() {
|
||||
const treeEl = $("#tree");
|
||||
|
||||
function pasteAfter(node) {
|
||||
const subjectNode = getNodeByKey(noteTree.getClipboardNoteId());
|
||||
const subjectNode = treeUtils.getNodeByKey(noteTree.getClipboardNoteId());
|
||||
|
||||
treeChanges.moveAfterNode(subjectNode, node);
|
||||
|
||||
@ -12,7 +12,7 @@ const contextMenu = (function() {
|
||||
}
|
||||
|
||||
function pasteInto(node) {
|
||||
const subjectNode = getNodeByKey(noteTree.getClipboardNoteId());
|
||||
const subjectNode = treeUtils.getNodeByKey(noteTree.getClipboardNoteId());
|
||||
|
||||
treeChanges.moveToNode(subjectNode, node);
|
||||
|
||||
@ -56,8 +56,8 @@ const contextMenu = (function() {
|
||||
const node = $.ui.fancytree.getNode(ui.target);
|
||||
|
||||
if (ui.cmd === "insertNoteHere") {
|
||||
const parentKey = getParentKey(node);
|
||||
const encryption = getParentEncryption(node);
|
||||
const parentKey = treeUtils.getParentKey(node);
|
||||
const encryption = treeUtils.getParentEncryption(node);
|
||||
|
||||
noteEditor.createNote(node, parentKey, 'after', encryption);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ const addLink = (function() {
|
||||
linkTitleEl.val('');
|
||||
|
||||
function setDefaultLinkTitle(noteId) {
|
||||
const noteTitle = getNoteTitle(noteId);
|
||||
const noteTitle = treeUtils.getNoteTitle(noteId);
|
||||
|
||||
linkTitleEl.val(noteTitle);
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ const jumpToNote = (function() {
|
||||
const noteId = link.getNodeIdFromLabel(val);
|
||||
|
||||
if (noteId) {
|
||||
getNodeByKey(noteId).setActive();
|
||||
treeUtils.activateNode(noteId);
|
||||
|
||||
dialogEl.dialog('close');
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ const recentNotes = (function() {
|
||||
const recNotes = list.filter(note => note !== noteEditor.getCurrentNoteId());
|
||||
|
||||
$.each(recNotes, (key, valueNoteId) => {
|
||||
const noteTitle = getFullName(valueNoteId);
|
||||
const noteTitle = treeUtils.getFullName(valueNoteId);
|
||||
|
||||
if (!noteTitle) {
|
||||
return;
|
||||
@ -66,7 +66,7 @@ const recentNotes = (function() {
|
||||
function setActiveNoteBasedOnRecentNotes() {
|
||||
const noteId = getSelectedNoteIdFromRecentNotes();
|
||||
|
||||
getNodeByKey(noteId).setActive();
|
||||
treeUtils.activateNode(noteId);
|
||||
|
||||
dialogEl.dialog('close');
|
||||
}
|
||||
@ -74,7 +74,7 @@ const recentNotes = (function() {
|
||||
function addLinkBasedOnRecentNotes() {
|
||||
const noteId = getSelectedNoteIdFromRecentNotes();
|
||||
|
||||
const linkTitle = getNoteTitle(noteId);
|
||||
const linkTitle = treeUtils.getNoteTitle(noteId);
|
||||
|
||||
dialogEl.dialog("close");
|
||||
|
||||
|
@ -42,7 +42,7 @@ const encryption = (function() {
|
||||
open: () => {
|
||||
if (!modal) {
|
||||
// dialog steals focus for itself, which is not what we want for non-modal (viewing)
|
||||
getNodeByKey(noteEditor.getCurrentNoteId()).setFocus();
|
||||
treeUtils.getNodeByKey(noteEditor.getCurrentNoteId()).setFocus();
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -105,7 +105,7 @@ const encryption = (function() {
|
||||
}
|
||||
|
||||
for (const noteId of glob.allNoteIds) {
|
||||
const note = getNodeByKey(noteId);
|
||||
const note = treeUtils.getNodeByKey(noteId);
|
||||
|
||||
if (note.data.encryption > 0) {
|
||||
const title = decryptString(note.data.note_title);
|
||||
@ -375,7 +375,7 @@ const encryption = (function() {
|
||||
function updateSubTreeRecursively(noteId, updateCallback, successCallback) {
|
||||
updateNoteSynchronously(noteId, updateCallback, successCallback);
|
||||
|
||||
const node = getNodeByKey(noteId);
|
||||
const node = treeUtils.getNodeByKey(noteId);
|
||||
if (!node || !node.getChildren()) {
|
||||
return;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ const link = (function() {
|
||||
function createNoteLink(noteId) {
|
||||
const noteLink = $("<a>", {
|
||||
href: 'javascript:',
|
||||
text: getFullName(noteId)
|
||||
text: treeUtils.getFullName(noteId)
|
||||
}).attr('action', 'note')
|
||||
.attr('note-id', noteId);
|
||||
|
||||
@ -41,7 +41,7 @@ const link = (function() {
|
||||
}
|
||||
|
||||
if (noteId) {
|
||||
getNodeByKey(noteId).setActive();
|
||||
treeUtils.activateNode(noteId);
|
||||
|
||||
// this is quite ugly hack, but it seems like we can't close the tooltip otherwise
|
||||
$("[role='tooltip']").remove();
|
||||
|
@ -78,7 +78,7 @@ const noteEditor = (function() {
|
||||
|
||||
const title = noteTitleEl.val();
|
||||
|
||||
getNodeByKey(note.detail.note_id).setTitle(title);
|
||||
treeUtils.getNodeByKey(note.detail.note_id).setTitle(title);
|
||||
|
||||
note.detail.note_title = title;
|
||||
}
|
||||
@ -155,7 +155,7 @@ const noteEditor = (function() {
|
||||
}
|
||||
|
||||
function setTreeBasedOnEncryption(note) {
|
||||
const node = getNodeByKey(note.detail.note_id);
|
||||
const node = treeUtils.getNodeByKey(note.detail.note_id);
|
||||
node.toggleClass("encrypted", note.detail.encryption > 0);
|
||||
}
|
||||
|
||||
|
@ -58,8 +58,8 @@ const noteTree = (function() {
|
||||
function initFancyTree(notes, startNoteId) {
|
||||
const keybindings = {
|
||||
"insert": node => {
|
||||
const parentKey = getParentKey(node);
|
||||
const encryption = getParentEncryption(node);
|
||||
const parentKey = treeUtils.getParentKey(node);
|
||||
const encryption = treeUtils.getParentEncryption(node);
|
||||
|
||||
noteEditor.createNote(node, parentKey, 'after', encryption);
|
||||
},
|
||||
@ -227,7 +227,7 @@ const noteTree = (function() {
|
||||
$(document).bind('keydown', 'alt+c', collapseTree);
|
||||
|
||||
function scrollToCurrentNote() {
|
||||
const node = getNodeByKey(noteEditor.getCurrentNoteId());
|
||||
const node = treeUtils.getNodeByKey(noteEditor.getCurrentNoteId());
|
||||
|
||||
if (node) {
|
||||
node.makeVisible({scrollIntoView: true});
|
||||
|
@ -1,5 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
const treeUtils = (function() {
|
||||
const treeEl = $("#tree");
|
||||
|
||||
function getParentKey(node) {
|
||||
@ -14,8 +15,14 @@ function getNodeByKey(noteId) {
|
||||
return treeEl.fancytree('getNodeByKey', noteId);
|
||||
}
|
||||
|
||||
function activateNode(noteId) {
|
||||
const node = treeUtils.getNodeByKey(noteId);
|
||||
|
||||
node.setActive();
|
||||
}
|
||||
|
||||
function getNoteTitle(noteId) {
|
||||
const note = getNodeByKey(noteId);
|
||||
const note = treeUtils.getNodeByKey(noteId);
|
||||
if (!note) {
|
||||
return;
|
||||
}
|
||||
@ -30,7 +37,7 @@ function getNoteTitle(noteId) {
|
||||
}
|
||||
|
||||
function getFullName(noteId) {
|
||||
let note = getNodeByKey(noteId);
|
||||
let note = treeUtils.getNodeByKey(noteId);
|
||||
|
||||
if (note === null) {
|
||||
return "[unknown]";
|
||||
@ -59,3 +66,13 @@ function getFullName(noteId) {
|
||||
|
||||
return path.reverse().join(" > ");
|
||||
}
|
||||
|
||||
return {
|
||||
getParentKey,
|
||||
getParentEncryption,
|
||||
getNodeByKey,
|
||||
activateNode,
|
||||
getNoteTitle,
|
||||
getFullName
|
||||
};
|
||||
})();
|
@ -20,7 +20,7 @@ function getAutocompleteItems(noteIds) {
|
||||
const autocompleteItems = [];
|
||||
|
||||
for (const noteId of noteIds) {
|
||||
const fullName = getFullName(noteId);
|
||||
const fullName = treeUtils.getFullName(noteId);
|
||||
|
||||
if (fullName !== null) {
|
||||
autocompleteItems.push({
|
||||
|
Loading…
x
Reference in New Issue
Block a user