mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	delete notes are now in cache as well which allows simplified update of the tree after deletion
This commit is contained in:
		
							
								
								
									
										4
									
								
								libraries/autocomplete.jquery.min.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								libraries/autocomplete.jquery.min.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@@ -32,6 +32,8 @@ class NoteShort {
 | 
				
			|||||||
        /** @param {string} content-type, e.g. "application/json" */
 | 
					        /** @param {string} content-type, e.g. "application/json" */
 | 
				
			||||||
        this.mime = row.mime;
 | 
					        this.mime = row.mime;
 | 
				
			||||||
        /** @param {boolean} */
 | 
					        /** @param {boolean} */
 | 
				
			||||||
 | 
					        this.isDeleted = row.isDeleted;
 | 
				
			||||||
 | 
					        /** @param {boolean} */
 | 
				
			||||||
        this.archived = row.archived;
 | 
					        this.archived = row.archived;
 | 
				
			||||||
        /** @param {string} */
 | 
					        /** @param {string} */
 | 
				
			||||||
        this.cssClass = row.cssClass;
 | 
					        this.cssClass = row.cssClass;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -80,6 +80,22 @@ async function moveToNode(nodesToMove, toNode) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async function getNextNode(nodes) {
 | 
				
			||||||
 | 
					    // following code assumes that nodes contain only top-most selected nodes - getSelectedNodes has been
 | 
				
			||||||
 | 
					    // called with stopOnParent=true
 | 
				
			||||||
 | 
					    let next = nodes[nodes.length - 1].getNextSibling();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!next) {
 | 
				
			||||||
 | 
					        next = nodes[0].getPrevSibling();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!next && !await hoistedNoteService.isRootNode(nodes[0])) {
 | 
				
			||||||
 | 
					        next = nodes[0].getParent();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return treeUtils.getNotePath(next);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function deleteNodes(nodes) {
 | 
					async function deleteNodes(nodes) {
 | 
				
			||||||
    nodes = await filterRootNote(nodes);
 | 
					    nodes = await filterRootNote(nodes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -130,47 +146,11 @@ async function deleteNodes(nodes) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (deleteClones) {
 | 
					    const nextNotePath = await getNextNode(nodes);
 | 
				
			||||||
        // if clones are also deleted we give up with targeted cleanup of the tree
 | 
					 | 
				
			||||||
        treeService.reload();
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // following code assumes that nodes contain only top-most selected nodes - getSelectedNodes has been
 | 
					    const noteIds = Array.from(new Set(nodes.map(node => node.data.noteId)));
 | 
				
			||||||
    // called with stopOnParent=true
 | 
					 | 
				
			||||||
    let next = nodes[nodes.length - 1].getNextSibling();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!next) {
 | 
					    await treeService.reloadNotes(noteIds, nextNotePath);
 | 
				
			||||||
        next = nodes[0].getPrevSibling();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (!next && !await hoistedNoteService.isRootNode(nodes[0])) {
 | 
					 | 
				
			||||||
        next = nodes[0].getParent();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let activeNotePath = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (next) {
 | 
					 | 
				
			||||||
        activeNotePath = await treeUtils.getNotePath(next);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await treeService.loadTreeCache();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const parentNoteIds = Array.from(new Set(nodes.map(node => node.getParent().data.noteId)));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for (const node of nodes) {
 | 
					 | 
				
			||||||
        node.remove();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await treeService.reloadNotes(parentNoteIds);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // activate after all the reloading
 | 
					 | 
				
			||||||
    if (activeNotePath) {
 | 
					 | 
				
			||||||
        treeService.focusTree();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const node = await treeService.activateNote(activeNotePath);
 | 
					 | 
				
			||||||
        node.setFocus(true);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -559,14 +559,10 @@ function getHashValueFromAddress() {
 | 
				
			|||||||
    return str.split("-");
 | 
					    return str.split("-");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function loadTreeCache() {
 | 
					async function loadTree() {
 | 
				
			||||||
    const resp = await server.get('tree');
 | 
					    const resp = await server.get('tree');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    treeCache.load(resp.notes, resp.branches);
 | 
					    treeCache.load(resp.notes, resp.branches);
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
async function loadTree() {
 | 
					 | 
				
			||||||
    await loadTreeCache();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return await treeBuilder.prepareTree();
 | 
					    return await treeBuilder.prepareTree();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -828,25 +824,34 @@ async function checkFolderStatus(node) {
 | 
				
			|||||||
    node.renderTitle();
 | 
					    node.renderTitle();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function reloadNotes(noteIds) {
 | 
					async function reloadNotes(noteIds, activateNotePath = null) {
 | 
				
			||||||
    if (noteIds.length === 0) {
 | 
					    if (noteIds.length === 0) {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await treeCache.reloadNotes(noteIds);
 | 
					    await treeCache.reloadNotes(noteIds);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const activeNotePath = noteDetailService.getActiveTabNotePath();
 | 
					    if (!activateNotePath) {
 | 
				
			||||||
 | 
					        activateNotePath = noteDetailService.getActiveTabNotePath();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (const noteId of noteIds) {
 | 
					    for (const noteId of noteIds) {
 | 
				
			||||||
        for (const node of getNodesByNoteId(noteId)) {
 | 
					        for (const node of getNodesByNoteId(noteId)) {
 | 
				
			||||||
 | 
					            const branch = treeCache.getBranch(node.data.branchId, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (!branch) {
 | 
				
			||||||
 | 
					                node.remove();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else {
 | 
				
			||||||
                await node.load(true);
 | 
					                await node.load(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                await checkFolderStatus(node);
 | 
					                await checkFolderStatus(node);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (activeNotePath) {
 | 
					    if (activateNotePath) {
 | 
				
			||||||
        const node = await getNodeFromPath(activeNotePath);
 | 
					        const node = await getNodeFromPath(activateNotePath);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (node) {
 | 
					        if (node) {
 | 
				
			||||||
            await node.setActive(true, {noEvents: true}); // this node has been already active so no need to fire events again
 | 
					            await node.setActive(true, {noEvents: true}); // this node has been already active so no need to fire events again
 | 
				
			||||||
@@ -926,7 +931,6 @@ export default {
 | 
				
			|||||||
    getNodesByNoteId,
 | 
					    getNodesByNoteId,
 | 
				
			||||||
    checkFolderStatus,
 | 
					    checkFolderStatus,
 | 
				
			||||||
    reloadNotes,
 | 
					    reloadNotes,
 | 
				
			||||||
    loadTreeCache,
 | 
					 | 
				
			||||||
    expandToNote,
 | 
					    expandToNote,
 | 
				
			||||||
    getNodeFromPath,
 | 
					    getNodeFromPath,
 | 
				
			||||||
    resolveNotePath,
 | 
					    resolveNotePath,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -77,11 +77,11 @@ class TreeCache {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for (const branch of branchesByNotes[noteId]) {
 | 
					            for (const branch of branchesByNotes[noteId] || []) { // can be empty for deleted notes
 | 
				
			||||||
                this.addBranch(branch);
 | 
					                this.addBranch(branch);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const note = new NoteShort(this, noteRow, branchesByNotes[noteId]);
 | 
					            const note = new NoteShort(this, noteRow, branchesByNotes[noteId] || []);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            this.notes[note.noteId] = note;
 | 
					            this.notes[note.noteId] = note;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -158,10 +158,12 @@ class TreeCache {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** @return {Branch} */
 | 
					    /** @return {Branch} */
 | 
				
			||||||
    getBranch(branchId) {
 | 
					    getBranch(branchId, silentNotFoundError = false) {
 | 
				
			||||||
        if (!(branchId in this.branches)) {
 | 
					        if (!(branchId in this.branches)) {
 | 
				
			||||||
 | 
					            if (!silentNotFoundError) {
 | 
				
			||||||
                console.error(`Not existing branch ${branchId}`);
 | 
					                console.error(`Not existing branch ${branchId}`);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        else {
 | 
					        else {
 | 
				
			||||||
            return this.branches[branchId];
 | 
					            return this.branches[branchId];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,17 +6,17 @@ const protectedSessionService = require('../../services/protected_session');
 | 
				
			|||||||
const noteCacheService = require('../../services/note_cache');
 | 
					const noteCacheService = require('../../services/note_cache');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getNotes(noteIds) {
 | 
					async function getNotes(noteIds) {
 | 
				
			||||||
 | 
					    // we return also deleted notes which have been specifically asked for
 | 
				
			||||||
    const notes = await sql.getManyRows(`
 | 
					    const notes = await sql.getManyRows(`
 | 
				
			||||||
      SELECT 
 | 
					      SELECT 
 | 
				
			||||||
             noteId, 
 | 
					             noteId, 
 | 
				
			||||||
             title, 
 | 
					             title, 
 | 
				
			||||||
             isProtected, 
 | 
					             isProtected, 
 | 
				
			||||||
             type, 
 | 
					             type, 
 | 
				
			||||||
             mime
 | 
					             mime,
 | 
				
			||||||
      FROM 
 | 
					             isDeleted
 | 
				
			||||||
           notes 
 | 
					      FROM notes 
 | 
				
			||||||
      WHERE isDeleted = 0 
 | 
					      WHERE noteId IN (???)`, noteIds);
 | 
				
			||||||
        AND noteId IN (???)`, noteIds);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const cssClassLabels = await sql.getManyRows(`
 | 
					    const cssClassLabels = await sql.getManyRows(`
 | 
				
			||||||
      SELECT noteId, value FROM attributes WHERE isDeleted = 0 AND type = 'label' 
 | 
					      SELECT noteId, value FROM attributes WHERE isDeleted = 0 AND type = 'label' 
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user