refactoring of date notes route

This commit is contained in:
zadam 2021-07-24 11:28:47 +02:00
parent af703445e1
commit b381331029
2 changed files with 73 additions and 66 deletions

View File

@ -8,3 +8,4 @@
* readOnly=auto - like without readOnly (used to override inherited readOnly) * readOnly=auto - like without readOnly (used to override inherited readOnly)
* readOnly=never - like autoReadOnlyDisabled * readOnly=never - like autoReadOnlyDisabled
- remove focusOnAttributesKeyboardShortcut - remove focusOnAttributesKeyboardShortcut
- rename white theme to "light" theme (it's not completely white and matches well to dark theme)

View File

@ -66,12 +66,13 @@ function getYearNote(dateStr, rootNote) {
const yearStr = dateStr.substr(0, 4); 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) { if (yearNote) {
yearNote = getNoteStartingWith(rootNote.noteId, yearStr); return yearNote;
}
if (!yearNote) {
sql.transactional(() => { sql.transactional(() => {
yearNote = createNote(rootNote, yearStr); yearNote = createNote(rootNote, yearStr);
@ -84,8 +85,6 @@ function getYearNote(dateStr, rootNote) {
attributeService.createRelation(yearNote.noteId, 'template', yearTemplateAttr.value); attributeService.createRelation(yearNote.noteId, 'template', yearTemplateAttr.value);
} }
}); });
}
}
return yearNote; return yearNote;
} }
@ -110,12 +109,18 @@ function getMonthNote(dateStr, rootNote) {
let monthNote = attributeService.getNoteWithLabel(MONTH_LABEL, monthStr); let monthNote = attributeService.getNoteWithLabel(MONTH_LABEL, monthStr);
if (!monthNote) { if (monthNote) {
return monthNote;
}
const yearNote = getYearNote(dateStr, rootNote); const yearNote = getYearNote(dateStr, rootNote);
monthNote = getNoteStartingWith(yearNote.noteId, monthNumber); monthNote = getNoteStartingWith(yearNote.noteId, monthNumber);
if (!monthNote) { if (monthNote) {
return monthNote;
}
const dateObj = dateUtils.parseLocalDate(dateStr); const dateObj = dateUtils.parseLocalDate(dateStr);
const noteTitle = getMonthNoteTitle(rootNote, monthNumber, dateObj); const noteTitle = getMonthNoteTitle(rootNote, monthNumber, dateObj);
@ -132,8 +137,6 @@ function getMonthNote(dateStr, rootNote) {
attributeService.createRelation(monthNote.noteId, 'template', monthTemplateAttr.value); attributeService.createRelation(monthNote.noteId, 'template', monthTemplateAttr.value);
} }
}); });
}
}
return monthNote; return monthNote;
} }
@ -152,17 +155,22 @@ function getDateNoteTitle(rootNote, dayNumber, dateObj) {
/** @return {Note} */ /** @return {Note} */
function getDateNote(dateStr) { function getDateNote(dateStr) {
const rootNote = getRootCalendarNote();
let dateNote = attributeService.getNoteWithLabel(DATE_LABEL, dateStr); let dateNote = attributeService.getNoteWithLabel(DATE_LABEL, dateStr);
if (!dateNote) { if (dateNote) {
return dateNote;
}
const rootNote = getRootCalendarNote();
const monthNote = getMonthNote(dateStr, rootNote); const monthNote = getMonthNote(dateStr, rootNote);
const dayNumber = dateStr.substr(8, 2); const dayNumber = dateStr.substr(8, 2);
dateNote = getNoteStartingWith(monthNote.noteId, dayNumber); dateNote = getNoteStartingWith(monthNote.noteId, dayNumber);
if (!dateNote) { if (dateNote) {
return dateNote;
}
const dateObj = dateUtils.parseLocalDate(dateStr); const dateObj = dateUtils.parseLocalDate(dateStr);
const noteTitle = getDateNoteTitle(rootNote, dayNumber, dateObj); const noteTitle = getDateNoteTitle(rootNote, dayNumber, dateObj);
@ -178,8 +186,6 @@ function getDateNote(dateStr) {
attributeService.createRelation(dateNote.noteId, 'template', dateTemplateAttr.value); attributeService.createRelation(dateNote.noteId, 'template', dateTemplateAttr.value);
} }
}); });
}
}
return dateNote; return dateNote;
} }