mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-10-29 19:51:31 +08:00
feat(calendar_view): allow rendering by custom relation
This commit is contained in:
parent
10b2d19710
commit
a8509d8b1d
@ -66,7 +66,7 @@ export default class CalendarView extends ViewMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const eventData: typeof events[0] = {
|
const eventData: typeof events[0] = {
|
||||||
title: CalendarView.#parseCustomTitle(customTitle, note),
|
title: (await CalendarView.#parseCustomTitle(customTitle, note))[0],
|
||||||
start: startDate
|
start: startDate
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -83,15 +83,33 @@ export default class CalendarView extends ViewMode {
|
|||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
|
|
||||||
static #parseCustomTitle(customTitleValue: string | null, note: FNote) {
|
static async #parseCustomTitle(customTitleValue: string | null, note: FNote, allowRelations = true): Promise<string[]> {
|
||||||
if (customTitleValue && customTitleValue.startsWith("#")) {
|
if (customTitleValue) {
|
||||||
const labelValue = note.getAttributeValue("label", customTitleValue.substring(1));
|
const attributeName = customTitleValue.substring(1);
|
||||||
|
if (customTitleValue.startsWith("#")) {
|
||||||
|
const labelValue = note.getAttributeValue("label", attributeName);
|
||||||
if (labelValue) {
|
if (labelValue) {
|
||||||
return labelValue;
|
return [ labelValue ];
|
||||||
|
}
|
||||||
|
} else if (allowRelations && customTitleValue.startsWith("~")) {
|
||||||
|
const relations = note.getRelations(attributeName);
|
||||||
|
if (relations.length > 0) {
|
||||||
|
const noteIds = relations.map((r) => r.targetNoteId);
|
||||||
|
const notesFromRelation = await froca.getNotes(noteIds);
|
||||||
|
const titles = [];
|
||||||
|
|
||||||
|
for (const targetNote of notesFromRelation) {
|
||||||
|
const targetCustomTitleValue = targetNote.getAttributeValue("label", "calendar:title");
|
||||||
|
const targetTitles = await CalendarView.#parseCustomTitle(targetCustomTitleValue, targetNote, false);
|
||||||
|
titles.push(targetTitles.flat());
|
||||||
|
}
|
||||||
|
|
||||||
|
return titles.flat();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return note.title;
|
return [ note.title ];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user