From 3fe78cad61eb351dc6d7c582e12d339a00ad0dc4 Mon Sep 17 00:00:00 2001 From: "Romain DEP." Date: Sat, 8 Mar 2025 22:17:58 +0100 Subject: [PATCH] feat(calendar): rename "promotedAttributes" into "displayedAttributes" and permit non-promoted attributes to be displayed --- .../app/widgets/view_widgets/calendar_view.ts | 40 +++++-------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/src/public/app/widgets/view_widgets/calendar_view.ts b/src/public/app/widgets/view_widgets/calendar_view.ts index 14f20b60e..c429f4924 100644 --- a/src/public/app/widgets/view_widgets/calendar_view.ts +++ b/src/public/app/widgets/view_widgets/calendar_view.ts @@ -347,10 +347,10 @@ export default class CalendarView extends ViewMode { const color = note.getLabelValue("calendar:color") ?? note.getLabelValue("color"); const events: EventInput[] = []; - const calendarPromotedAttributes = note.getLabelValue("calendar:promotedAttributes"); - let promotedAttributesData = null; - if (calendarPromotedAttributes) { - promotedAttributesData = await this.#buildPromotedAttributes(note, calendarPromotedAttributes); + const calendarDisplayedAttributes = note.getLabelValue("calendar:displayedAttributes")?.split(","); + let displayedAttributesData = null; + if (calendarDisplayedAttributes) { + displayedAttributesData = await this.#buildDisplayedAttributes(note, calendarDisplayedAttributes); } for (const title of titles) { @@ -361,7 +361,7 @@ export default class CalendarView extends ViewMode { noteId: note.noteId, color: color ?? undefined, iconClass: note.getLabelValue("iconClass"), - promotedAttributes: promotedAttributesData + promotedAttributes: displayedAttributesData }; const endDateOffset = CalendarView.#offsetDate(endDate ?? startDate, 1); @@ -373,33 +373,13 @@ export default class CalendarView extends ViewMode { return events; } - static async #buildPromotedAttributes(note: FNote, calendarPromotedAttributes: string) { - const promotedAttributeNames = calendarPromotedAttributes.split(","); - const filteredPromotedAttributes = note.getPromotedDefinitionAttributes().filter((attr) => promotedAttributeNames.includes(attr.name)); + static async #buildDisplayedAttributes(note: FNote, calendarDisplayedAttributes: string[]) { + const filteredDisplayedAttributes = note.getAttributes().filter((attr): boolean => calendarDisplayedAttributes.includes(attr.name)) const result: Record = {}; - for (const promotedAttribute of filteredPromotedAttributes) { - const [type, name] = promotedAttribute.name.split(":", 2); - const definition = promotedAttribute.getDefinition(); - - if (definition.multiplicity !== "single") { - // TODO: Add support for multiple definitions. - continue; - } - - let value: string | undefined | null = null; - - if (type === "label" && note.hasLabel(name)) { - value = note.getLabelValue(name); - } else if (type === "relation" && note.hasRelation(name)) { - const targetNote = await note.getRelationTarget(name); - value = targetNote?.title; - } - - const friendlyName = definition.promotedAlias ?? name; - if (friendlyName && value) { - result[friendlyName] = value; - } + for (const attribute of filteredDisplayedAttributes) { + if (attribute.type === "label") result[attribute.name] = attribute.value; + else result[attribute.name] = (await attribute.getTargetNote())?.title || "" } return result;