From 3fe78cad61eb351dc6d7c582e12d339a00ad0dc4 Mon Sep 17 00:00:00 2001 From: "Romain DEP." Date: Sat, 8 Mar 2025 22:17:58 +0100 Subject: [PATCH 1/4] 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; From 6c1cb71c9fbdd5cff1dbef8c3e1fe68a7ebe331d Mon Sep 17 00:00:00 2001 From: "Romain DEP." Date: Sun, 9 Mar 2025 13:03:15 +0100 Subject: [PATCH 2/4] feat(calendar): make it so that events with customized `calendar:startDate` and `calendar:endDate` can be drag&dropped on the calendar view --- src/public/app/widgets/view_widgets/calendar_view.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/public/app/widgets/view_widgets/calendar_view.ts b/src/public/app/widgets/view_widgets/calendar_view.ts index c429f4924..5510f0412 100644 --- a/src/public/app/widgets/view_widgets/calendar_view.ts +++ b/src/public/app/widgets/view_widgets/calendar_view.ts @@ -229,8 +229,13 @@ export default class CalendarView extends ViewMode { return; } - attributes.setAttribute(note, "label", "startDate", startDate); - attributes.setAttribute(note, "label", "endDate", endDate); + // Since they can be customized via calendar:startDate=$foo and calendar:endDate=$bar we need to determine the + // attributes to be effectively updated + const startAttribute = note.getAttributes("label").filter(attr => attr.name == "calendar:startDate").shift()?.value.replace("#", "")||"startDate" + const endAttribute = note.getAttributes("label").filter(attr => attr.name == "calendar:endDate").shift()?.value.replace("#", "")||"endDate" + + attributes.setAttribute(note, "label", startAttribute, startDate); + attributes.setAttribute(note, "label", endAttribute, endDate); } onEntitiesReloaded({ loadResults }: EventData<"entitiesReloaded">) { From 85917d7207ba7bb7ea99f00e28fe8c3f33fafc74 Mon Sep 17 00:00:00 2001 From: "Romain DEP." Date: Sun, 9 Mar 2025 21:26:41 +0100 Subject: [PATCH 3/4] feat(calendar): support displaying of attributes and realtions with multiple cardinality --- src/public/app/widgets/view_widgets/calendar_view.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/public/app/widgets/view_widgets/calendar_view.ts b/src/public/app/widgets/view_widgets/calendar_view.ts index 5510f0412..3ce0a90e3 100644 --- a/src/public/app/widgets/view_widgets/calendar_view.ts +++ b/src/public/app/widgets/view_widgets/calendar_view.ts @@ -138,7 +138,7 @@ export default class CalendarView extends ViewMode { // Promoted attributes if (promotedAttributes) { - for (const [name, value] of Object.entries(promotedAttributes)) { + for (const [name, value] of promotedAttributes) { html += `\