From d34a0a9fc0840b675445f4aaae69c685252db249 Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 16 Dec 2022 16:00:49 +0100 Subject: [PATCH] hidden subtree is not archived anymore --- .../0208__remove_archived_from_hidden.js | 13 +++++ src/etapi/validators.js | 4 +- src/public/app/entities/note_short.js | 2 + src/public/app/widgets/note_tree.js | 9 ++-- src/services/app_info.js | 2 +- src/services/consistency_checks.js | 2 +- src/services/hidden_subtree.js | 9 ++-- src/services/hoisted_note.js | 2 + src/services/note_types.js | 48 ++++++++++++------- src/services/notes.js | 15 +----- 10 files changed, 64 insertions(+), 42 deletions(-) create mode 100644 db/migrations/0208__remove_archived_from_hidden.js diff --git a/db/migrations/0208__remove_archived_from_hidden.js b/db/migrations/0208__remove_archived_from_hidden.js new file mode 100644 index 000000000..52089ee6b --- /dev/null +++ b/db/migrations/0208__remove_archived_from_hidden.js @@ -0,0 +1,13 @@ +module.exports = () => { + const cls = require("../../src/services/cls"); + const beccaLoader = require("../../src/becca/becca_loader"); + const becca = require("../../src/becca/becca"); + + cls.init(() => { + beccaLoader.load(); + + for (const label of becca.getNote('hidden').getLabels('archived')) { + label.markAsDeleted('0208__remove_archived_from_hidden'); + } + }); +}; diff --git a/src/etapi/validators.js b/src/etapi/validators.js index 73f8ac311..797b61761 100644 --- a/src/etapi/validators.js +++ b/src/etapi/validators.js @@ -1,4 +1,4 @@ -const noteTypes = require("../services/note_types"); +const noteTypeService = require("../services/note_types"); function mandatory(obj) { if (obj === undefined ) { @@ -63,6 +63,8 @@ function isNoteType(obj) { return; } + const noteTypes = noteTypeService.getNoteTypeNames(); + if (!noteTypes.includes(obj)) { return `'${obj}' is not a valid note type, allowed types are: ` + noteTypes.join(", "); } diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.js index be7a549bb..6635d3a3d 100644 --- a/src/public/app/entities/note_short.js +++ b/src/public/app/entities/note_short.js @@ -354,6 +354,8 @@ class NoteShort { return a.isSearch ? 1 : -1; } else if (a.isArchived !== b.isArchived) { return a.isArchived ? 1 : -1; + } else if (a.isHidden !== b.isHidden) { + return a.isHidden ? 1 : -1; } else { return a.notePath.length - b.notePath.length; } diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index 6a277c2ee..1f48844d6 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -605,11 +605,12 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { this.$tree.on('contextmenu', '.fancytree-node', e => { const node = $.ui.fancytree.getNode(e); + const note = froca.getNoteFromCache(node.data.noteId); - if (hoistedNoteService.getHoistedNoteId() === 'lbRoot') { - import("../menus/launcher_context_menu.js").then(({LauncherContextMenu: ShortcutContextMenu}) => { - const shortcutContextMenu = new LauncherContextMenu(this, node); - shortcutContextMenu.show(e); + if (note.isLaunchBarConfig()) { + import("../menus/launcher_context_menu.js").then(({default: LauncherContextMenu}) => { + const launcherContextMenu = new LauncherContextMenu(this, node); + launcherContextMenu.show(e); }); } else { import("../menus/tree_context_menu.js").then(({default: TreeContextMenu}) => { diff --git a/src/services/app_info.js b/src/services/app_info.js index aefd41886..c7c3e5949 100644 --- a/src/services/app_info.js +++ b/src/services/app_info.js @@ -4,7 +4,7 @@ const build = require('./build'); const packageJson = require('../../package'); const {TRILIUM_DATA_DIR} = require('./data_dir'); -const APP_DB_VERSION = 207; +const APP_DB_VERSION = 208; const SYNC_VERSION = 28; const CLIPPER_PROTOCOL_VERSION = "1.0"; diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js index 2b3b344e0..2d7230879 100644 --- a/src/services/consistency_checks.js +++ b/src/services/consistency_checks.js @@ -13,7 +13,7 @@ const attributeService = require('./attributes'); const noteRevisionService = require('./note_revisions'); const becca = require("../becca/becca"); const utils = require("../services/utils"); -const noteTypes = require("../services/note_types"); +const noteTypes = require("../services/note_types").getNoteTypeNames(); class ConsistencyChecks { constructor(autoFix) { diff --git a/src/services/hidden_subtree.js b/src/services/hidden_subtree.js index 4058df1bc..cb0043184 100644 --- a/src/services/hidden_subtree.js +++ b/src/services/hidden_subtree.js @@ -4,9 +4,9 @@ const log = require("./log"); const LBTPL_ROOT = "lbTplRoot"; const LBTPL_BASE = "lbTplBase"; -const LBTPL_COMMAND = "lbTplCommand"; +const LBTPL_COMMAND = "lbTplCommandLauncher"; const LBTPL_NOTE_LAUNCHER = "lbTplNoteLauncher"; -const LBTPL_SCRIPT = "lbTplScript"; +const LBTPL_SCRIPT = "lbTplScriptLauncher"; const LBTPL_BUILTIN_WIDGET = "lbTplBuiltinWidget"; const LBTPL_SPACER = "lbTplSpacer"; const LBTPL_CUSTOM_WIDGET = "lbTplCustomWidget"; @@ -20,9 +20,6 @@ const HIDDEN_SUBTREE_DEFINITION = { // over tree when it's in the middle notePosition: 999_999_999, attributes: [ - // isInheritable: false means that this notePath is automatically not preffered but at the same time - // the flag is not inherited to the children - { type: 'label', name: 'archived' }, { type: 'label', name: 'excludeFromNoteMap', isInheritable: true } ], children: [ @@ -283,7 +280,7 @@ function checkHiddenSubtreeRecursively(parentNoteId, item) { if (!branch) { // not sure if there's some better way to recover - log.error(`Cannot find branch id='${item.id}', ignoring...`); + log.error(`Cannot find launcher branch id='${item.id}', ignoring...`); } else { if (item.notePosition !== undefined && branch.notePosition !== item.notePosition) { branch.notePosition = item.notePosition; diff --git a/src/services/hoisted_note.js b/src/services/hoisted_note.js index 9b4d2f023..0e38b895c 100644 --- a/src/services/hoisted_note.js +++ b/src/services/hoisted_note.js @@ -10,6 +10,8 @@ function isHoistedInHiddenSubtree() { if (hoistedNoteId === 'root') { return false; + } else if (hoistedNoteId === 'hidden') { + return true; } const hoistedNote = becca.getNote(hoistedNoteId); diff --git a/src/services/note_types.js b/src/services/note_types.js index 6e970f2d3..65c715e6e 100644 --- a/src/services/note_types.js +++ b/src/services/note_types.js @@ -1,17 +1,33 @@ -module.exports = [ - 'text', - 'code', - 'render', - 'file', - 'image', - 'search', - 'relationMap', - 'book', - 'noteMap', - 'mermaid', - 'canvas', - 'webView', - 'launcher', - 'doc', - 'contentWidget' +const noteTypes = [ + { type: 'text', defaultMime: 'text/html' }, + { type: 'code', defaultMime: 'text/plain' }, + { type: 'render', defaultMime: '' }, + { type: 'file', defaultMime: 'application/octet-stream' }, + { type: 'image', defaultMime: '' }, + { type: 'search', defaultMime: '' }, + { type: 'relationMap', defaultMime: 'application/json' }, + { type: 'book', defaultMime: '' }, + { type: 'noteMap', defaultMime: '' }, + { type: 'mermaid', defaultMime: 'text/plain' }, + { type: 'canvas', defaultMime: 'application/json' }, + { type: 'webView', defaultMime: '' }, + { type: 'launcher', defaultMime: '' }, + { type: 'doc', defaultMime: '' }, + { type: 'contentWidget', defaultMime: '' } ]; + +function getDefaultMimeForNoteType(typeName) { + const typeRec = noteTypes.find(nt => nt.type === typeName); + + if (!typeRec) { + throw new Error(`Cannot find note type '${typeName}'`); + } + + return typeRec.defaultMime; +} + +module.exports = { + getNoteTypes: () => noteTypes, + getNoteTypeNames: () => noteTypes.map(nt => nt.type), + getDefaultMimeForNoteType +}; diff --git a/src/services/notes.js b/src/services/notes.js index aa7bc5c26..d74e96075 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -20,6 +20,7 @@ const Attribute = require('../becca/entities/attribute'); const dayjs = require("dayjs"); const htmlSanitizer = require("./html_sanitizer"); const ValidationError = require("../errors/validation_error"); +const noteTypesService = require("./note_types"); function getNewNotePosition(parentNoteId) { const note = becca.notes[parentNoteId]; @@ -47,19 +48,7 @@ function deriveMime(type, mime) { return mime; } - if (type === 'text') { - mime = 'text/html'; - } else if (type === 'code' || type === 'mermaid') { - mime = 'text/plain'; - } else if (['relationMap', 'search', 'canvas'].includes(type)) { - mime = 'application/json'; - } else if (['render', 'book', 'webView'].includes(type)) { - mime = ''; - } else { - mime = 'application/octet-stream'; - } - - return mime; + return noteTypesService.getDefaultMimeForNoteType(type); } function copyChildAttributes(parentNote, childNote) {