From a21c49cba75bb0af3c3811a36004d50c86a803da Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 5 Feb 2022 13:02:19 +0100 Subject: [PATCH] added "hideRelations" label to relation map --- .../app/widgets/attribute_widgets/attribute_detail.js | 2 ++ src/public/app/widgets/note_detail.js | 2 +- src/routes/api/notes.js | 9 +++++++-- src/services/builtin_attributes.js | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/public/app/widgets/attribute_widgets/attribute_detail.js b/src/public/app/widgets/attribute_widgets/attribute_detail.js index fd22207c7..d65d49617 100644 --- a/src/public/app/widgets/attribute_widgets/attribute_detail.js +++ b/src/public/app/widgets/attribute_widgets/attribute_detail.js @@ -215,6 +215,8 @@ const ATTR_HELP = { "shareAlias": "define an alias using which the note will be available under https://your_trilium_host/share/[your_alias]", "shareOmitDefaultCss": "default share page CSS will be omitted. Use when you make extensive styling changes.", "shareRoot": "marks note which is served on /share root.", + "displayRelations": "comma delimited names of relations which should be displayed. All other ones will be hidden.", + "hideRelations": "comma delimited names of relations which should be hidden. All other ones will be displayed.", }, "relation": { "runOnNoteCreation": "executes when note is created on backend", diff --git a/src/public/app/widgets/note_detail.js b/src/public/app/widgets/note_detail.js index 0e2f10a07..dea666515 100644 --- a/src/public/app/widgets/note_detail.js +++ b/src/public/app/widgets/note_detail.js @@ -275,7 +275,7 @@ export default class NoteDetailWidget extends NoteContextAwareWidget { const label = attrs.find(attr => attr.type === 'label' - && ['readOnly', 'autoReadOnlyDisabled', 'cssClass', 'displayRelations'].includes(attr.name) + && ['readOnly', 'autoReadOnlyDisabled', 'cssClass', 'displayRelations', 'hideRelations'].includes(attr.name) && attributeService.isAffecting(attr, this.note)); const relation = attrs.find(attr => diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js index 3a62749a7..f602189e2 100644 --- a/src/routes/api/notes.js +++ b/src/routes/api/notes.js @@ -153,7 +153,10 @@ function getRelationMap(req) { .split(",") .map(token => token.trim()); - console.log("displayRelations", displayRelations); + const hideRelationsVal = relationMapNote.getLabelValue('hideRelations'); + const hideRelations = !hideRelationsVal ? [] : hideRelationsVal + .split(",") + .map(token => token.trim()); const foundNoteIds = sql.getColumn(`SELECT noteId FROM notes WHERE isDeleted = 0 AND noteId IN (${questionMarks})`, noteIds); const notes = becca.getNotes(foundNoteIds); @@ -163,7 +166,9 @@ function getRelationMap(req) { resp.relations = resp.relations.concat(note.getRelations() .filter(relation => !relation.isAutoLink() || displayRelations.includes(relation.name)) - .filter(relation => displayRelations.length === 0 || displayRelations.includes(relation.name)) + .filter(relation => displayRelations.length > 0 + ? displayRelations.includes(relation.name) + : !hideRelations.includes(relation.name)) .filter(relation => noteIds.includes(relation.value)) .map(relation => ({ attributeId: relation.attributeId, diff --git a/src/services/builtin_attributes.js b/src/services/builtin_attributes.js index 51949bb5d..b988cc820 100644 --- a/src/services/builtin_attributes.js +++ b/src/services/builtin_attributes.js @@ -46,6 +46,8 @@ module.exports = [ { type: 'label', name: 'shareAlias' }, { type: 'label', name: 'shareOmitDefaultCss' }, { type: 'label', name: 'shareRoot' }, + { type: 'label', name: 'displayRelations' }, + { type: 'label', name: 'hideRelations' }, // relation names { type: 'relation', name: 'internalLink' },