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
refactoring of date notes route
zadamb381331029cf
diff --git a/db/TODO.txt b/db/TODO.txtindex 1e2fc2b3fe..727557383d 100644--- a/db/TODO.txt+++ b/db/TODO.txt@@ -8,3 +8,4 @@* readOnly=auto - like without readOnly (used to override inherited readOnly)* readOnly=never - like autoReadOnlyDisabled- remove focusOnAttributesKeyboardShortcut+- rename white theme to "light" theme (it's not completely white and matches well to dark theme)diff --git a/src/services/date_notes.js b/src/services/date_notes.jsindex 9b55224ca4..847354dc82 100644--- a/src/services/date_notes.js+++ b/src/services/date_notes.js@@ -66,26 +66,25 @@ function getYearNote(dateStr, rootNote) {const yearStr = dateStr.substr(0, 4);- let yearNote = attributeService.getNoteWithLabel(YEAR_LABEL, yearStr);+ let yearNote = attributeService.getNoteWithLabel(YEAR_LABEL, yearStr)+ || getNoteStartingWith(rootNote.noteId, yearStr);- if (!yearNote) {- yearNote = getNoteStartingWith(rootNote.noteId, yearStr);+ if (yearNote) {+ return yearNote;+ }- if (!yearNote) {- sql.transactional(() => {- yearNote = createNote(rootNote, yearStr);+ sql.transactional(() => {+ yearNote = createNote(rootNote, yearStr);- attributeService.createLabel(yearNote.noteId, YEAR_LABEL, yearStr);- attributeService.createLabel(yearNote.noteId, 'sorted');+ attributeService.createLabel(yearNote.noteId, YEAR_LABEL, yearStr);+ attributeService.createLabel(yearNote.noteId, 'sorted');- const yearTemplateAttr = rootNote.getOwnedAttribute('relation', 'yearTemplate');+ const yearTemplateAttr = rootNote.getOwnedAttribute('relation', 'yearTemplate');- if (yearTemplateAttr) {- attributeService.createRelation(yearNote.noteId, 'template', yearTemplateAttr.value);- }- });+ if (yearTemplateAttr) {+ attributeService.createRelation(yearNote.noteId, 'template', yearTemplateAttr.value);}- }+ });return yearNote;}@@ -110,30 +109,34 @@ function getMonthNote(dateStr, rootNote) {let monthNote = attributeService.getNoteWithLabel(MONTH_LABEL, monthStr);- if (!monthNote) {- const yearNote = getYearNote(dateStr, rootNote);+ if (monthNote) {+ return monthNote;+ }++ const yearNote = getYearNote(dateStr, rootNote);- monthNote = getNoteStartingWith(yearNote.noteId, monthNumber);+ monthNote = getNoteStartingWith(yearNote.noteId, monthNumber);- if (!monthNote) {- const dateObj = dateUtils.parseLocalDate(dateStr);+ if (monthNote) {+ return monthNote;+ }++ const dateObj = dateUtils.parseLocalDate(dateStr);- const noteTitle = getMonthNoteTitle(rootNote, monthNumber, dateObj);+ const noteTitle = getMonthNoteTitle(rootNote, monthNumber, dateObj);- sql.transactional(() => {- monthNote = createNote(yearNote, noteTitle);+ sql.transactional(() => {+ monthNote = createNote(yearNote, noteTitle);- attributeService.createLabel(monthNote.noteId, MONTH_LABEL, monthStr);- attributeService.createLabel(monthNote.noteId, 'sorted');+ attributeService.createLabel(monthNote.noteId, MONTH_LABEL, monthStr);+ attributeService.createLabel(monthNote.noteId, 'sorted');- const monthTemplateAttr = rootNote.getOwnedAttribute('relation', 'monthTemplate');+ const monthTemplateAttr = rootNote.getOwnedAttribute('relation', 'monthTemplate');- if (monthTemplateAttr) {- attributeService.createRelation(monthNote.noteId, 'template', monthTemplateAttr.value);- }- });+ if (monthTemplateAttr) {+ attributeService.createRelation(monthNote.noteId, 'template', monthTemplateAttr.value);}- }+ });return monthNote;}@@ -152,34 +155,37 @@ function getDateNoteTitle(rootNote, dayNumber, dateObj) {/** @return {Note} */function getDateNote(dateStr) {- const rootNote = getRootCalendarNote();-let dateNote = attributeService.getNoteWithLabel(DATE_LABEL, dateStr);- if (!dateNote) {- const monthNote = getMonthNote(dateStr, rootNote);- const dayNumber = dateStr.substr(8, 2);+ if (dateNote) {+ return dateNote;+ }- dateNote = getNoteStartingWith(monthNote.noteId, dayNumber);+ const rootNote = getRootCalendarNote();+ const monthNote = getMonthNote(dateStr, rootNote);+ const dayNumber = dateStr.substr(8, 2);- if (!dateNote) {- const dateObj = dateUtils.parseLocalDate(dateStr);+ dateNote = getNoteStartingWith(monthNote.noteId, dayNumber);- const noteTitle = getDateNoteTitle(rootNote, dayNumber, dateObj);+ if (dateNote) {+ return dateNote;+ }- sql.transactional(() => {- dateNote = createNote(monthNote, noteTitle);+ const dateObj = dateUtils.parseLocalDate(dateStr);- attributeService.createLabel(dateNote.noteId, DATE_LABEL, dateStr.substr(0, 10));+ const noteTitle = getDateNoteTitle(rootNote, dayNumber, dateObj);- const dateTemplateAttr = rootNote.getOwnedAttribute('relation', 'dateTemplate');+ sql.transactional(() => {+ dateNote = createNote(monthNote, noteTitle);- if (dateTemplateAttr) {- attributeService.createRelation(dateNote.noteId, 'template', dateTemplateAttr.value);- }- });+ attributeService.createLabel(dateNote.noteId, DATE_LABEL, dateStr.substr(0, 10));++ const dateTemplateAttr = rootNote.getOwnedAttribute('relation', 'dateTemplate');++ if (dateTemplateAttr) {+ attributeService.createRelation(dateNote.noteId, 'template', dateTemplateAttr.value);}- }+ });return dateNote;}