From 50009bfb6ea0729a39c15459f6132c568a2feb7a Mon Sep 17 00:00:00 2001 From: Jin <22962980+JYC333@users.noreply.github.com> Date: Tue, 1 Apr 2025 19:13:09 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20frontend=20api=20s?= =?UTF-8?q?upport?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/public/app/services/date_notes.ts | 9 +++++++++ src/public/app/services/frontend_script_api.ts | 18 ++++++++++++++++++ src/routes/api/special_notes.ts | 5 +++++ src/routes/routes.ts | 1 + 4 files changed, 33 insertions(+) diff --git a/src/public/app/services/date_notes.ts b/src/public/app/services/date_notes.ts index 013b900f7..51d8e68a2 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(`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(`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 c20d9dc16..cfcf076cd 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 f2c77a68c..0951deac1 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 4a18ad87c..2f2ff90df 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);