clean up tree service WIP

This commit is contained in:
zadam
2020-02-02 22:04:28 +01:00
parent d5ae3802d1
commit b63ecba695
14 changed files with 68 additions and 118 deletions

View File

@@ -1,6 +1,7 @@
import optionsService from './options.js';
import server from "./server.js";
import appContext from "./app_context.js";
import treeService from "./tree.js";
let hoistedNoteId = 'root';
@@ -19,15 +20,11 @@ async function getHoistedNoteId() {
}
async function setHoistedNoteId(noteId) {
if (noteId !== 'root') {
await appContext.filterTabs(noteId);
}
hoistedNoteId = noteId;
await server.put('options/hoistedNoteId/' + noteId);
appContext.trigger('hoistedNoteChanged');
appContext.trigger('hoistedNoteChanged', {hoistedNoteId});
}
async function unhoist() {
@@ -44,11 +41,38 @@ async function isRootNode(node) {
|| node.data.noteId === await getHoistedNoteId();
}
async function checkNoteAccess(notePath) {
// notePath argument can contain only noteId which is not good when hoisted since
// then we need to check the whole note path
const runNotePath = await treeService.getRunPath(notePath);
if (!runNotePath) {
console.log("Cannot activate " + notePath);
return false;
}
const hoistedNoteId = await getHoistedNoteId();
if (hoistedNoteId !== 'root' && !runNotePath.includes(hoistedNoteId)) {
const confirmDialog = await import('../dialogs/confirm.js');
if (!await confirmDialog.confirm("Requested note is outside of hoisted note subtree and you must unhoist to access the note. Do you want to proceed with unhoisting?")) {
return false;
}
// unhoist so we can activate the note
await unhoist();
}
return true;
}
export default {
getHoistedNoteId,
getHoistedNoteNoPromise,
setHoistedNoteId,
unhoist,
isTopLevelNode,
isRootNode
isRootNode,
checkNoteAccess
}