Skip to content

Build your personal knowledge base with Trilium Notes

feat: 🎸 add frontend api support

Jin50009bfb6ea0
diff --git a/src/public/app/services/date_notes.ts b/src/public/app/services/date_notes.ts
index 013b900f7b..51d8e68a2e 100644
--- a/src/public/app/services/date_notes.ts
+++ b/src/public/app/services/date_notes.ts
@@ -46,6 +46,14 @@ async function getMonthNote(month: string) {
return await froca.getNote(note.noteId);
}
+async function getQuarterNote(quarter: string) {
+ const note = await server.get<FNoteRow>(`special-notes/quarters/${quarter}`, "date-note");
+
+ await ws.waitForMaxKnownEntityChangeId();
+
+ return await froca.getNote(note.noteId);
+}
+
async function getYearNote(year: string) {
const note = await server.get<FNoteRow>(`special-notes/years/${year}`, "date-note");
@@ -76,6 +84,7 @@ export default {
getDayNote,
getWeekFirstDayNote,
getWeekNote,
+ getQuarterNote,
getMonthNote,
getYearNote,
createSqlConsole,
diff --git a/src/public/app/services/frontend_script_api.ts b/src/public/app/services/frontend_script_api.ts
index c20d9dc167..cfcf076cd3 100644
--- a/src/public/app/services/frontend_script_api.ts
+++ b/src/public/app/services/frontend_script_api.ts
@@ -365,6 +365,14 @@ interface Api {
*/
getWeekFirstDayNote: typeof dateNotesService.getWeekFirstDayNote;
+ /**
+ * Returns week note for given date. If such a note doesn't exist, it is automatically created.
+ *
+ * @param date in YYYY-MM-DD format
+ * @param rootNote - specify calendar root note, normally leave empty to use the default calendar
+ */
+ getWeekNote: typeof dateNotesService.getWeekNote;
+
/**
* Returns month-note. If it doesn't exist, it is automatically created.
*
@@ -372,6 +380,14 @@ interface Api {
*/
getMonthNote: typeof dateNotesService.getMonthNote;
+ /**
+ * Returns quarter note for given date. If such a note doesn't exist, it is automatically created.
+ *
+ * @param date in YYYY-MM format
+ * @param rootNote - specify calendar root note, normally leave empty to use the default calendar
+ */
+ getQuarterNote: typeof dateNotesService.getQuarterNote;
+
/**
* Returns year-note. If it doesn't exist, it is automatically created.
*
@@ -652,7 +668,9 @@ function FrontendScriptApi(this: Api, startNote: FNote, currentNote: FNote, orig
this.getTodayNote = dateNotesService.getTodayNote;
this.getDayNote = dateNotesService.getDayNote;
this.getWeekFirstDayNote = dateNotesService.getWeekFirstDayNote;
+ this.getWeekNote = dateNotesService.getWeekNote;
this.getMonthNote = dateNotesService.getMonthNote;
+ this.getQuarterNote = dateNotesService.getQuarterNote;
this.getYearNote = dateNotesService.getYearNote;
this.setHoistedNoteId = (noteId) => {
diff --git a/src/routes/api/special_notes.ts b/src/routes/api/special_notes.ts
index f2c77a68c5..0951deac19 100644
--- a/src/routes/api/special_notes.ts
+++ b/src/routes/api/special_notes.ts
@@ -25,6 +25,10 @@ function getMonthNote(req: Request) {
return dateNoteService.getMonthNote(req.params.month);
}
+function getQuarterNote(req: Request) {
+ return dateNoteService.getQuarterNote(req.params.quarter);
+}
+
function getYearNote(req: Request) {
return dateNoteService.getYearNote(req.params.year);
}
@@ -106,6 +110,7 @@ export default {
getWeekFirstDayNote,
getWeekNote,
getMonthNote,
+ getQuarterNote,
getYearNote,
getDayNotesForMonth,
createSqlConsole,
diff --git a/src/routes/routes.ts b/src/routes/routes.ts
index 4a18ad87c5..2f2ff90dfa 100644
--- a/src/routes/routes.ts
+++ b/src/routes/routes.ts
@@ -308,6 +308,7 @@ function register(app: express.Application) {
apiRoute(GET, "/api/special-notes/week-first-day/:date", specialNotesRoute.getWeekFirstDayNote);
apiRoute(GET, "/api/special-notes/weeks/:week", specialNotesRoute.getWeekNote);
apiRoute(GET, "/api/special-notes/months/:month", specialNotesRoute.getMonthNote);
+ apiRoute(GET, "/api/special-notes/quarters/:quarter", specialNotesRoute.getQuarterNote);
apiRoute(GET, "/api/special-notes/years/:year", specialNotesRoute.getYearNote);
apiRoute(GET, "/api/special-notes/notes-for-month/:month", specialNotesRoute.getDayNotesForMonth);
apiRoute(PST, "/api/special-notes/sql-console", specialNotesRoute.createSqlConsole);