deleting a note will close all tabs containing the note

This commit is contained in:
zadam 2019-05-20 21:50:01 +02:00
parent aead6a44de
commit 48b4488a58
5 changed files with 27 additions and 6 deletions

View file

@ -4,6 +4,7 @@ import server from './server.js';
import infoService from "./info.js"; import infoService from "./info.js";
import treeCache from "./tree_cache.js"; import treeCache from "./tree_cache.js";
import hoistedNoteService from "./hoisted_note.js"; import hoistedNoteService from "./hoisted_note.js";
import noteDetailService from "./note_detail.js";
async function moveBeforeNode(nodesToMove, beforeNode) { async function moveBeforeNode(nodesToMove, beforeNode) {
nodesToMove = await filterRootNote(nodesToMove); nodesToMove = await filterRootNote(nodesToMove);
@ -85,7 +86,11 @@ async function deleteNodes(nodes) {
} }
for (const node of nodes) { for (const node of nodes) {
await server.remove('branches/' + node.data.branchId); const {noteDeleted} = await server.remove('branches/' + node.data.branchId);
if (noteDeleted) {
noteDetailService.noteDeleted(node.data.noteId);
}
} }
// 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

View file

@ -267,7 +267,7 @@ async function loadNote(noteId) {
async function filterTabs(noteId) { async function filterTabs(noteId) {
for (const tc of tabContexts) { for (const tc of tabContexts) {
if (tc.notePath && !tc.notePath.split("/").includes(noteId)) { if (tc.notePath && !tc.notePath.split("/").includes(noteId)) {
await tabRow.removeTab(tc.tab); await tabRow.removeTab(tc.$tab[0]);
} }
} }
@ -281,6 +281,14 @@ async function filterTabs(noteId) {
await saveOpenTabs(); await saveOpenTabs();
} }
async function noteDeleted(noteId) {
for (const tc of tabContexts) {
if (tc.notePath && tc.notePath.split("/").includes(noteId)) {
await tabRow.removeTab(tc.$tab[0]);
}
}
}
function focusOnTitle() { function focusOnTitle() {
getActiveTabContext().$noteTitle.focus(); getActiveTabContext().$noteTitle.focus();
} }
@ -496,5 +504,6 @@ export default {
activateTabContext, activateTabContext,
clearOpenTabsTask, clearOpenTabsTask,
filterTabs, filterTabs,
openEmptyTab openEmptyTab,
noteDeleted
}; };

View file

@ -853,7 +853,6 @@ export default {
loadTree, loadTree,
treeInitialized, treeInitialized,
setExpandedToServer, setExpandedToServer,
getHashValueFromAddress,
getNodesByNoteId, getNodesByNoteId,
checkFolderStatus, checkFolderStatus,
reloadNote, reloadNote,

View file

@ -102,7 +102,9 @@ async function setExpanded(req) {
async function deleteBranch(req) { async function deleteBranch(req) {
const branch = await repository.getBranch(req.params.branchId); const branch = await repository.getBranch(req.params.branchId);
await notes.deleteNote(branch); return {
noteDeleted: await notes.deleteNote(branch)
};
} }
async function setPrefix(req) { async function setPrefix(req) {

View file

@ -373,9 +373,10 @@ async function updateNote(noteId, noteUpdates) {
await protectNoteRevisions(note); await protectNoteRevisions(note);
} }
/** @return {boolean} - true if note has been deleted, false otherwise */
async function deleteNote(branch) { async function deleteNote(branch) {
if (!branch || branch.isDeleted) { if (!branch || branch.isDeleted) {
return; return false;
} }
if (branch.branchId === 'root' if (branch.branchId === 'root'
@ -418,6 +419,11 @@ async function deleteNote(branch) {
link.isDeleted = true; link.isDeleted = true;
await link.save(); await link.save();
} }
return true;
}
else {
return false;
} }
} }