2019-08-25 17:36:13 +02:00
|
|
|
import optionsService from './options.js';
|
2018-12-11 21:53:56 +01:00
|
|
|
import server from "./server.js";
|
2020-01-24 15:44:24 +01:00
|
|
|
import appContext from "./app_context.js";
|
2018-12-11 21:53:56 +01:00
|
|
|
|
2019-11-04 22:41:06 +01:00
|
|
|
let hoistedNoteId = 'root';
|
2018-12-11 21:53:56 +01:00
|
|
|
|
2019-08-25 17:36:13 +02:00
|
|
|
optionsService.waitForOptions().then(options => {
|
2019-08-22 23:31:02 +02:00
|
|
|
hoistedNoteId = options.get('hoistedNoteId');
|
2018-12-11 21:53:56 +01:00
|
|
|
});
|
|
|
|
|
2019-11-04 22:41:06 +01:00
|
|
|
function getHoistedNoteNoPromise() {
|
|
|
|
return hoistedNoteId;
|
|
|
|
}
|
|
|
|
|
2018-12-11 21:53:56 +01:00
|
|
|
async function getHoistedNoteId() {
|
2019-08-25 17:36:13 +02:00
|
|
|
await optionsService.waitForOptions();
|
2018-12-11 21:53:56 +01:00
|
|
|
|
|
|
|
return hoistedNoteId;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function setHoistedNoteId(noteId) {
|
2019-05-11 19:27:33 +02:00
|
|
|
if (noteId !== 'root') {
|
2020-01-12 12:48:17 +01:00
|
|
|
await appContext.filterTabs(noteId);
|
2019-05-11 19:27:33 +02:00
|
|
|
}
|
|
|
|
|
2019-05-11 21:27:27 +02:00
|
|
|
hoistedNoteId = noteId;
|
|
|
|
|
2018-12-11 21:53:56 +01:00
|
|
|
await server.put('options/hoistedNoteId/' + noteId);
|
2018-12-12 20:39:56 +01:00
|
|
|
|
2020-01-24 15:44:24 +01:00
|
|
|
appContext.trigger('hoistedNoteChanged');
|
2018-12-11 21:53:56 +01:00
|
|
|
}
|
|
|
|
|
2018-12-15 20:29:08 +01:00
|
|
|
async function unhoist() {
|
|
|
|
await setHoistedNoteId('root');
|
|
|
|
}
|
|
|
|
|
2019-04-16 21:40:04 +02:00
|
|
|
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-11 21:53:56 +01:00
|
|
|
export default {
|
|
|
|
getHoistedNoteId,
|
2019-11-04 22:41:06 +01:00
|
|
|
getHoistedNoteNoPromise,
|
2018-12-15 20:29:08 +01:00
|
|
|
setHoistedNoteId,
|
2019-04-16 21:40:04 +02:00
|
|
|
unhoist,
|
|
|
|
isTopLevelNode,
|
|
|
|
isRootNode
|
2018-12-11 21:53:56 +01:00
|
|
|
}
|