mirror of
https://github.com/zadam/trilium.git
synced 2025-01-16 03:58:53 +08:00
allow showing inherited attributes in the sidebar as well
This commit is contained in:
parent
c0c36d10e5
commit
7bee93bb73
1 changed files with 48 additions and 22 deletions
|
@ -32,34 +32,60 @@ class AttributesWidget {
|
||||||
const ownedAttributes = attributes.filter(attr => attr.noteId === this.ctx.note.noteId);
|
const ownedAttributes = attributes.filter(attr => attr.noteId === this.ctx.note.noteId);
|
||||||
|
|
||||||
if (ownedAttributes.length === 0) {
|
if (ownedAttributes.length === 0) {
|
||||||
$body.text("No attributes yet...");
|
$body.text("No own attributes yet...");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ownedAttributes.length > 0) {
|
await this.renderAttributes(ownedAttributes, $body);
|
||||||
for (const attribute of ownedAttributes) {
|
|
||||||
|
const inheritedAttributes = attributes.filter(attr => attr.noteId !== this.ctx.note.noteId);
|
||||||
|
|
||||||
|
if (inheritedAttributes.length > 0) {
|
||||||
|
const $inheritedAttrs = $("<span>").append($("<strong>").text("Inherited: "));
|
||||||
|
const $showInheritedAttributes = $("<a>")
|
||||||
|
.attr("href", "javascript:")
|
||||||
|
.text("+show inherited")
|
||||||
|
.click(() => {
|
||||||
|
$showInheritedAttributes.hide();
|
||||||
|
$inheritedAttrs.show();
|
||||||
|
});
|
||||||
|
|
||||||
|
const $hideInheritedAttributes = $("<a>")
|
||||||
|
.attr("href", "javascript:")
|
||||||
|
.text("-hide inherited")
|
||||||
|
.click(() => {
|
||||||
|
$showInheritedAttributes.show();
|
||||||
|
$inheritedAttrs.hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
$body.append($showInheritedAttributes);
|
||||||
|
$body.append($inheritedAttrs);
|
||||||
|
|
||||||
|
await this.renderAttributes(inheritedAttributes, $inheritedAttrs);
|
||||||
|
|
||||||
|
$inheritedAttrs.append($hideInheritedAttributes);
|
||||||
|
$inheritedAttrs.hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async renderAttributes(attributes, $container) {
|
||||||
|
for (const attribute of attributes) {
|
||||||
if (attribute.type === 'label') {
|
if (attribute.type === 'label') {
|
||||||
$body.append(utils.formatLabel(attribute) + " ");
|
$container.append(utils.formatLabel(attribute) + " ");
|
||||||
}
|
} else if (attribute.type === 'relation') {
|
||||||
else if (attribute.type === 'relation') {
|
|
||||||
if (attribute.value) {
|
if (attribute.value) {
|
||||||
$body.append('@' + attribute.name + "=");
|
$container.append('@' + attribute.name + "=");
|
||||||
$body.append(await linkService.createNoteLink(attribute.value));
|
$container.append(await linkService.createNoteLink(attribute.value));
|
||||||
$body.append(" ");
|
$container.append(" ");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
messagingService.logError(`Relation ${attribute.attributeId} has empty target`);
|
messagingService.logError(`Relation ${attribute.attributeId} has empty target`);
|
||||||
}
|
}
|
||||||
}
|
} else if (attribute.type === 'label-definition' || attribute.type === 'relation-definition') {
|
||||||
else if (attribute.type === 'label-definition' || attribute.type === 'relation-definition') {
|
$container.append(attribute.name + " definition ");
|
||||||
$body.append(attribute.name + " definition ");
|
} else {
|
||||||
}
|
|
||||||
else {
|
|
||||||
messagingService.logError("Unknown attr type: " + attribute.type);
|
messagingService.logError("Unknown attr type: " + attribute.type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AttributesWidget;
|
export default AttributesWidget;
|
Loading…
Reference in a new issue