Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat: 🎸 add enableWeekNote func
Jin22f1441c4e92
diff --git a/src/public/app/widgets/buttons/calendar.ts b/src/public/app/widgets/buttons/calendar.tsindex 0533bec949..ab73c1329c 100644--- a/src/public/app/widgets/buttons/calendar.ts+++ b/src/public/app/widgets/buttons/calendar.ts@@ -10,6 +10,7 @@ import type { EventData } from "../../components/app_context.js";import dayjs, { Dayjs } from "dayjs";import utc from "dayjs/plugin/utc.js";import isSameOrAfter from "dayjs/plugin/isSameOrAfter.js";+import type BAttribute from "../../../../becca/entities/battribute.js";import "../../../stylesheets/calendar.css";dayjs.extend(utc);@@ -93,6 +94,7 @@ export default class CalendarWidget extends RightDropdownButtonWidget {private activeDate: Dayjs | null = null;private todaysDate!: Dayjs;private date!: Dayjs;+ private weekNoteEnable: boolean = false;constructor(title: string = "", icon: string = "") {super(title, icon, DROPDOWN_TPL);@@ -168,6 +170,27 @@ export default class CalendarWidget extends RightDropdownButtonWidget {ev.stopPropagation();});+ this.$dropdownContent.on("click", ".calendar-week-number", async (ev) => {+ if (!this.weekNoteEnable) {+ return;+ }++ const week = $(ev.target).closest(".calendar-week-number").attr("data-calendar-week-number");++ if (week) {+ const note = await dateNoteService.getWeekNote(week);++ if (note) {+ appContext.tabManager.getActiveContext()?.setNote(note.noteId);+ this.dropdown?.hide();+ } else {+ toastService.showError(t("calendar.cannot_find_week_note"));+ }+ }++ ev.stopPropagation();+ });+// Handle click events for the entire calendar widgetthis.$dropdownContent.on("click", (e) => {const $target = $(e.target);@@ -186,6 +209,19 @@ export default class CalendarWidget extends RightDropdownButtonWidget {});}+ private async getWeekNoteEnable() {+ const noteId = await server.get<string[]>(`search/${encodeURIComponent('#calendarRoot')}`);+ const noteAttributes = await server.get<BAttribute[]>(`notes/${noteId}/attributes`);++ for (const attribute of noteAttributes) {+ if (attribute.name === 'enableWeekNote') {+ this.weekNoteEnable = true;+ return+ }+ }+ this.weekNoteEnable = false;+ }+manageFirstDayOfWeek() {this.firstDayOfWeek = options.getInt("firstDayOfWeek") || 0;@@ -272,6 +308,7 @@ export default class CalendarWidget extends RightDropdownButtonWidget {}async dropdownShown() {+ await this.getWeekNoteEnable();this.init(appContext.tabManager.getActiveContextNote()?.getOwnedLabelValue("dateNote") ?? null);}@@ -308,11 +345,18 @@ export default class CalendarWidget extends RightDropdownButtonWidget {}createWeekNumber(weekNumber: number) {- const weekNumberText = String(weekNumber);- const $newWeekNumber = $("<a>").addClass("calendar-date calendar-week-number").attr("data-calendar-week-number", 'W' + weekNumberText.padStart(2, '0'));- const $weekNumber = $("<span>").html(weekNumberText);+ const weekNoteId = this.date.local().format('YYYY-') + 'W' + String(weekNumber).padStart(2, '0');++ let $newWeekNumber;+ if (this.weekNoteEnable) {+ // Utilize the hover effect of calendar-date+ $newWeekNumber = $("<a>").addClass("calendar-date");+ } else {+ $newWeekNumber = $("<span>").addClass("calendar-week-number-disabled");+ }+ $newWeekNumber.addClass("calendar-week-number").attr("data-calendar-week-number", weekNoteId);+ $newWeekNumber.append($("<span>").html(String(weekNumber)));- $newWeekNumber.append($weekNumber);return $newWeekNumber;}diff --git a/src/public/stylesheets/calendar.css b/src/public/stylesheets/calendar.cssindex 586adb46c3..a3ad89c346 100644--- a/src/public/stylesheets/calendar.css+++ b/src/public/stylesheets/calendar.css@@ -109,6 +109,17 @@z-index: 2;}+.calendar-dropdown-widget .calendar-week-number-disabled {+ align-items: center;+ color: var(--main-text-color);+ display: flex;+ flex-direction: column;+ flex: 0 0 12.5%;+ max-width: 12.5%;+ padding: 0.4rem 0;+ font-size: 120%;+}+.calendar-dropdown-widget .calendar-date {align-items: center;color: var(--main-text-color);diff --git a/src/public/translations/cn/translation.json b/src/public/translations/cn/translation.jsonindex f928eaa3ff..f34cb55004 100644--- a/src/public/translations/cn/translation.json+++ b/src/public/translations/cn/translation.json@@ -589,6 +589,7 @@"sat": "六","sun": "日","cannot_find_day_note": "无法找到日记",+ "cannot_find_week_note": "无法找到周记","january": "一月","febuary": "二月","march": "三月",diff --git a/src/public/translations/en/translation.json b/src/public/translations/en/translation.jsonindex 97b699a740..738a8f8f34 100644--- a/src/public/translations/en/translation.json+++ b/src/public/translations/en/translation.json@@ -589,6 +589,7 @@"sat": "Sat","sun": "Sun","cannot_find_day_note": "Cannot find day note",+ "cannot_find_week_note": "Cannot find week note","january": "January","febuary": "February","march": "March",