mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 21:19:01 +01:00 
			
		
		
		
	cleanup in tree service
This commit is contained in:
		
							parent
							
								
									d3316cd09c
								
							
						
					
					
						commit
						91ee90d827
					
				@ -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();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										7
									
								
								src/public/javascripts/services/bootstrap.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										7
									
								
								src/public/javascripts/services/bootstrap.js
									
									
									
									
										vendored
									
									
								
							@ -61,4 +61,9 @@ utils.bindShortcut('alt+l', labelsDialog.showDialog);
 | 
			
		||||
 | 
			
		||||
$("#settings-button").click(settingsDialog.showDialog);
 | 
			
		||||
 | 
			
		||||
utils.bindShortcut('alt+o', sqlConsoleDialog.showDialog);
 | 
			
		||||
utils.bindShortcut('alt+o', sqlConsoleDialog.showDialog);
 | 
			
		||||
 | 
			
		||||
if (utils.isElectron()) {
 | 
			
		||||
    utils.bindShortcut('alt+left', window.history.back);
 | 
			
		||||
    utils.bindShortcut('alt+right', window.history.forward);
 | 
			
		||||
}
 | 
			
		||||
@ -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'));
 | 
			
		||||
 | 
			
		||||
@ -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({
 | 
			
		||||
        // options
 | 
			
		||||
 | 
			
		||||
@ -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 editables
 | 
			
		||||
jQuery.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();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -24,16 +24,6 @@ let instanceName = null; // should have better place
 | 
			
		||||
 | 
			
		||||
let 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 it
 | 
			
		||||
        startNotePath = 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
 | 
			
		||||
};
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user