Skip to content

Build your personal knowledge base with Trilium Notes

feat(views/calendar): filter notes by ancestor

Elian Doran63584c153cee
diff --git a/src/public/app/widgets/view_widgets/calendar_view.ts b/src/public/app/widgets/view_widgets/calendar_view.ts
index 11e6553ff1..1a861d9b56 100644
--- a/src/public/app/widgets/view_widgets/calendar_view.ts
+++ b/src/public/app/widgets/view_widgets/calendar_view.ts
@@ -238,7 +238,7 @@ export default class CalendarView extends ViewMode {
let allDateNoteIds: string[] = [];
for (const month of dateRange) {
// TODO: Deduplicate get type.
- const dateNotesForMonth = await server.get<Record<string, string>>(`special-notes/notes-for-month/${month}`);
+ const dateNotesForMonth = await server.get<Record<string, string>>(`special-notes/notes-for-month/${month}?calendarRoot=${this.parentNote.noteId}`);
const dateNoteIds = Object.values(dateNotesForMonth);
allDateNoteIds = [ ...allDateNoteIds, ...dateNoteIds ];
}
diff --git a/src/routes/api/special_notes.ts b/src/routes/api/special_notes.ts
index 7a5a1f616d..cf339794bd 100644
--- a/src/routes/api/special_notes.ts
+++ b/src/routes/api/special_notes.ts
@@ -29,8 +29,8 @@ function getYearNote(req: Request) {
function getDayNotesForMonth(req: Request) {
const month = req.params.month;
-
- return sql.getMap(`
+ const calendarRoot = req.query.calendarRoot;
+ const query = `\
SELECT
attr.value AS date,
notes.noteId
@@ -40,7 +40,22 @@ function getDayNotesForMonth(req: Request) {
AND attr.isDeleted = 0
AND attr.type = 'label'
AND attr.name = 'dateNote'
- AND attr.value LIKE '${month}%'`);
+ AND attr.value LIKE '${month}%'`;
+
+ if (calendarRoot) {
+ const rows = sql.getRows<{ date: string, noteId: string }>(query);
+ const result: Record<string, string> = {};
+ for (const {date, noteId} of rows) {
+ const note = becca.getNote(noteId);
+ if (note?.hasAncestor(String(calendarRoot))) {
+ result[date] = noteId;
+ }
+ }
+
+ return result;
+ } else {
+ return sql.getMap(query);
+ }
}
function saveSqlConsole(req: Request) {