mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-30 03:32:26 +08:00
feat(views/calendar): display child notes of days
This commit is contained in:
parent
f4e6edd19e
commit
bc4d820cb0
@ -67,6 +67,7 @@ export default class CalendarView extends ViewMode {
|
|||||||
private noteIds: string[];
|
private noteIds: string[];
|
||||||
private parentNote: FNote;
|
private parentNote: FNote;
|
||||||
private calendar?: Calendar;
|
private calendar?: Calendar;
|
||||||
|
private isCalendarRoot: boolean;
|
||||||
|
|
||||||
constructor(args: ViewModeArgs) {
|
constructor(args: ViewModeArgs) {
|
||||||
super(args);
|
super(args);
|
||||||
@ -75,7 +76,7 @@ export default class CalendarView extends ViewMode {
|
|||||||
this.$calendarContainer = this.$root.find(".calendar-container");
|
this.$calendarContainer = this.$root.find(".calendar-container");
|
||||||
this.noteIds = args.noteIds;
|
this.noteIds = args.noteIds;
|
||||||
this.parentNote = args.parentNote;
|
this.parentNote = args.parentNote;
|
||||||
console.log(args);
|
this.isCalendarRoot = false;
|
||||||
args.$parent.append(this.$root);
|
args.$parent.append(this.$root);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +98,7 @@ export default class CalendarView extends ViewMode {
|
|||||||
const calendar = new Calendar(this.$calendarContainer[0], {
|
const calendar = new Calendar(this.$calendarContainer[0], {
|
||||||
plugins,
|
plugins,
|
||||||
initialView: "dayGridMonth",
|
initialView: "dayGridMonth",
|
||||||
events: async () => await CalendarView.#buildEvents(this.noteIds),
|
events: async () => await this.#buildEvents(this.noteIds),
|
||||||
editable: isEditable,
|
editable: isEditable,
|
||||||
selectable: isEditable,
|
selectable: isEditable,
|
||||||
select: (e) => this.#onCalendarSelection(e),
|
select: (e) => this.#onCalendarSelection(e),
|
||||||
@ -121,6 +122,7 @@ export default class CalendarView extends ViewMode {
|
|||||||
});
|
});
|
||||||
calendar.render();
|
calendar.render();
|
||||||
this.calendar = calendar;
|
this.calendar = calendar;
|
||||||
|
this.isCalendarRoot = this.parentNote.hasLabel("calendarRoot");
|
||||||
|
|
||||||
return this.$root;
|
return this.$root;
|
||||||
}
|
}
|
||||||
@ -210,17 +212,32 @@ export default class CalendarView extends ViewMode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #buildEvents(noteIds: string[]) {
|
async #buildEvents(noteIds: string[], enforcedStartDate?: string) {
|
||||||
const notes = await froca.getNotes(noteIds);
|
const notes = await froca.getNotes(noteIds);
|
||||||
const events: EventSourceInput = [];
|
const events: EventSourceInput = [];
|
||||||
|
|
||||||
for (const note of notes) {
|
for (const note of notes) {
|
||||||
const startDate = note.getLabelValue("startDate") ?? note.getLabelValue("dateNote");
|
let startDate;
|
||||||
|
|
||||||
|
if (enforcedStartDate) {
|
||||||
|
startDate = enforcedStartDate;
|
||||||
|
} else if (!this.isCalendarRoot) {
|
||||||
|
startDate = note.getLabelValue("startDate");
|
||||||
|
} else {
|
||||||
|
startDate = note.getLabelValue("dateNote");
|
||||||
|
}
|
||||||
const customTitle = note.getAttributeValue("label", "calendar:title");
|
const customTitle = note.getAttributeValue("label", "calendar:title");
|
||||||
const color = note.getAttributeValue("label", "calendar:color") ?? note.getAttributeValue("label", "color") ?? undefined;
|
const color = note.getAttributeValue("label", "calendar:color") ?? note.getAttributeValue("label", "color") ?? undefined;
|
||||||
|
|
||||||
if (note.hasChildren()) {
|
if (note.hasChildren()) {
|
||||||
const childrenEventData = await this.#buildEvents(note.getChildNoteIds());
|
const dateNote = note.getLabelValue("dateNote");
|
||||||
|
let enforcedStartDate = undefined;
|
||||||
|
if (dateNote) {
|
||||||
|
// This is a day note which can have children. Make sure the children are added to the calendar even if they themselves don't have it.
|
||||||
|
enforcedStartDate = dateNote;
|
||||||
|
}
|
||||||
|
|
||||||
|
const childrenEventData = await this.#buildEvents(note.getChildNoteIds(), enforcedStartDate);
|
||||||
if (childrenEventData.length > 0) {
|
if (childrenEventData.length > 0) {
|
||||||
events.push(childrenEventData);
|
events.push(childrenEventData);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user