mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
cloning is now done without reloading the whole tree
This commit is contained in:
parent
3f656ea76f
commit
ca0d17d93a
@ -139,22 +139,6 @@ async function moveNodeUpInHierarchy(node) {
|
|||||||
node);
|
node);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkFolderStatus(node) {
|
|
||||||
const children = node.getChildren();
|
|
||||||
const note = await treeCache.getNote(node.data.noteId);
|
|
||||||
|
|
||||||
if (!children || children.length === 0) {
|
|
||||||
node.folder = false;
|
|
||||||
node.icon = await treeBuilder.getIcon(note);
|
|
||||||
node.renderTitle();
|
|
||||||
}
|
|
||||||
else if (children && children.length > 0) {
|
|
||||||
node.folder = true;
|
|
||||||
node.icon = await treeBuilder.getIcon(note);
|
|
||||||
node.renderTitle();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function changeNode(func, node, beforeNoteId = null, afterNoteId = null) {
|
async function changeNode(func, node, beforeNoteId = null, afterNoteId = null) {
|
||||||
utils.assertArguments(func, node);
|
utils.assertArguments(func, node);
|
||||||
|
|
||||||
@ -176,8 +160,8 @@ async function changeNode(func, node, beforeNoteId = null, afterNoteId = null) {
|
|||||||
|
|
||||||
treeService.setCurrentNotePathToHash(node);
|
treeService.setCurrentNotePathToHash(node);
|
||||||
|
|
||||||
await checkFolderStatus(thisOldParentNode);
|
await treeService.checkFolderStatus(thisOldParentNode);
|
||||||
await checkFolderStatus(thisNewParentNode);
|
await treeService.checkFolderStatus(thisNewParentNode);
|
||||||
|
|
||||||
if (!thisNewParentNode.isExpanded()) {
|
if (!thisNewParentNode.isExpanded()) {
|
||||||
// this expands the note in case it become the folder only after the move
|
// this expands the note in case it become the folder only after the move
|
||||||
@ -192,7 +176,7 @@ async function changeNode(func, node, beforeNoteId = null, afterNoteId = null) {
|
|||||||
|
|
||||||
newParentNode.load(true); // force reload to show up new note
|
newParentNode.load(true); // force reload to show up new note
|
||||||
|
|
||||||
await checkFolderStatus(newParentNode);
|
await treeService.checkFolderStatus(newParentNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const oldParentNode of treeService.getNodesByNoteId(thisOldParentNode.data.noteId)) {
|
for (const oldParentNode of treeService.getNodesByNoteId(thisOldParentNode.data.noteId)) {
|
||||||
@ -203,7 +187,7 @@ async function changeNode(func, node, beforeNoteId = null, afterNoteId = null) {
|
|||||||
|
|
||||||
await oldParentNode.load(true); // force reload to show up new note
|
await oldParentNode.load(true); // force reload to show up new note
|
||||||
|
|
||||||
await checkFolderStatus(oldParentNode);
|
await treeService.checkFolderStatus(oldParentNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import treeService from './tree.js';
|
import treeService from './tree.js';
|
||||||
|
import treeCache from './tree_cache.js';
|
||||||
import server from './server.js';
|
import server from './server.js';
|
||||||
|
|
||||||
async function cloneNoteTo(childNoteId, parentNoteId, prefix) {
|
async function cloneNoteTo(childNoteId, parentNoteId, prefix) {
|
||||||
@ -11,7 +12,9 @@ async function cloneNoteTo(childNoteId, parentNoteId, prefix) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await treeService.reload();
|
treeCache.addBranchRelationship(resp.branchId, childNoteId, parentNoteId);
|
||||||
|
|
||||||
|
await treeService.reloadNote(parentNoteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// beware that first arg is noteId and second is branchId!
|
// beware that first arg is noteId and second is branchId!
|
||||||
@ -23,7 +26,11 @@ async function cloneNoteAfter(noteId, afterBranchId) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await treeService.reload();
|
const afterBranch = await treeCache.getBranch(afterBranchId);
|
||||||
|
|
||||||
|
treeCache.addBranchRelationship(resp.branchId, noteId, afterBranch.parentNoteId);
|
||||||
|
|
||||||
|
await treeService.reloadNote(afterBranch.parentNoteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -708,6 +708,30 @@ function createNoteInto() {
|
|||||||
createNote(node, node.data.noteId, 'into', null, node.data.isProtected, true);
|
createNote(node, node.data.noteId, 'into', null, node.data.isProtected, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function checkFolderStatus(node) {
|
||||||
|
const children = node.getChildren();
|
||||||
|
const note = await treeCache.getNote(node.data.noteId);
|
||||||
|
|
||||||
|
if (!children || children.length === 0) {
|
||||||
|
node.folder = false;
|
||||||
|
node.icon = await treeBuilder.getIcon(note);
|
||||||
|
node.renderTitle();
|
||||||
|
}
|
||||||
|
else if (children && children.length > 0) {
|
||||||
|
node.folder = true;
|
||||||
|
node.icon = await treeBuilder.getIcon(note);
|
||||||
|
node.renderTitle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function reloadNote(noteId) {
|
||||||
|
for (const node of getNodesByNoteId(noteId)) {
|
||||||
|
await node.load(true);
|
||||||
|
|
||||||
|
await checkFolderStatus(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.glob.createNoteInto = createNoteInto;
|
window.glob.createNoteInto = createNoteInto;
|
||||||
|
|
||||||
utils.bindShortcut('ctrl+p', createNoteInto);
|
utils.bindShortcut('ctrl+p', createNoteInto);
|
||||||
@ -757,5 +781,7 @@ export default {
|
|||||||
treeInitialized,
|
treeInitialized,
|
||||||
setExpandedToServer,
|
setExpandedToServer,
|
||||||
getHashValueFromAddress,
|
getHashValueFromAddress,
|
||||||
getNodesByNoteId
|
getNodesByNoteId,
|
||||||
|
checkFolderStatus,
|
||||||
|
reloadNote
|
||||||
};
|
};
|
@ -46,6 +46,8 @@ async function pasteInto(node) {
|
|||||||
|
|
||||||
await treeChangesService.moveToNode(nodes, node);
|
await treeChangesService.moveToNode(nodes, node);
|
||||||
|
|
||||||
|
await node.setExpanded(true);
|
||||||
|
|
||||||
clipboardIds = [];
|
clipboardIds = [];
|
||||||
clipboardMode = null;
|
clipboardMode = null;
|
||||||
}
|
}
|
||||||
@ -53,6 +55,9 @@ async function pasteInto(node) {
|
|||||||
for (const noteId of clipboardIds) {
|
for (const noteId of clipboardIds) {
|
||||||
await cloningService.cloneNoteTo(noteId, node.data.noteId);
|
await cloningService.cloneNoteTo(noteId, node.data.noteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await node.setExpanded(true);
|
||||||
|
|
||||||
// copy will keep clipboardIds and clipboardMode so it's possible to paste into multiple places
|
// copy will keep clipboardIds and clipboardMode so it's possible to paste into multiple places
|
||||||
}
|
}
|
||||||
else if (clipboardIds.length === 0) {
|
else if (clipboardIds.length === 0) {
|
||||||
|
@ -18,7 +18,7 @@ async function cloneNoteToParent(noteId, parentNoteId, prefix) {
|
|||||||
return validationResult;
|
return validationResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
await new Branch({
|
const branch = await new Branch({
|
||||||
noteId: noteId,
|
noteId: noteId,
|
||||||
parentNoteId: parentNoteId,
|
parentNoteId: parentNoteId,
|
||||||
prefix: prefix,
|
prefix: prefix,
|
||||||
@ -27,7 +27,7 @@ async function cloneNoteToParent(noteId, parentNoteId, prefix) {
|
|||||||
|
|
||||||
await sql.execute("UPDATE branches SET isExpanded = 1 WHERE noteId = ?", [parentNoteId]);
|
await sql.execute("UPDATE branches SET isExpanded = 1 WHERE noteId = ?", [parentNoteId]);
|
||||||
|
|
||||||
return { success: true };
|
return { success: true, branchId: branch.branchId };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function ensureNoteIsPresentInParent(noteId, parentNoteId, prefix) {
|
async function ensureNoteIsPresentInParent(noteId, parentNoteId, prefix) {
|
||||||
@ -86,14 +86,14 @@ async function cloneNoteAfter(noteId, afterBranchId) {
|
|||||||
|
|
||||||
await syncTable.addNoteReorderingSync(afterNote.parentNoteId);
|
await syncTable.addNoteReorderingSync(afterNote.parentNoteId);
|
||||||
|
|
||||||
await new Branch({
|
const branch = await new Branch({
|
||||||
noteId: noteId,
|
noteId: noteId,
|
||||||
parentNoteId: afterNote.parentNoteId,
|
parentNoteId: afterNote.parentNoteId,
|
||||||
notePosition: afterNote.notePosition + 1,
|
notePosition: afterNote.notePosition + 1,
|
||||||
isExpanded: 0
|
isExpanded: 0
|
||||||
}).save();
|
}).save();
|
||||||
|
|
||||||
return { success: true };
|
return { success: true, branchId: branch.branchId };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function isNoteDeleted(noteId) {
|
async function isNoteDeleted(noteId) {
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
"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