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 hoistedNoteService from "./hoisted_note.js"; import ws from "./ws.js"; import appContext from "./app_context.js"; async function moveBeforeBranch(branchIdsToMove, beforeBranchId) { branchIdsToMove = await filterRootNote(branchIdsToMove); if (beforeBranchId === 'root') { alert('Cannot move notes before root note.'); return; } for (const branchIdToMove of branchIdsToMove) { const resp = await server.put(`branches/${branchIdToMove}/move-before/${beforeBranchId}`); if (!resp.success) { alert(resp.message); return; } } } async function moveAfterBranch(branchIdsToMove, afterBranchId) { branchIdsToMove = await filterRootNote(branchIdsToMove); const afterNote = await treeCache.getBranch(afterBranchId).getNote(); if (afterNote.noteId === 'root' || afterNote.noteId === await hoistedNoteService.getHoistedNoteId()) { alert('Cannot move notes after root note.'); return; } branchIdsToMove.reverse(); // need to reverse to keep the note order for (const branchIdToMove of branchIdsToMove) { const resp = await server.put(`branches/${branchIdToMove}/move-after/${afterBranchId}`); if (!resp.success) { alert(resp.message); return; } } } async function moveToParentNote(branchIdsToMove, newParentNoteId) { branchIdsToMove = await filterRootNote(branchIdsToMove); for (const branchIdToMove of branchIdsToMove) { const branchToMove = treeCache.getBranch(branchIdToMove); if (branchToMove.noteId === await hoistedNoteService.getHoistedNoteId() || (await branchToMove.getParentNote()).type === 'search') { continue; } const resp = await server.put(`branches/${branchIdToMove}/move-to/${newParentNoteId}`); if (!resp.success) { alert(resp.message); return; } } } // FIXME used for finding a next note to activate after a delete 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 treeService.getNotePath(next); } async function deleteNodes(branchIdsToDelete) { branchIdsToDelete = await filterRootNote(branchIdsToDelete); if (branchIdsToDelete.length === 0) { return false; } const $deleteClonesCheckbox = $('