From 4e3d48fe7d5aff36cf87f8634346ed6f8bf532c5 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 26 Oct 2022 14:23:56 +0200 Subject: [PATCH] allow specifying rootNote for date API functions, #3237 --- docs/backend_api/Branch.html | 2 +- docs/backend_api/Note.html | 2 +- .../backend_api/becca_entities_branch.js.html | 2 +- docs/backend_api/becca_entities_note.js.html | 6 +- docs/frontend_api/NoteShort.html | 116 +++++++++--------- docs/frontend_api/entities_note_short.js.html | 10 +- src/services/backend_script_api.js | 8 +- src/services/date_notes.js | 15 ++- 8 files changed, 88 insertions(+), 73 deletions(-) diff --git a/docs/backend_api/Branch.html b/docs/backend_api/Branch.html index 619545941..332b283dc 100644 --- a/docs/backend_api/Branch.html +++ b/docs/backend_api/Branch.html @@ -1844,7 +1844,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
diff --git a/docs/backend_api/Note.html b/docs/backend_api/Note.html index 9e2361403..3c95422fc 100644 --- a/docs/backend_api/Note.html +++ b/docs/backend_api/Note.html @@ -11746,7 +11746,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
diff --git a/docs/backend_api/becca_entities_branch.js.html b/docs/backend_api/becca_entities_branch.js.html index e8cfd6bc4..fc264138a 100644 --- a/docs/backend_api/becca_entities_branch.js.html +++ b/docs/backend_api/becca_entities_branch.js.html @@ -274,7 +274,7 @@ module.exports = Branch;
diff --git a/docs/backend_api/becca_entities_note.js.html b/docs/backend_api/becca_entities_note.js.html index a3af3312f..d50098ce1 100644 --- a/docs/backend_api/becca_entities_note.js.html +++ b/docs/backend_api/becca_entities_note.js.html @@ -431,7 +431,7 @@ class Note extends AbstractEntity { templateAttributes.push( ...templateNote.__getAttributes(newPath) // template attr is used as a marker for templates, but it's not meant to be inherited - .filter(attr => !(attr.type === 'label' && attr.name === 'template')) + .filter(attr => !(attr.type === 'label' && (attr.name === 'template' || attr.name === 'workspacetemplate'))) ); } } @@ -726,7 +726,7 @@ class Note extends AbstractEntity { // this is done so that non-search & non-archived paths are always explored as first when looking for note path sortParents() { this.parentBranches.sort((a, b) => - a.branchId.startsWith('virt-') + a.branchId.startsWith('virt-') // FIXME: search virtual notes appear only in froca so this is probably not necessary || a.parentNote?.hasInheritableOwnedArchivedLabel() ? 1 : -1); this.parents = this.parentBranches @@ -1378,7 +1378,7 @@ module.exports = Note;
diff --git a/docs/frontend_api/NoteShort.html b/docs/frontend_api/NoteShort.html index c58ad3671..fc95148b8 100644 --- a/docs/frontend_api/NoteShort.html +++ b/docs/frontend_api/NoteShort.html @@ -167,7 +167,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -267,7 +267,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -335,7 +335,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -403,7 +403,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -471,7 +471,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -543,7 +543,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -611,7 +611,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -679,7 +679,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -747,7 +747,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -815,7 +815,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -883,7 +883,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -955,7 +955,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -1103,7 +1103,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -1303,7 +1303,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -1481,7 +1481,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -1589,7 +1589,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -1693,7 +1693,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -1795,7 +1795,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -1897,7 +1897,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -1999,7 +1999,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -2150,7 +2150,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -2317,7 +2317,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -2472,7 +2472,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -2582,7 +2582,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -2756,7 +2756,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -2956,7 +2956,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -3134,7 +3134,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -3289,7 +3289,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -3456,7 +3456,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -3611,7 +3611,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -3766,7 +3766,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -3933,7 +3933,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -4088,7 +4088,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -4194,7 +4194,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -4296,7 +4296,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -4398,7 +4398,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -4500,7 +4500,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -4651,7 +4651,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -4818,7 +4818,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -4973,7 +4973,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -5143,7 +5143,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -5294,7 +5294,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -5400,7 +5400,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -5513,7 +5513,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -5619,7 +5619,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -5721,7 +5721,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -5895,7 +5895,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -6001,7 +6001,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -6152,7 +6152,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -6330,7 +6330,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -6485,7 +6485,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -6640,7 +6640,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -6795,7 +6795,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -6903,7 +6903,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -6987,7 +6987,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -7093,7 +7093,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -7199,7 +7199,7 @@ This note's representation is used in note tree and is kept in Froca.
Source:
@@ -7269,7 +7269,7 @@ This note's representation is used in note tree and is kept in Froca.
diff --git a/docs/frontend_api/entities_note_short.js.html b/docs/frontend_api/entities_note_short.js.html index 6ed141e1b..a63cacf28 100644 --- a/docs/frontend_api/entities_note_short.js.html +++ b/docs/frontend_api/entities_note_short.js.html @@ -32,6 +32,7 @@ import ws from "../services/ws.js"; import options from "../services/options.js"; import froca from "../services/froca.js"; import protectedSessionHolder from "../services/protected_session_holder.js"; +import cssClassManager from "../services/css_class_manager.js"; const LABEL = 'label'; const RELATION = 'relation'; @@ -295,7 +296,7 @@ class NoteShort { attrArrs.push( templateNote.__getCachedAttributes(newPath) // template attr is used as a marker for templates, but it's not meant to be inherited - .filter(attr => !(attr.type === 'label' && attr.name === 'template')) + .filter(attr => !(attr.type === 'label' && (attr.name === 'template' || attr.name === 'workspacetemplate'))) ); } } @@ -452,6 +453,11 @@ class NoteShort { } } + getColorClass() { + const color = this.getLabelValue("color"); + return cssClassManager.createClassForColor(color); + } + isFolder() { return this.type === 'search' || this.getFilteredChildBranches().length > 0; @@ -864,7 +870,7 @@ export default NoteShort;
diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index 0f4f378d8..ec3705e0f 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -332,6 +332,7 @@ function BackendScriptApi(currentNote, apiParams) { * * @method * @param {string} date in YYYY-MM-DD format + * @param {Note} [rootNote] - specify calendar root note, normally leave empty to use default calendar * @returns {Note|null} * @deprecated use getDayNote instead */ @@ -342,6 +343,7 @@ function BackendScriptApi(currentNote, apiParams) { * * @method * @param {string} date in YYYY-MM-DD format + * @param {Note} [rootNote] - specify calendar root note, normally leave empty to use default calendar * @returns {Note|null} */ this.getDayNote = dateNoteService.getDayNote; @@ -350,6 +352,7 @@ function BackendScriptApi(currentNote, apiParams) { * Returns today's day note. If such note doesn't exist, it is created. * * @method + * @param {Note} [rootNote] - specify calendar root note, normally leave empty to use default calendar * @returns {Note|null} */ this.getTodayNote = dateNoteService.getTodayNote; @@ -359,7 +362,8 @@ function BackendScriptApi(currentNote, apiParams) { * * @method * @param {string} date in YYYY-MM-DD format - * @param {object} options - "startOfTheWeek" - either "monday" (default) or "sunday" + * @param {object} [options] - "startOfTheWeek" - either "monday" (default) or "sunday" + * @param {Note} [rootNote] - specify calendar root note, normally leave empty to use default calendar * @returns {Note|null} */ this.getWeekNote = dateNoteService.getWeekNote; @@ -369,6 +373,7 @@ function BackendScriptApi(currentNote, apiParams) { * * @method * @param {string} date in YYYY-MM format + * @param {Note} [rootNote] - specify calendar root note, normally leave empty to use default calendar * @returns {Note|null} */ this.getMonthNote = dateNoteService.getMonthNote; @@ -378,6 +383,7 @@ function BackendScriptApi(currentNote, apiParams) { * * @method * @param {string} year in YYYY format + * @param {Note} [rootNote] - specify calendar root note, normally leave empty to use default calendar * @returns {Note|null} */ this.getYearNote = dateNoteService.getYearNote; diff --git a/src/services/date_notes.js b/src/services/date_notes.js index a541e34e3..3aed9de51 100644 --- a/src/services/date_notes.js +++ b/src/services/date_notes.js @@ -150,8 +150,11 @@ function getDayNoteTitle(rootNote, dayNumber, dateObj) { } /** @returns {Note} */ -function getDayNote(dateStr) { - const rootNote = getRootCalendarNote(); +function getDayNote(dateStr, rootNote = null) { + if (!rootNote) { + rootNote = getRootCalendarNote(); + } + dateStr = dateStr.trim().substr(0, 10); let dateNote = searchService.findFirstNoteWithQuery(`#${DATE_LABEL}="${dateStr}"`, @@ -183,8 +186,8 @@ function getDayNote(dateStr) { return dateNote; } -function getTodayNote() { - return getDayNote(dateUtils.localNowDate()); +function getTodayNote(rootNote = null) { + return getDayNote(dateUtils.localNowDate(), rootNote); } function getStartOfTheWeek(date, startOfTheWeek) { @@ -204,14 +207,14 @@ function getStartOfTheWeek(date, startOfTheWeek) { return new Date(date.setDate(diff)); } -function getWeekNote(dateStr, options = {}) { +function getWeekNote(dateStr, options = {}, rootNote = null) { const startOfTheWeek = options.startOfTheWeek || "monday"; const dateObj = getStartOfTheWeek(dateUtils.parseLocalDate(dateStr), startOfTheWeek); dateStr = dateUtils.utcDateTimeStr(dateObj); - return getDayNote(dateStr); + return getDayNote(dateStr, rootNote); } module.exports = {