mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 07:08:55 +02:00
feat(calendar_view): render notes by their start date
This commit is contained in:
parent
4dc2803cc6
commit
64b446315d
@ -1,3 +1,5 @@
|
||||
import type { EventSourceInput } from "@fullcalendar/core";
|
||||
import froca from "../../services/froca.js";
|
||||
import ViewMode, { type ViewModeArgs } from "./view_mode.js";
|
||||
|
||||
const TPL = `
|
||||
@ -25,12 +27,14 @@ export default class CalendarView extends ViewMode {
|
||||
|
||||
private $root: JQuery<HTMLElement>;
|
||||
private $calendarContainer: JQuery<HTMLElement>;
|
||||
private noteIds: string[];
|
||||
|
||||
constructor(args: ViewModeArgs) {
|
||||
super(args);
|
||||
|
||||
this.$root = $(TPL);
|
||||
this.$calendarContainer = this.$root.find(".calendar-container");
|
||||
this.noteIds = args.noteIds;
|
||||
args.$parent.append(this.$root);
|
||||
}
|
||||
|
||||
@ -40,11 +44,32 @@ export default class CalendarView extends ViewMode {
|
||||
|
||||
const calendar = new Calendar(this.$calendarContainer[0], {
|
||||
plugins: [ dayGridPlugin ],
|
||||
initialView: "dayGridMonth"
|
||||
initialView: "dayGridMonth",
|
||||
events: await CalendarView.#buildEvents(this.noteIds)
|
||||
});
|
||||
calendar.render();
|
||||
|
||||
return this.$root;
|
||||
}
|
||||
|
||||
static async #buildEvents(noteIds: string[]) {
|
||||
const notes = await froca.getNotes(noteIds);
|
||||
const events: EventSourceInput = [];
|
||||
|
||||
for (const note of notes) {
|
||||
const startDate = note.getAttributeValue("label", "startDate");
|
||||
|
||||
if (!startDate) {
|
||||
continue;
|
||||
}
|
||||
|
||||
events.push({
|
||||
title: note.title,
|
||||
start: startDate
|
||||
});
|
||||
}
|
||||
|
||||
return events;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user