mirror of
https://github.com/zadam/trilium.git
synced 2025-11-08 06:15:48 +01:00
clean up tree service WIP
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user