import treeService from './tree.js'; import utils from './utils.js'; import server from './server.js'; import toastService from "./toast.js"; import treeCache from "./tree_cache.js"; import treeUtils from "./tree_utils.js"; import hoistedNoteService from "./hoisted_note.js"; import noteDetailService from "./note_detail.js"; import ws from "./ws.js"; async function moveBeforeNode(nodesToMove, beforeNode) { nodesToMove = await filterRootNote(nodesToMove); if (beforeNode.data.noteId === 'root') { alert('Cannot move notes before root note.'); return; } for (const nodeToMove of nodesToMove) { const resp = await server.put('branches/' + nodeToMove.data.branchId + '/move-before/' + beforeNode.data.branchId); if (!resp.success) { alert(resp.message); return; } await changeNode( node => node.moveTo(beforeNode, 'before'), nodeToMove); } } async function moveAfterNode(nodesToMove, afterNode) { nodesToMove = await filterRootNote(nodesToMove); if (afterNode.data.noteId === 'root' || afterNode.data.noteId === await hoistedNoteService.getHoistedNoteId()) { alert('Cannot move notes after root note.'); return; } nodesToMove.reverse(); // need to reverse to keep the note order for (const nodeToMove of nodesToMove) { const resp = await server.put('branches/' + nodeToMove.data.branchId + '/move-after/' + afterNode.data.branchId); if (!resp.success) { alert(resp.message); return; } await changeNode( node => node.moveTo(afterNode, 'after'), nodeToMove); } } async function moveToNode(nodesToMove, toNode) { nodesToMove = await filterRootNote(nodesToMove); for (const nodeToMove of nodesToMove) { if (nodeToMove.data.noteId === await hoistedNoteService.getHoistedNoteId() || nodeToMove.getParent().data.noteType === 'search') { continue; } const resp = await server.put('branches/' + nodeToMove.data.branchId + '/move-to/' + toNode.data.noteId); if (!resp.success) { alert(resp.message); return; } await changeNode(async node => { // first expand which will force lazy load and only then move the node // if this is not expanded before moving, then lazy load won't happen because it already contains node // this doesn't work if this isn't a folder yet, that's why we expand second time below await toNode.setExpanded(true); node.moveTo(toNode); }, nodeToMove); } } 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) { nodes = await filterRootNote(nodes); if (nodes.length === 0) { return false; } const $deleteClonesCheckbox = $('