allow search result to be moved from tree to relation map, fixes #1650

This commit is contained in:
zadam 2021-02-18 22:30:55 +01:00
parent 859465841d
commit 2cfd093cae
4 changed files with 22 additions and 14 deletions

View File

@ -7,6 +7,7 @@ import ws from "./ws.js";
async function moveBeforeBranch(branchIdsToMove, beforeBranchId) { async function moveBeforeBranch(branchIdsToMove, beforeBranchId) {
branchIdsToMove = filterRootNote(branchIdsToMove); branchIdsToMove = filterRootNote(branchIdsToMove);
branchIdsToMove = filterSearchBranches(branchIdsToMove);
if (beforeBranchId === 'root') { if (beforeBranchId === 'root') {
alert('Cannot move notes before root note.'); alert('Cannot move notes before root note.');
@ -25,6 +26,7 @@ async function moveBeforeBranch(branchIdsToMove, beforeBranchId) {
async function moveAfterBranch(branchIdsToMove, afterBranchId) { async function moveAfterBranch(branchIdsToMove, afterBranchId) {
branchIdsToMove = filterRootNote(branchIdsToMove); branchIdsToMove = filterRootNote(branchIdsToMove);
branchIdsToMove = filterSearchBranches(branchIdsToMove);
const afterNote = await treeCache.getBranch(afterBranchId).getNote(); const afterNote = await treeCache.getBranch(afterBranchId).getNote();
@ -142,6 +144,10 @@ async function moveNodeUpInHierarchy(node) {
} }
} }
function filterSearchBranches(branchIds) {
return branchIds.filter(branchId => !branchId.startsWith('virt-'));
}
function filterRootNote(branchIds) { function filterRootNote(branchIds) {
const hoistedNoteId = hoistedNoteService.getHoistedNoteId(); const hoistedNoteId = hoistedNoteService.getHoistedNoteId();

View File

@ -392,12 +392,6 @@ export default class NoteTreeWidget extends TabAwareWidget {
autoExpandMS: 600, autoExpandMS: 600,
preventLazyParents: false, preventLazyParents: false,
dragStart: (node, data) => { dragStart: (node, data) => {
// don't allow dragging root node
if (node.data.noteId === hoistedNoteService.getHoistedNoteId()
|| node.getParent().data.noteType === 'search') {
return false;
}
const notes = this.getSelectedOrActiveNodes(node).map(node => ({ const notes = this.getSelectedOrActiveNodes(node).map(node => ({
noteId: node.data.noteId, noteId: node.data.noteId,
branchId: node.data.branchId, branchId: node.data.branchId,

View File

@ -5,7 +5,7 @@
.note-detail-relation-map { .note-detail-relation-map {
height: 100%; height: 100%;
overflow: hidden !important; overflow: hidden !important;
padding-top: 10px; padding: 10px;
position: relative; position: relative;
} }

View File

@ -54,9 +54,17 @@ function moveBranchBeforeNote(req) {
const {branchId, beforeBranchId} = req.params; const {branchId, beforeBranchId} = req.params;
const branchToMove = repository.getBranch(branchId); const branchToMove = repository.getBranch(branchId);
const beforeNote = repository.getBranch(beforeBranchId); const beforeBranch = repository.getBranch(beforeBranchId);
const validationResult = treeService.validateParentChild(beforeNote.parentNoteId, branchToMove.noteId, branchId); if (!branchToMove) {
return [404, `Can't find branch ${branchId}`];
}
if (!beforeBranch) {
return [404, `Can't find branch ${beforeBranchId}`];
}
const validationResult = treeService.validateParentChild(beforeBranch.parentNoteId, branchToMove.noteId, branchId);
if (!validationResult.success) { if (!validationResult.success) {
return [200, validationResult]; return [200, validationResult];
@ -65,16 +73,16 @@ function moveBranchBeforeNote(req) {
// we don't change utcDateModified so other changes are prioritized in case of conflict // we don't change utcDateModified so other changes are prioritized in case of conflict
// also we would have to sync all those modified branches otherwise hash checks would fail // also we would have to sync all those modified branches otherwise hash checks would fail
sql.execute("UPDATE branches SET notePosition = notePosition + 10 WHERE parentNoteId = ? AND notePosition >= ? AND isDeleted = 0", sql.execute("UPDATE branches SET notePosition = notePosition + 10 WHERE parentNoteId = ? AND notePosition >= ? AND isDeleted = 0",
[beforeNote.parentNoteId, beforeNote.notePosition]); [beforeBranch.parentNoteId, beforeBranch.notePosition]);
entityChangesService.addNoteReorderingEntityChange(beforeNote.parentNoteId); entityChangesService.addNoteReorderingEntityChange(beforeBranch.parentNoteId);
if (branchToMove.parentNoteId === beforeNote.parentNoteId) { if (branchToMove.parentNoteId === beforeBranch.parentNoteId) {
branchToMove.notePosition = beforeNote.notePosition; branchToMove.notePosition = beforeBranch.notePosition;
branchToMove.save(); branchToMove.save();
} }
else { else {
const newBranch = branchToMove.createClone(beforeNote.parentNoteId, beforeNote.notePosition); const newBranch = branchToMove.createClone(beforeBranch.parentNoteId, beforeBranch.notePosition);
newBranch.save(); newBranch.save();
branchToMove.isDeleted = true; branchToMove.isDeleted = true;