Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
cleanup in tree service
azivner91ee90d827b9
diff --git a/src/public/javascripts/dialogs/edit_tree_prefix.js b/src/public/javascripts/dialogs/edit_tree_prefix.jsindex 63629d758a..41a6078046 100644--- a/src/public/javascripts/dialogs/edit_tree_prefix.js+++ b/src/public/javascripts/dialogs/edit_tree_prefix.js@@ -1,5 +1,6 @@import treeService from '../services/tree.js';import server from '../services/server.js';+import treeCache from "../services/tree_cache.js";const $dialog = $("#edit-tree-prefix-dialog");const $form = $("#edit-tree-prefix-form");@@ -19,7 +20,7 @@ async function showDialog() {const currentNode = treeService.getCurrentNode();branchId = currentNode.data.branchId;- const branch = await treeService.getBranch(branchId);+ const branch = await treeCache.getBranch(branchId);$treePrefixInput.val(branch.prefix).focus();diff --git a/src/public/javascripts/services/bootstrap.js b/src/public/javascripts/services/bootstrap.jsindex 69d9c0ca04..a31c0b8462 100644--- a/src/public/javascripts/services/bootstrap.js+++ b/src/public/javascripts/services/bootstrap.js@@ -61,4 +61,9 @@ utils.bindShortcut('alt+l', labelsDialog.showDialog);$("#settings-button").click(settingsDialog.showDialog);-utils.bindShortcut('alt+o', sqlConsoleDialog.showDialog);\ No newline at end of file+utils.bindShortcut('alt+o', sqlConsoleDialog.showDialog);++if (utils.isElectron()) {+ utils.bindShortcut('alt+left', window.history.back);+ utils.bindShortcut('alt+right', window.history.forward);+}\ No newline at end of filediff --git a/src/public/javascripts/services/context_menu.js b/src/public/javascripts/services/context_menu.jsindex a5d96b70d3..f15acd69e7 100644--- a/src/public/javascripts/services/context_menu.js+++ b/src/public/javascripts/services/context_menu.js@@ -8,6 +8,7 @@ import treeUtils from './tree_utils.js';import utils from './utils.js';import editTreePrefixDialog from '../dialogs/edit_tree_prefix.js';import infoService from "./info.js";+import treeCache from "./tree_cache.js";const $tree = $("#tree");@@ -103,9 +104,9 @@ const contextMenuSettings = {],beforeOpen: async (event, ui) => {const node = $.ui.fancytree.getNode(ui.target);- const branch = await treeService.getBranch(node.data.branchId);- const note = await treeService.getNote(node.data.noteId);- const parentNote = await treeService.getNote(branch.parentNoteId);+ const branch = await treeCache.getBranch(branchId);+ const note = await treeCache.getNote(node.data.noteId);+ const parentNote = await treeCache.getNote(branch.parentNoteId);// Modify menu entries depending on node status$tree.contextmenu("enableEntry", "pasteAfter", clipboardIds.length > 0 && (!parentNote || parentNote.type !== 'search'));diff --git a/src/public/javascripts/services/info.js b/src/public/javascripts/services/info.jsindex b20f6262dc..48ab4eae4d 100644--- a/src/public/javascripts/services/info.js+++ b/src/public/javascripts/services/info.js@@ -1,7 +1,8 @@import messagingService from "./messaging.js";+import utils from "./utils.js";function showMessage(message) {- console.log(now(), "message: ", message);+ console.log(utils.now(), "message: ", message);$.notify({// options@@ -14,7 +15,7 @@ function showMessage(message) {}function showError(message, delay = 10000) {- console.log(now(), "error: ", message);+ console.log(utils.now(), "error: ", message);$.notify({// optionsdiff --git a/src/public/javascripts/services/init.js b/src/public/javascripts/services/init.jsindex 67002d9962..54e9dd5fd5 100644--- a/src/public/javascripts/services/init.js+++ b/src/public/javascripts/services/init.js@@ -6,6 +6,7 @@ import treeUtils from './tree_utils.js';import utils from './utils.js';import server from './server.js';import bundleService from './bundle.js';+import treeCache from "./tree_cache.js";// hot keys are active also inside inputs and content editablesjQuery.hotkeys.options.filterInputAcceptingElements = false;@@ -218,7 +219,7 @@ $(document).ready(() => {if (utils.isElectron()) {require('electron').ipcRenderer.on('create-day-sub-note', async function(event, parentNoteId) {// this might occur when day note had to be created- if (!await treeService.noteExists(parentNoteId)) {+ if (!await treeCache.getNote(parentNoteId)) {await treeService.reload();}diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.jsindex c6dfaef2a5..93a7720310 100644--- a/src/public/javascripts/services/tree.js+++ b/src/public/javascripts/services/tree.js@@ -24,16 +24,6 @@ let instanceName = null; // should have better placelet startNotePath = null;-async function getNote(noteId) {- const note = await treeCache.getNote(noteId);-- if (!note) {- infoService.throwError(`Can't find title for noteId='${noteId}'`);- }-- return note;-}-async function getNoteTitle(noteId, parentNoteId = null) {utils.assertArguments(noteId);@@ -403,7 +393,7 @@ function clearSelectedNodes() {async function treeInitialized() {const noteId = treeUtils.getNoteIdFromNotePath(startNotePath);- if ((await treeCache.getNote(noteId)) === undefined) {+ if (!await treeCache.getNote(noteId)) {// note doesn't exist so don't try to activate itstartNotePath = null;}@@ -609,7 +599,7 @@ function initFancyTree(branch) {dnd: dragAndDropSetup,lazyLoad: function(event, data) {const noteId = data.node.data.noteId;- data.result = getNote(noteId).then(note => {+ data.result = treeCache.getNote(noteId).then(note => {if (note.type === 'search') {return loadSearchNote(noteId);}@@ -760,7 +750,9 @@ async function getAutocompleteItems(parentNoteId, notePath, titlePath) {async function setNoteTitle(noteId, title) {utils.assertArguments(noteId);- getNote(noteId).title = title;+ const note = await treeCache.getNote(noteId);++ note.title = title;for (const clone of getNodesByNoteId(noteId)) {await setNodeTitleWithPrefix(clone);@@ -846,18 +838,10 @@ async function sortAlphabetically(noteId) {await reload();}-async function noteExists(noteId) {- return !!(await treeCache.getNote(noteId));-}-function getInstanceName() {return instanceName;}-async function getBranch(branchId) {- return await treeCache.getBranch(branchId);-}-messagingService.subscribeToMessages(syncData => {if (syncData.some(sync => sync.entityName === 'branches')|| syncData.some(sync => sync.entityName === 'notes')) {@@ -868,33 +852,27 @@ messagingService.subscribeToMessages(syncData => {}});-$(document).bind('keydown', 'ctrl+o', e => {+utils.bindShortcut('ctrl+o', () => {const node = getCurrentNode();const parentNoteId = node.data.parentNoteId;const isProtected = treeUtils.getParentProtectedStatus(node);createNote(node, parentNoteId, 'after', isProtected);-- e.preventDefault();});-$(document).bind('keydown', 'ctrl+p', e => {+utils.bindShortcut('ctrl+p', () => {const node = getCurrentNode();createNote(node, node.data.noteId, 'into', node.data.isProtected);-- e.preventDefault();});-$(document).bind('keydown', 'ctrl+del', e => {+utils.bindShortcut('ctrl+del', () => {const node = getCurrentNode();treeChangesService.deleteNodes([node]);-- e.preventDefault();});-$(document).bind('keydown', 'ctrl+.', scrollToCurrentNote);+utils.bindShortcut('ctrl+.', scrollToCurrentNote);$(window).bind('hashchange', function() {const notePath = getNotePathFromAddress();@@ -906,20 +884,6 @@ $(window).bind('hashchange', function() {}});-if (utils.isElectron()) {- $(document).bind('keydown', 'alt+left', e => {- window.history.back();-- e.preventDefault();- });-- $(document).bind('keydown', 'alt+right', e => {- window.history.forward();-- e.preventDefault();- });-}-$createTopLevelNoteButton.click(createNewTopLevelNote);$collapseTreeButton.click(collapseTree);$scrollToCurrentNoteButton.click(scrollToCurrentNote);@@ -946,8 +910,5 @@ export default {setParentChildRelation,getSelectedNodes,sortAlphabetically,- noteExists,- getInstanceName,- getBranch,- getNote+ getInstanceName};\ No newline at end of file