mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
deleting without reloading the whole tree (at least on frontend)
This commit is contained in:
parent
ca0d17d93a
commit
0267468cd5
@ -93,6 +93,8 @@ async function deleteNodes(nodes) {
|
|||||||
await server.remove('branches/' + node.data.branchId);
|
await server.remove('branches/' + node.data.branchId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// following code assumes that nodes contain only top-most selected nodes - getSelectedNodes has been
|
// following code assumes that nodes contain only top-most selected nodes - getSelectedNodes has been
|
||||||
// called with stopOnParent=true
|
// called with stopOnParent=true
|
||||||
let next = nodes[nodes.length - 1].getNextSibling();
|
let next = nodes[nodes.length - 1].getNextSibling();
|
||||||
@ -112,9 +114,19 @@ async function deleteNodes(nodes) {
|
|||||||
treeService.setCurrentNotePathToHash(next);
|
treeService.setCurrentNotePathToHash(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
infoService.showMessage("Note(s) has been deleted.");
|
await treeService.loadTreeCache();
|
||||||
|
|
||||||
await treeService.reload();
|
const parentNoteIds = Array.from(new Set(nodes.map(node => node.getParent().data.noteId)));
|
||||||
|
|
||||||
|
for (const node of nodes) {
|
||||||
|
node.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const parentNoteId of parentNoteIds) {
|
||||||
|
treeService.reloadNote(parentNoteId);
|
||||||
|
}
|
||||||
|
|
||||||
|
infoService.showMessage("Note(s) has been deleted.");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function moveNodeUpInHierarchy(node) {
|
async function moveNodeUpInHierarchy(node) {
|
||||||
|
@ -491,7 +491,7 @@ function getHashValueFromAddress() {
|
|||||||
return document.location.hash ? document.location.hash.substr(1) : ""; // strip initial #
|
return document.location.hash ? document.location.hash.substr(1) : ""; // strip initial #
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadTree() {
|
async function loadTreeCache() {
|
||||||
const resp = await server.get('tree');
|
const resp = await server.get('tree');
|
||||||
startNotePath = resp.startNotePath;
|
startNotePath = resp.startNotePath;
|
||||||
|
|
||||||
@ -499,7 +499,13 @@ async function loadTree() {
|
|||||||
startNotePath = getHashValueFromAddress();
|
startNotePath = getHashValueFromAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
return await treeBuilder.prepareTree(resp.notes, resp.branches, resp.relations);
|
treeCache.load(resp.notes, resp.branches, resp.relations);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadTree() {
|
||||||
|
await loadTreeCache();
|
||||||
|
|
||||||
|
return await treeBuilder.prepareTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function collapseTree(node = null) {
|
async function collapseTree(node = null) {
|
||||||
@ -783,5 +789,6 @@ export default {
|
|||||||
getHashValueFromAddress,
|
getHashValueFromAddress,
|
||||||
getNodesByNoteId,
|
getNodesByNoteId,
|
||||||
checkFolderStatus,
|
checkFolderStatus,
|
||||||
reloadNote
|
reloadNote,
|
||||||
|
loadTreeCache
|
||||||
};
|
};
|
@ -6,11 +6,7 @@ import treeCache from "./tree_cache.js";
|
|||||||
import messagingService from "./messaging.js";
|
import messagingService from "./messaging.js";
|
||||||
import hoistedNoteService from "./hoisted_note.js";
|
import hoistedNoteService from "./hoisted_note.js";
|
||||||
|
|
||||||
async function prepareTree(noteRows, branchRows, relations) {
|
async function prepareTree() {
|
||||||
utils.assertArguments(noteRows, branchRows, relations);
|
|
||||||
|
|
||||||
treeCache.load(noteRows, branchRows, relations);
|
|
||||||
|
|
||||||
const hoistedNoteId = await hoistedNoteService.getHoistedNoteId();
|
const hoistedNoteId = await hoistedNoteService.getHoistedNoteId();
|
||||||
|
|
||||||
let hoistedBranch;
|
let hoistedBranch;
|
||||||
|
@ -158,21 +158,21 @@ class TreeCache {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const branchId = treeCache.childParentToBranch[childNoteId + '-' + oldParentNoteId];
|
const branchId = this.childParentToBranch[childNoteId + '-' + oldParentNoteId];
|
||||||
const branch = await this.getBranch(branchId);
|
const branch = await this.getBranch(branchId);
|
||||||
branch.parentNoteId = newParentNoteId;
|
branch.parentNoteId = newParentNoteId;
|
||||||
|
|
||||||
treeCache.childParentToBranch[childNoteId + '-' + newParentNoteId] = branchId;
|
this.childParentToBranch[childNoteId + '-' + newParentNoteId] = branchId;
|
||||||
delete treeCache.childParentToBranch[childNoteId + '-' + oldParentNoteId]; // this is correct because we know that oldParentId isn't same as newParentId
|
delete this.childParentToBranch[childNoteId + '-' + oldParentNoteId]; // this is correct because we know that oldParentId isn't same as newParentId
|
||||||
|
|
||||||
// remove old associations
|
// remove old associations
|
||||||
treeCache.parents[childNoteId] = treeCache.parents[childNoteId].filter(p => p !== oldParentNoteId);
|
this.parents[childNoteId] = this.parents[childNoteId].filter(p => p !== oldParentNoteId);
|
||||||
treeCache.children[oldParentNoteId] = treeCache.children[oldParentNoteId].filter(ch => ch !== childNoteId);
|
this.children[oldParentNoteId] = this.children[oldParentNoteId].filter(ch => ch !== childNoteId);
|
||||||
|
|
||||||
// add new associations
|
// add new associations
|
||||||
treeCache.parents[childNoteId].push(newParentNoteId);
|
this.parents[childNoteId].push(newParentNoteId);
|
||||||
|
|
||||||
const children = treeCache.children[newParentNoteId] = treeCache.children[newParentNoteId] || []; // this might be first child
|
const children = this.children[newParentNoteId] = this.children[newParentNoteId] || []; // this might be first child
|
||||||
|
|
||||||
// we try to put the note into precise order which might be used again by lazy-loaded nodes
|
// we try to put the note into precise order which might be used again by lazy-loaded nodes
|
||||||
if (beforeNoteId && children.includes(beforeNoteId)) {
|
if (beforeNoteId && children.includes(beforeNoteId)) {
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import treeCache from "../public/javascripts/services/tree_cache.js";
|
|
||||||
import treeBuilder from "../public/javascripts/services/tree_builder.js";
|
|
||||||
|
|
||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
const repository = require('./repository');
|
const repository = require('./repository');
|
||||||
const Branch = require('../entities/branch');
|
const Branch = require('../entities/branch');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user