trilium/src/public/javascripts/services/hoisted_note.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-12-12 04:53:56 +08:00
import optionsInit from './options_init.js';
import server from "./server.js";
2018-12-13 03:39:56 +08:00
import tree from "./tree.js";
2019-05-12 01:27:33 +08:00
import noteDetailService from "./note_detail.js";
2018-12-12 04:53:56 +08:00
let hoistedNoteId;
optionsInit.optionsReady.then(options => {
hoistedNoteId = options['hoistedNoteId'];
});
async function getHoistedNoteId() {
await optionsInit.optionsReady;
return hoistedNoteId;
}
async function setHoistedNoteId(noteId) {
2019-05-12 01:27:33 +08:00
if (noteId !== 'root') {
await noteDetailService.filterTabs(noteId);
}
hoistedNoteId = noteId;
2018-12-12 04:53:56 +08:00
await server.put('options/hoistedNoteId/' + noteId);
2018-12-13 03:39:56 +08:00
await tree.reload();
2018-12-12 04:53:56 +08:00
}
2018-12-16 03:29:08 +08:00
async function unhoist() {
await setHoistedNoteId('root');
}
async function isTopLevelNode(node) {
return await isRootNode(node.getParent());
}
async function isRootNode(node) {
// even though check for 'root' should not be necessary, we keep it just in case
return node.data.noteId === "root"
|| node.data.noteId === await getHoistedNoteId();
}
2018-12-12 04:53:56 +08:00
export default {
getHoistedNoteId,
2018-12-16 03:29:08 +08:00
setHoistedNoteId,
unhoist,
isTopLevelNode,
isRootNode
2018-12-12 04:53:56 +08:00
}