mirror of
https://github.com/zadam/trilium.git
synced 2025-11-08 06:15:48 +01:00
small script API additions
This commit is contained in:
@@ -778,6 +778,16 @@ class Note extends Entity {
|
||||
return notePaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ancestorNoteId
|
||||
* @return {Promise<boolean>} - true if ancestorNoteId occurs in at least one of the note's paths
|
||||
*/
|
||||
async isDescendantOfNote(ancestorNoteId) {
|
||||
const notePaths = await this.getAllNotePaths();
|
||||
|
||||
return notePaths.some(path => path.includes(ancestorNoteId));
|
||||
}
|
||||
|
||||
beforeSaving() {
|
||||
if (!this.isDeleted) {
|
||||
this.isDeleted = false;
|
||||
|
||||
@@ -254,6 +254,14 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
*/
|
||||
this.getDateNote = dateNoteService.getDateNote;
|
||||
|
||||
/**
|
||||
* Returns today's day note. If such note doesn't exist, it is created.
|
||||
*
|
||||
* @method
|
||||
* @returns {Promise<Note|null>}
|
||||
*/
|
||||
this.getTodayNote = dateNoteService.getTodayNote;
|
||||
|
||||
/**
|
||||
* Returns note for the first date of the week of the given date.
|
||||
*
|
||||
|
||||
@@ -170,6 +170,10 @@ async function getDateNote(dateStr) {
|
||||
return dateNote;
|
||||
}
|
||||
|
||||
async function getTodayNote() {
|
||||
return await getDateNote(dateUtils.localNowDate());
|
||||
}
|
||||
|
||||
function getStartOfTheWeek(date, startOfTheWeek) {
|
||||
const day = date.getDay();
|
||||
let diff;
|
||||
@@ -202,5 +206,6 @@ module.exports = {
|
||||
getYearNote,
|
||||
getMonthNote,
|
||||
getWeekNote,
|
||||
getDateNote
|
||||
getDateNote,
|
||||
getTodayNote
|
||||
};
|
||||
Reference in New Issue
Block a user