Notes/src/services/special_notes.js

655 lines
19 KiB
JavaScript
Raw Normal View History

const attributeService = require("./attributes");
const dateNoteService = require("./date_notes");
const becca = require("../becca/becca");
const noteService = require("./notes");
const cls = require("./cls");
const dateUtils = require("./date_utils");
2022-11-28 23:39:23 +01:00
const LBTPL_ROOT = "lbtpl_root";
2022-11-30 16:57:51 +01:00
const LBTPL_BASE = "lbtpl_base";
2022-11-29 16:16:57 +01:00
const LBTPL_COMMAND = "lbtpl_command";
2022-12-01 10:16:57 +01:00
const LBTPL_NOTE_LAUNCHER = "lbtpl_notelauncher";
2022-11-28 23:39:23 +01:00
const LBTPL_SCRIPT = "lbtpl_script";
const LBTPL_BUILTIN_WIDGET = "lbtpl_builtinwidget";
const LBTPL_SPACER = "lbtpl_spacer";
const LBTPL_CUSTOM_WIDGET = "lbtpl_customwidget";
function getInboxNote(date) {
const hoistedNote = getHoistedNote();
let inbox;
if (!hoistedNote.isRoot()) {
inbox = hoistedNote.searchNoteInSubtree('#hoistedInbox');
if (!inbox) {
inbox = hoistedNote.searchNoteInSubtree('#inbox');
}
if (!inbox) {
inbox = hoistedNote;
}
}
else {
inbox = attributeService.getNoteWithLabel('inbox')
2022-01-10 17:09:20 +01:00
|| dateNoteService.getDayNote(date);
}
return inbox;
}
function getHiddenRoot() {
let hidden = becca.getNote('hidden');
if (!hidden) {
hidden = noteService.createNewNote({
2021-12-21 13:22:13 +01:00
branchId: 'hidden',
noteId: 'hidden',
title: 'hidden',
2022-11-25 15:29:57 +01:00
type: 'doc',
content: '',
parentNoteId: 'root'
}).note;
// isInheritable: false means that this notePath is automatically not preffered but at the same time
// the flag is not inherited to the children
hidden.addLabel('archived', "", false);
hidden.addLabel('excludeFromNoteMap', "", true);
2022-11-25 15:29:57 +01:00
hidden.addLabel('iconClass', "bx bx-chip", false);
}
2022-11-26 14:57:39 +01:00
const MAX_POS = 999_999_999;
const branch = hidden.getBranches()[0];
if (branch.notePosition !== MAX_POS) {
// we want to keep the hidden subtree always last, otherwise there will be problems with e.g. keyboard navigation
// over tree when it's in the middle
branch.notePosition = MAX_POS;
branch.save();
}
return hidden;
}
function getSearchRoot() {
let searchRoot = becca.getNote('search');
if (!searchRoot) {
searchRoot = noteService.createNewNote({
2022-11-06 15:18:32 +01:00
branchId: 'search',
noteId: 'search',
title: 'search',
2022-11-25 15:29:57 +01:00
type: 'doc',
content: '',
parentNoteId: getHiddenRoot().noteId
}).note;
}
return searchRoot;
}
2021-09-20 23:04:41 +02:00
function getGlobalNoteMap() {
let globalNoteMap = becca.getNote('globalnotemap');
2021-09-20 23:04:41 +02:00
if (!globalNoteMap) {
globalNoteMap = noteService.createNewNote({
2022-11-06 15:18:32 +01:00
branchId: 'globalnotemap',
2021-09-20 22:19:47 +02:00
noteId: 'globalnotemap',
title: 'Global Note Map',
type: 'note-map',
content: '',
2022-11-06 15:18:32 +01:00
parentNoteId: getHiddenRoot().noteId
}).note;
2021-09-20 23:04:41 +02:00
globalNoteMap.addLabel('mapRootNoteId', 'hoisted');
}
2021-09-20 23:04:41 +02:00
return globalNoteMap;
}
function getSqlConsoleRoot() {
let sqlConsoleRoot = becca.getNote('sqlconsole');
if (!sqlConsoleRoot) {
sqlConsoleRoot = noteService.createNewNote({
2022-11-06 15:18:32 +01:00
branchId: 'sqlconsole',
noteId: 'sqlconsole',
title: 'SQL Console',
2022-11-25 15:29:57 +01:00
type: 'doc',
content: '',
parentNoteId: getHiddenRoot().noteId
}).note;
2022-11-25 15:29:57 +01:00
sqlConsoleRoot.addLabel('iconClass', 'bx bx-data');
}
return sqlConsoleRoot;
}
function createSqlConsole() {
const {note} = noteService.createNewNote({
parentNoteId: getSqlConsoleRoot().noteId,
title: 'SQL Console',
content: "SELECT title, isDeleted, isProtected FROM notes WHERE noteId = ''\n\n\n\n",
type: 'code',
mime: 'text/x-sqlite;schema=trilium'
});
note.setLabel("sqlConsole", dateUtils.localNowDate());
2022-11-25 15:29:57 +01:00
note.setLabel('iconClass', 'bx bx-data');
return note;
}
function saveSqlConsole(sqlConsoleNoteId) {
const sqlConsoleNote = becca.getNote(sqlConsoleNoteId);
const today = dateUtils.localNowDate();
const sqlConsoleHome =
attributeService.getNoteWithLabel('sqlConsoleHome')
2022-01-10 17:09:20 +01:00
|| dateNoteService.getDayNote(today);
const result = sqlConsoleNote.cloneTo(sqlConsoleHome.noteId);
for (const parentBranch of sqlConsoleNote.getParentBranches()) {
if (parentBranch.parentNote.hasAncestor("hidden")) {
parentBranch.markAsDeleted();
}
}
return result;
}
function createSearchNote(searchString, ancestorNoteId) {
const {note} = noteService.createNewNote({
parentNoteId: getSearchRoot().noteId,
title: 'Search: ' + searchString,
content: "",
type: 'search',
mime: 'application/json'
});
note.setLabel('searchString', searchString);
if (ancestorNoteId) {
note.setRelation('ancestor', ancestorNoteId);
}
return note;
}
function getSearchHome() {
const hoistedNote = getHoistedNote();
if (!hoistedNote.isRoot()) {
return hoistedNote.searchNoteInSubtree('#hoistedSearchHome')
|| hoistedNote.searchNoteInSubtree('#searchHome')
|| hoistedNote;
} else {
const today = dateUtils.localNowDate();
return hoistedNote.searchNoteInSubtree('#searchHome')
2022-01-10 17:09:20 +01:00
|| dateNoteService.getDayNote(today);
}
}
function saveSearchNote(searchNoteId) {
const searchNote = becca.getNote(searchNoteId);
const searchHome = getSearchHome();
const result = searchNote.cloneTo(searchHome.noteId);
for (const parentBranch of searchNote.getParentBranches()) {
if (parentBranch.parentNote.hasAncestor("hidden")) {
parentBranch.markAsDeleted();
}
}
return result;
}
function getHoistedNote() {
return becca.getNote(cls.getHoistedNoteId());
}
2021-12-07 23:03:49 +01:00
function getShareRoot() {
let shareRoot = becca.getNote('share');
if (!shareRoot) {
2022-11-06 14:44:26 +01:00
const hiddenRoot = getHiddenRoot();
2021-12-07 23:03:49 +01:00
shareRoot = noteService.createNewNote({
2021-12-20 17:30:47 +01:00
branchId: 'share',
2021-12-07 23:03:49 +01:00
noteId: 'share',
2021-12-20 17:30:47 +01:00
title: 'Shared notes',
2022-11-25 15:29:57 +01:00
type: 'doc',
2021-12-07 23:03:49 +01:00
content: '',
2022-11-06 14:44:26 +01:00
parentNoteId: hiddenRoot.noteId
2021-12-07 23:03:49 +01:00
}).note;
}
2022-11-25 15:29:57 +01:00
if (!shareRoot.hasOwnedLabel("docName")) {
shareRoot.addLabel("docName", "share");
}
2021-12-07 23:03:49 +01:00
return shareRoot;
}
2022-06-03 17:29:08 +02:00
function getBulkActionNote() {
let bulkActionNote = becca.getNote('bulkaction');
if (!bulkActionNote) {
bulkActionNote = noteService.createNewNote({
branchId: 'bulkaction',
noteId: 'bulkaction',
title: 'Bulk action',
type: 'text',
content: '',
parentNoteId: getHiddenRoot().noteId
}).note;
}
return bulkActionNote;
}
2022-08-02 17:01:09 +02:00
function getLaunchBarRoot() {
2022-08-04 23:00:32 +02:00
let note = becca.getNote('lb_root');
2022-08-02 17:01:09 +02:00
if (!note) {
note = noteService.createNewNote({
2022-08-04 23:00:32 +02:00
branchId: 'lb_root',
noteId: 'lb_root',
2022-08-02 17:01:09 +02:00
title: 'Launch bar',
2022-11-25 15:29:57 +01:00
type: 'doc',
2022-08-02 17:01:09 +02:00
content: '',
parentNoteId: getHiddenRoot().noteId
}).note;
2022-08-05 19:15:28 +02:00
note.addLabel("iconClass", "bx bx-sidebar");
2022-08-06 23:49:25 +02:00
note.addLabel("docName", "launchbar_intro");
2022-08-02 17:01:09 +02:00
}
return note;
}
2022-12-01 10:16:57 +01:00
function getLaunchBarAvailableLaunchersRoot() {
let note = becca.getNote('lb_availablelaunchers');
2022-08-02 17:01:09 +02:00
if (!note) {
note = noteService.createNewNote({
2022-12-01 10:16:57 +01:00
branchId: 'lb_availablelaunchers',
noteId: 'lb_availablelaunchers',
title: 'Available launchers',
2022-11-25 15:29:57 +01:00
type: 'doc',
2022-08-02 17:01:09 +02:00
content: '',
2022-11-28 23:39:23 +01:00
parentNoteId: getLaunchBarRoot().noteId,
ignoreForbiddenParents: true
2022-08-02 17:01:09 +02:00
}).note;
2022-08-05 19:15:28 +02:00
note.addLabel("iconClass", "bx bx-hide");
2022-08-06 23:49:25 +02:00
note.addLabel("docName", "launchbar_intro");
2022-08-02 17:01:09 +02:00
}
2022-12-01 10:16:57 +01:00
const branch = becca.getBranch('lb_availablelaunchers');
2022-08-05 16:44:26 +02:00
if (!branch.isExpanded) {
branch.isExpanded = true;
branch.save();
}
2022-08-02 17:01:09 +02:00
return note;
}
2022-12-01 10:16:57 +01:00
function getLaunchBarVisibleLaunchersRoot() {
let note = becca.getNote('lb_visiblelaunchers');
2022-08-02 17:01:09 +02:00
if (!note) {
note = noteService.createNewNote({
2022-12-01 10:16:57 +01:00
branchId: 'lb_visiblelaunchers',
noteId: 'lb_visiblelaunchers',
title: 'Visible launchers',
2022-11-25 15:29:57 +01:00
type: 'doc',
2022-08-02 17:01:09 +02:00
content: '',
2022-11-28 23:39:23 +01:00
parentNoteId: getLaunchBarRoot().noteId,
ignoreForbiddenParents: true
2022-08-02 17:01:09 +02:00
}).note;
2022-08-05 19:15:28 +02:00
note.addLabel("iconClass", "bx bx-show");
2022-08-06 23:49:25 +02:00
note.addLabel("docName", "launchbar_intro");
2022-08-02 17:01:09 +02:00
}
2022-12-01 10:16:57 +01:00
const branch = becca.getBranch('lb_visiblelaunchers');
2022-08-05 16:44:26 +02:00
if (!branch.isExpanded) {
branch.isExpanded = true;
branch.save();
}
2022-08-02 17:01:09 +02:00
return note;
}
2022-12-01 10:16:57 +01:00
const launchers = [
// visible launchers:
2022-08-04 23:00:32 +02:00
{ id: 'lb_newnote', command: 'createNoteIntoInbox', title: 'New note', icon: 'bx bx-file-blank', isVisible: true },
{ id: 'lb_search', command: 'searchNotes', title: 'Search notes', icon: 'bx bx-search', isVisible: true },
{ id: 'lb_jumpto', command: 'jumpToNote', title: 'Jump to note', icon: 'bx bx-send', isVisible: true },
2022-08-05 16:44:26 +02:00
{ id: 'lb_notemap', targetNoteId: 'globalnotemap', title: 'Note map', icon: 'bx bx-map-alt', isVisible: true },
{ id: 'lb_calendar', builtinWidget: 'calendar', title: 'Calendar', icon: 'bx bx-calendar', isVisible: true },
2022-12-01 13:07:23 +01:00
{ id: 'lb_spacer1', builtinWidget: 'spacer', title: 'Spacer', isVisible: true, baseSize: "50", growthFactor: "0" },
2022-08-05 19:15:28 +02:00
{ id: 'lb_bookmarks', builtinWidget: 'bookmarks', title: 'Bookmarks', icon: 'bx bx-bookmark', isVisible: true },
2022-12-01 13:07:23 +01:00
{ id: 'lb_spacer2', builtinWidget: 'spacer', title: 'Spacer', isVisible: true, baseSize: "0", growthFactor: "1" },
2022-08-05 19:15:28 +02:00
{ id: 'lb_protectedsession', builtinWidget: 'protectedSession', title: 'Protected session', icon: 'bx bx bx-shield-quarter', isVisible: true },
{ id: 'lb_syncstatus', builtinWidget: 'syncStatus', title: 'Sync status', icon: 'bx bx-wifi', isVisible: true },
2022-11-25 15:29:57 +01:00
2022-12-01 10:16:57 +01:00
// available launchers:
2022-11-25 15:29:57 +01:00
{ id: 'lb_recentchanges', command: 'showRecentChanges', title: 'Recent changes', icon: 'bx bx-history', isVisible: false },
{ id: 'lb_backinhistory', builtinWidget: 'backInHistoryButton', title: 'Back in history', icon: 'bx bxs-left-arrow-square', isVisible: false },
{ id: 'lb_forwardinhistory', builtinWidget: 'forwardInHistoryButton', title: 'Forward in history', icon: 'bx bxs-right-arrow-square', isVisible: false },
2022-08-02 17:01:09 +02:00
];
2022-12-05 23:57:29 +01:00
function createLaunchers() {
2022-12-01 10:16:57 +01:00
for (const launcher of launchers) {
let note = becca.getNote(launcher.id);
2022-08-06 13:47:27 +02:00
if (note) {
continue;
}
2022-12-01 10:16:57 +01:00
const parentNoteId = launcher.isVisible
? getLaunchBarVisibleLaunchersRoot().noteId
: getLaunchBarAvailableLaunchersRoot().noteId;
2022-11-25 15:29:57 +01:00
2022-08-06 13:47:27 +02:00
note = noteService.createNewNote({
2022-12-01 10:16:57 +01:00
noteId: launcher.id,
title: launcher.title,
type: 'launcher',
2022-08-06 13:47:27 +02:00
content: '',
parentNoteId: parentNoteId
}).note;
2022-12-01 10:16:57 +01:00
if (launcher.icon) {
note.addLabel('iconClass', launcher.icon);
2022-11-28 23:39:23 +01:00
}
2022-08-06 13:47:27 +02:00
2022-12-01 10:16:57 +01:00
if (launcher.command) {
2022-11-29 16:16:57 +01:00
note.addRelation('template', LBTPL_COMMAND);
2022-12-01 10:16:57 +01:00
note.addLabel('command', launcher.command);
} else if (launcher.builtinWidget) {
if (launcher.builtinWidget === 'spacer') {
2022-11-28 23:39:23 +01:00
note.addRelation('template', LBTPL_SPACER);
2022-12-01 10:16:57 +01:00
note.addLabel("baseSize", launcher.baseSize);
note.addLabel("growthFactor", launcher.growthFactor);
2022-11-28 23:39:23 +01:00
} else {
note.addRelation('template', LBTPL_BUILTIN_WIDGET);
}
2022-12-01 10:16:57 +01:00
note.addLabel('builtinWidget', launcher.builtinWidget);
} else if (launcher.targetNoteId) {
note.addRelation('template', LBTPL_NOTE_LAUNCHER);
note.addRelation('targetNote', launcher.targetNoteId);
2022-08-06 13:47:27 +02:00
} else {
2022-12-01 10:16:57 +01:00
throw new Error(`No action defined for launcher ${JSON.stringify(launcher)}`);
2022-08-06 13:47:27 +02:00
}
2022-08-04 23:00:32 +02:00
}
}
2022-12-01 10:16:57 +01:00
function createLauncher(parentNoteId, launcherType) {
2022-08-07 15:34:59 +02:00
let note;
2022-12-01 10:16:57 +01:00
if (launcherType === 'note') {
2022-08-07 15:34:59 +02:00
note = noteService.createNewNote({
2022-12-01 10:16:57 +01:00
title: "Note launcher",
type: 'launcher',
2022-08-07 15:34:59 +02:00
content: '',
parentNoteId: parentNoteId
}).note;
2022-11-29 16:16:57 +01:00
2022-12-01 10:16:57 +01:00
note.addRelation('template', LBTPL_NOTE_LAUNCHER);
} else if (launcherType === 'script') {
2022-08-08 23:13:31 +02:00
note = noteService.createNewNote({
2022-12-01 10:16:57 +01:00
title: "Script launcher",
type: 'launcher',
2022-08-08 23:13:31 +02:00
content: '',
parentNoteId: parentNoteId
}).note;
2022-11-29 16:16:57 +01:00
note.addRelation('template', LBTPL_SCRIPT);
2022-12-01 10:16:57 +01:00
} else if (launcherType === 'customWidget') {
2022-08-07 15:34:59 +02:00
note = noteService.createNewNote({
2022-12-01 10:16:57 +01:00
title: "Widget launcher",
type: 'launcher',
2022-08-07 15:34:59 +02:00
content: '',
parentNoteId: parentNoteId
}).note;
2022-11-29 16:16:57 +01:00
note.addRelation('template', LBTPL_CUSTOM_WIDGET);
2022-12-01 10:16:57 +01:00
} else if (launcherType === 'spacer') {
2022-08-07 15:34:59 +02:00
note = noteService.createNewNote({
title: "Spacer",
2022-12-01 10:16:57 +01:00
type: 'launcher',
2022-08-07 15:34:59 +02:00
content: '',
parentNoteId: parentNoteId
}).note;
2022-08-07 13:23:03 +02:00
2022-11-29 16:16:57 +01:00
note.addRelation('template', LBTPL_SPACER);
2022-08-07 15:34:59 +02:00
} else {
2022-12-01 10:16:57 +01:00
throw new Error(`Unrecognized launcher type ${launcherType}`);
2022-08-07 13:23:03 +02:00
}
2022-08-07 15:34:59 +02:00
return {
success: true,
note
};
2022-08-07 13:23:03 +02:00
}
2022-12-05 23:57:29 +01:00
function initHiddenRoot() {
const hidden = getHiddenRoot();
if (!hidden.hasOwnedLabel("docName")) {
hidden.addLabel("docName", "hidden");
}
if (!hidden.hasOwnedLabel('excludeFromNoteMap')) {
hidden.addLabel('excludeFromNoteMap', "", true);
}
}
2022-12-01 10:16:57 +01:00
function createLauncherTemplates() {
2022-11-28 23:39:23 +01:00
if (!(LBTPL_ROOT in becca.notes)) {
noteService.createNewNote({
branchId: LBTPL_ROOT,
noteId: LBTPL_ROOT,
title: 'Launch bar templates',
type: 'doc',
content: '',
parentNoteId: getHiddenRoot().noteId
});
}
2022-11-30 16:57:51 +01:00
if (!(LBTPL_BASE in becca.notes)) {
2022-12-01 16:22:04 +01:00
noteService.createNewNote({
2022-11-30 16:57:51 +01:00
branchId: LBTPL_BASE,
noteId: LBTPL_BASE,
2022-12-01 10:16:57 +01:00
title: 'Launch bar base launcher',
2022-11-30 16:57:51 +01:00
type: 'doc',
content: '',
2022-12-04 20:05:18 +01:00
parentNoteId: LBTPL_ROOT
2022-12-01 16:22:04 +01:00
});
2022-11-30 16:57:51 +01:00
}
2022-11-29 16:16:57 +01:00
if (!(LBTPL_COMMAND in becca.notes)) {
const tpl = noteService.createNewNote({
branchId: LBTPL_COMMAND,
noteId: LBTPL_COMMAND,
2022-12-01 10:16:57 +01:00
title: 'Command launcher',
2022-11-29 16:16:57 +01:00
type: 'doc',
content: '',
parentNoteId: LBTPL_ROOT
}).note;
2022-11-30 16:57:51 +01:00
tpl.addRelation('template', LBTPL_BASE);
2022-12-01 10:16:57 +01:00
tpl.addLabel('launcherType', 'command');
2022-12-01 16:22:04 +01:00
tpl.addLabel('docName', 'launchbar_command_launcher');
2022-11-29 16:16:57 +01:00
}
2022-12-01 10:16:57 +01:00
if (!(LBTPL_NOTE_LAUNCHER in becca.notes)) {
2022-11-28 23:39:23 +01:00
const tpl = noteService.createNewNote({
2022-12-01 10:16:57 +01:00
branchId: LBTPL_NOTE_LAUNCHER,
noteId: LBTPL_NOTE_LAUNCHER,
title: 'Note launcher',
2022-11-28 23:39:23 +01:00
type: 'doc',
content: '',
parentNoteId: LBTPL_ROOT
}).note;
2022-11-30 16:57:51 +01:00
tpl.addRelation('template', LBTPL_BASE);
2022-12-01 10:16:57 +01:00
tpl.addLabel('launcherType', 'note');
2022-11-28 23:39:23 +01:00
tpl.addLabel('relation:targetNote', 'promoted');
2022-12-01 10:16:57 +01:00
tpl.addLabel('docName', 'launchbar_note_launcher');
2022-12-01 16:22:04 +01:00
tpl.addLabel('label:keyboardShortcut', 'promoted,text');
2022-11-28 23:39:23 +01:00
}
if (!(LBTPL_SCRIPT in becca.notes)) {
const tpl = noteService.createNewNote({
branchId: LBTPL_SCRIPT,
noteId: LBTPL_SCRIPT,
title: 'Script',
type: 'doc',
content: '',
parentNoteId: LBTPL_ROOT
}).note;
2022-11-30 16:57:51 +01:00
tpl.addRelation('template', LBTPL_BASE);
2022-12-01 10:16:57 +01:00
tpl.addLabel('launcherType', 'script');
2022-11-28 23:39:23 +01:00
tpl.addLabel('relation:script', 'promoted');
2022-12-01 10:16:57 +01:00
tpl.addLabel('docName', 'launchbar_script_launcher');
2022-12-01 16:22:04 +01:00
tpl.addLabel('label:keyboardShortcut', 'promoted,text');
2022-11-28 23:39:23 +01:00
}
if (!(LBTPL_BUILTIN_WIDGET in becca.notes)) {
const tpl = noteService.createNewNote({
branchId: LBTPL_BUILTIN_WIDGET,
noteId: LBTPL_BUILTIN_WIDGET,
title: 'Builtin widget',
type: 'doc',
content: '',
parentNoteId: LBTPL_ROOT
}).note;
2022-11-30 16:57:51 +01:00
tpl.addRelation('template', LBTPL_BASE);
2022-12-01 10:16:57 +01:00
tpl.addLabel('launcherType', 'builtinWidget');
2022-11-28 23:39:23 +01:00
}
if (!(LBTPL_SPACER in becca.notes)) {
const tpl = noteService.createNewNote({
branchId: LBTPL_SPACER,
noteId: LBTPL_SPACER,
title: 'Spacer',
type: 'doc',
content: '',
parentNoteId: LBTPL_ROOT
}).note;
tpl.addRelation('template', LBTPL_BUILTIN_WIDGET);
tpl.addLabel('builtinWidget', 'spacer');
tpl.addLabel('iconClass', 'bx bx-move-vertical');
tpl.addLabel('label:baseSize', 'promoted,number');
tpl.addLabel('label:growthFactor', 'promoted,number');
tpl.addLabel('docName', 'launchbar_spacer');
}
if (!(LBTPL_CUSTOM_WIDGET in becca.notes)) {
const tpl = noteService.createNewNote({
branchId: LBTPL_CUSTOM_WIDGET,
noteId: LBTPL_CUSTOM_WIDGET,
title: 'Custom widget',
type: 'doc',
content: '',
parentNoteId: LBTPL_ROOT
}).note;
2022-11-30 16:57:51 +01:00
tpl.addRelation('template', LBTPL_BASE);
2022-12-01 10:16:57 +01:00
tpl.addLabel('launcherType', 'customWidget');
2022-11-28 23:39:23 +01:00
tpl.addLabel('relation:widget', 'promoted');
2022-12-01 10:16:57 +01:00
tpl.addLabel('docName', 'launchbar_widget_launcher');
2022-11-28 23:39:23 +01:00
}
}
2022-12-05 23:57:29 +01:00
const OPTIONS_ROOT = "opt_root";
const OPTIONS_APPEARANCE = "opt_appearance";
function createOptionNotes() {
if (!(OPTIONS_ROOT in becca.notes)) {
noteService.createNewNote({
branchId: OPTIONS_ROOT,
noteId: OPTIONS_ROOT,
title: 'Options',
type: 'doc',
content: '',
parentNoteId: getHiddenRoot().noteId
});
}
if (!(OPTIONS_APPEARANCE in becca.notes)) {
const note = noteService.createNewNote({
branchId: OPTIONS_APPEARANCE,
noteId: OPTIONS_APPEARANCE,
title: 'Appearance',
type: 'content-widget',
2022-12-05 23:57:29 +01:00
content: '',
parentNoteId: OPTIONS_ROOT
}).note;
note.addLabel('contentWidget', 'optionsAppearance');
2022-12-05 23:57:29 +01:00
}
}
function createMissingSpecialNotes() {
initHiddenRoot();
getSqlConsoleRoot();
getGlobalNoteMap();
getBulkActionNote();
createLauncherTemplates();
getLaunchBarRoot();
getLaunchBarAvailableLaunchersRoot();
getLaunchBarVisibleLaunchersRoot();
createLaunchers();
createOptionNotes();
getShareRoot();
}
2022-12-01 10:16:57 +01:00
function resetLauncher(noteId) {
2022-11-25 15:29:57 +01:00
if (noteId.startsWith('lb_')) {
const note = becca.getNote(noteId);
if (note) {
if (noteId === 'lb_root') {
// deleting hoisted notes are not allowed, so we just reset the children
for (const childNote of note.getChildNotes()) {
childNote.deleteNote();
}
} else {
note.deleteNote();
}
} else {
log.info(`Note ${noteId} has not been found and cannot be reset.`);
}
} else {
2022-12-01 10:16:57 +01:00
log.info(`Note ${noteId} is not a resettable launcher note.`);
2022-11-25 15:29:57 +01:00
}
createMissingSpecialNotes();
}
module.exports = {
getInboxNote,
createSqlConsole,
saveSqlConsole,
createSearchNote,
saveSearchNote,
2021-12-20 17:30:47 +01:00
createMissingSpecialNotes,
2022-06-03 17:29:08 +02:00
getShareRoot,
2022-11-06 15:18:32 +01:00
getHiddenRoot,
2022-06-03 17:29:08 +02:00
getBulkActionNote,
2022-12-01 10:16:57 +01:00
createLauncher,
resetLauncher
};