From 7b0fd639f64874626f0e46c187efe7996eb6cf85 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 23 Jan 2021 21:41:02 +0100 Subject: [PATCH] improved heuristic of displaing attributes in note list and tooltips #1558 --- src/public/app/entities/attribute.js | 4 ++++ src/public/app/entities/note_short.js | 14 ++++++++++++++ src/public/app/services/attribute_renderer.js | 14 +++++++++++++- .../attribute_widgets/promoted_attributes.js | 18 ++---------------- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/public/app/entities/attribute.js b/src/public/app/entities/attribute.js index 70444e888..ec826ecc3 100644 --- a/src/public/app/entities/attribute.js +++ b/src/public/app/entities/attribute.js @@ -89,6 +89,10 @@ class Attribute { return promotedAttributeDefinitionParser.parse(this.value); } + isDefinitionFor(attr) { + return this.type === 'label' && this.name === `${attr.type}:${attr.name}`; + } + get dto() { const dto = Object.assign({}, this); delete dto.treeCache; diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.js index 398a06631..abccf5b87 100644 --- a/src/public/app/entities/note_short.js +++ b/src/public/app/entities/note_short.js @@ -479,6 +479,20 @@ class NoteShort { return relations.map(rel => this.treeCache.notes[rel.value]); } + getPromotedDefinitionAttributes() { + if (this.hasLabel('hidePromotedAttributes')) { + return []; + } + + return this.getAttributes() + .filter(attr => attr.isDefinition()) + .filter(attr => { + const def = attr.getDefinition(); + + return def && def.isPromoted; + }); + } + hasAncestor(ancestorNote) { if (this.noteId === ancestorNote.noteId) { return true; diff --git a/src/public/app/services/attribute_renderer.js b/src/public/app/services/attribute_renderer.js index e8986b513..5212536d2 100644 --- a/src/public/app/services/attribute_renderer.js +++ b/src/public/app/services/attribute_renderer.js @@ -80,7 +80,19 @@ async function renderAttributes(attributes, renderIsInheritable) { } async function renderNormalAttributes(note) { - const attrs = note.getAttributes().filter(attr => !attr.isDefinition() && !attr.isAutoLink); + const promotedDefinitionAttributes = note.getPromotedDefinitionAttributes(); + let attrs = note.getAttributes(); + + if (promotedDefinitionAttributes.length > 0) { + attrs = attrs.filter(attr => !!promotedDefinitionAttributes.find(promAttr => promAttr.isDefinitionFor(attr))); + } + else { + attrs = attrs.filter( + attr => !attr.isDefinition() + && !attr.isAutoLink + && attr.noteId === note.noteId + ); + } const $renderedAttributes = await renderAttributes(attrs, false); diff --git a/src/public/app/widgets/attribute_widgets/promoted_attributes.js b/src/public/app/widgets/attribute_widgets/promoted_attributes.js index 06be5d434..ec2b944ba 100644 --- a/src/public/app/widgets/attribute_widgets/promoted_attributes.js +++ b/src/public/app/widgets/attribute_widgets/promoted_attributes.js @@ -44,7 +44,7 @@ export default class PromotedAttributesWidget extends TabAwareWidget { } renderTitle(note) { - const promotedDefAttrs = this.getPromotedDefinitionAttributes(); + const promotedDefAttrs = note.getPromotedDefinitionAttributes(); if (promotedDefAttrs.length === 0) { return { show: false }; @@ -62,7 +62,7 @@ export default class PromotedAttributesWidget extends TabAwareWidget { async refreshWithNote(note) { this.$container.empty(); - const promotedDefAttrs = this.getPromotedDefinitionAttributes(); + const promotedDefAttrs = note.getPromotedDefinitionAttributes(); const ownedAttributes = note.getOwnedAttributes(); if (promotedDefAttrs.length === 0) { @@ -104,20 +104,6 @@ export default class PromotedAttributesWidget extends TabAwareWidget { this.toggleInt(true); } - getPromotedDefinitionAttributes() { - if (this.note.hasLabel('hidePromotedAttributes')) { - return []; - } - - return this.note.getAttributes() - .filter(attr => attr.isDefinition()) - .filter(attr => { - const def = attr.getDefinition(); - - return def && def.isPromoted; - }); - } - async createPromotedAttributeCell(definitionAttr, valueAttr, valueName) { const definition = definitionAttr.getDefinition();