small script API additions

This commit is contained in:
zadam 2019-11-27 23:07:10 +01:00
parent 0415efd33b
commit 1c057cac75
7 changed files with 307 additions and 9 deletions

View File

@ -396,7 +396,7 @@ the backend.
<dt class="tag-source">Source:</dt> <dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li> <dd class="tag-source"><ul class="dummy"><li>
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line327">line 327</a> <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line335">line 335</a>
</li></ul></dd> </li></ul></dd>
@ -1531,7 +1531,7 @@ JSON MIME type. See also createNote() for more options.
<dt class="tag-source">Source:</dt> <dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li> <dd class="tag-source"><ul class="dummy"><li>
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line332">line 332</a> <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line340">line 340</a>
</li></ul></dd> </li></ul></dd>
@ -2763,7 +2763,7 @@ if some action needs to happen on only one specific instance.
<dt class="tag-source">Source:</dt> <dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li> <dd class="tag-source"><ul class="dummy"><li>
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line274">line 274</a> <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line282">line 282</a>
</li></ul></dd> </li></ul></dd>
@ -3441,6 +3441,112 @@ if some action needs to happen on only one specific instance.
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.&lt;(<a href="Note.html">Note</a>|null)></span>
</dd>
</dl>
<h4 class="name" id="getTodayNote"><span class="type-signature"></span>getTodayNote<span class="signature">()</span><span class="type-signature"> &rarr; {Promise.&lt;(<a href="Note.html">Note</a>|null)>}</span></h4>
<div class="description">
Returns today's day note. If such note doesn't exist, it is created.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line263">line 263</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5> <h5>Returns:</h5>
@ -3594,7 +3700,7 @@ if some action needs to happen on only one specific instance.
<dt class="tag-source">Source:</dt> <dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li> <dd class="tag-source"><ul class="dummy"><li>
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line265">line 265</a> <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line273">line 273</a>
</li></ul></dd> </li></ul></dd>
@ -3749,7 +3855,7 @@ if some action needs to happen on only one specific instance.
<dt class="tag-source">Source:</dt> <dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li> <dd class="tag-source"><ul class="dummy"><li>
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line283">line 283</a> <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line291">line 291</a>
</li></ul></dd> </li></ul></dd>
@ -4402,7 +4508,7 @@ This method looks similar to toggleNoteInParent() but differs because we're look
<dt class="tag-source">Source:</dt> <dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li> <dd class="tag-source"><ul class="dummy"><li>
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line304">line 304</a> <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line312">line 312</a>
</li></ul></dd> </li></ul></dd>
@ -4535,7 +4641,7 @@ This method looks similar to toggleNoteInParent() but differs because we're look
<dt class="tag-source">Source:</dt> <dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li> <dd class="tag-source"><ul class="dummy"><li>
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line290">line 290</a> <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line298">line 298</a>
</li></ul></dd> </li></ul></dd>
@ -4910,7 +5016,7 @@ transactional by default.
<dt class="tag-source">Source:</dt> <dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li> <dd class="tag-source"><ul class="dummy"><li>
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line317">line 317</a> <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line325">line 325</a>
</li></ul></dd> </li></ul></dd>

View File

@ -5523,6 +5523,156 @@ Cache is note instance scoped.
<h4 class="name" id="isDescendantOfNote"><span class="type-signature">(async) </span>isDescendantOfNote<span class="signature">(ancestorNoteId)</span><span class="type-signature"> &rarr; {Promise.&lt;boolean>}</span></h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>ancestorNoteId</code></td>
<td class="type">
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line785">line 785</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
- true if ancestorNoteId occurs in at least one of the note's paths
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.&lt;boolean></span>
</dd>
</dl>

View File

@ -806,6 +806,16 @@ class Note extends Entity {
return notePaths; return notePaths;
} }
/**
* @param ancestorNoteId
* @return {Promise&lt;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() { beforeSaving() {
if (!this.isDeleted) { if (!this.isDeleted) {
this.isDeleted = false; this.isDeleted = false;
@ -846,6 +856,7 @@ class Note extends Entity {
delete pojo.isContentAvailable; delete pojo.isContentAvailable;
delete pojo.__attributeCache; delete pojo.__attributeCache;
delete pojo.content; delete pojo.content;
/** zero references to contentHash, probably can be removed */
delete pojo.contentHash; delete pojo.contentHash;
} }
} }

View File

@ -282,6 +282,14 @@ function BackendScriptApi(currentNote, apiParams) {
*/ */
this.getDateNote = dateNoteService.getDateNote; this.getDateNote = dateNoteService.getDateNote;
/**
* Returns today's day note. If such note doesn't exist, it is created.
*
* @method
* @returns {Promise&lt;Note|null>}
*/
this.getTodayNote = dateNoteService.getTodayNote;
/** /**
* Returns note for the first date of the week of the given date. * Returns note for the first date of the week of the given date.
* *

View File

@ -778,6 +778,16 @@ class Note extends Entity {
return notePaths; 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() { beforeSaving() {
if (!this.isDeleted) { if (!this.isDeleted) {
this.isDeleted = false; this.isDeleted = false;

View File

@ -254,6 +254,14 @@ function BackendScriptApi(currentNote, apiParams) {
*/ */
this.getDateNote = dateNoteService.getDateNote; 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. * Returns note for the first date of the week of the given date.
* *

View File

@ -170,6 +170,10 @@ async function getDateNote(dateStr) {
return dateNote; return dateNote;
} }
async function getTodayNote() {
return await getDateNote(dateUtils.localNowDate());
}
function getStartOfTheWeek(date, startOfTheWeek) { function getStartOfTheWeek(date, startOfTheWeek) {
const day = date.getDay(); const day = date.getDay();
let diff; let diff;
@ -202,5 +206,6 @@ module.exports = {
getYearNote, getYearNote,
getMonthNote, getMonthNote,
getWeekNote, getWeekNote,
getDateNote getDateNote,
getTodayNote
}; };