mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 04:51:31 +08:00 
			
		
		
		
	feat(calendar): rename "promotedAttributes" into "displayedAttributes" and permit non-promoted attributes to be displayed
This commit is contained in:
		
							parent
							
								
									0232fee905
								
							
						
					
					
						commit
						3fe78cad61
					
				| @ -347,10 +347,10 @@ export default class CalendarView extends ViewMode { | |||||||
|         const color = note.getLabelValue("calendar:color") ?? note.getLabelValue("color"); |         const color = note.getLabelValue("calendar:color") ?? note.getLabelValue("color"); | ||||||
|         const events: EventInput[] = []; |         const events: EventInput[] = []; | ||||||
| 
 | 
 | ||||||
|         const calendarPromotedAttributes = note.getLabelValue("calendar:promotedAttributes"); |         const calendarDisplayedAttributes = note.getLabelValue("calendar:displayedAttributes")?.split(","); | ||||||
|         let promotedAttributesData = null; |         let displayedAttributesData = null; | ||||||
|         if (calendarPromotedAttributes) { |         if (calendarDisplayedAttributes) { | ||||||
|             promotedAttributesData = await this.#buildPromotedAttributes(note, calendarPromotedAttributes); |             displayedAttributesData = await this.#buildDisplayedAttributes(note, calendarDisplayedAttributes); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         for (const title of titles) { |         for (const title of titles) { | ||||||
| @ -361,7 +361,7 @@ export default class CalendarView extends ViewMode { | |||||||
|                 noteId: note.noteId, |                 noteId: note.noteId, | ||||||
|                 color: color ?? undefined, |                 color: color ?? undefined, | ||||||
|                 iconClass: note.getLabelValue("iconClass"), |                 iconClass: note.getLabelValue("iconClass"), | ||||||
|                 promotedAttributes: promotedAttributesData |                 promotedAttributes: displayedAttributesData | ||||||
|             }; |             }; | ||||||
| 
 | 
 | ||||||
|             const endDateOffset = CalendarView.#offsetDate(endDate ?? startDate, 1); |             const endDateOffset = CalendarView.#offsetDate(endDate ?? startDate, 1); | ||||||
| @ -373,33 +373,13 @@ export default class CalendarView extends ViewMode { | |||||||
|         return events; |         return events; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     static async #buildPromotedAttributes(note: FNote, calendarPromotedAttributes: string) { |     static async #buildDisplayedAttributes(note: FNote, calendarDisplayedAttributes: string[]) { | ||||||
|         const promotedAttributeNames = calendarPromotedAttributes.split(","); |         const filteredDisplayedAttributes = note.getAttributes().filter((attr): boolean => calendarDisplayedAttributes.includes(attr.name)) | ||||||
|         const filteredPromotedAttributes = note.getPromotedDefinitionAttributes().filter((attr) => promotedAttributeNames.includes(attr.name)); |  | ||||||
|         const result: Record<string, string> = {}; |         const result: Record<string, string> = {}; | ||||||
| 
 | 
 | ||||||
|         for (const promotedAttribute of filteredPromotedAttributes) { |         for (const attribute of filteredDisplayedAttributes) { | ||||||
|             const [type, name] = promotedAttribute.name.split(":", 2); |             if (attribute.type === "label") result[attribute.name] = attribute.value; | ||||||
|             const definition = promotedAttribute.getDefinition(); |             else result[attribute.name] = (await attribute.getTargetNote())?.title || "" | ||||||
| 
 |  | ||||||
|             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; |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return result; |         return result; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Romain DEP.
						Romain DEP.