added date note APIs to frontend script API

This commit is contained in:
zadam 2019-04-14 12:24:48 +02:00
parent e1e020c1a4
commit 253a6ef081
8 changed files with 1413 additions and 85 deletions

View file

@ -581,7 +581,7 @@
<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#line326">line 326</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line347">line 347</a>
</li></ul></dd>
@ -746,7 +746,7 @@
<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#line195">line 195</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line216">line 216</a>
</li></ul></dd>
@ -922,7 +922,7 @@
<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#line337">line 337</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line358">line 358</a>
</li></ul></dd>
@ -1026,7 +1026,7 @@
<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#line624">line 624</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line645">line 645</a>
</li></ul></dd>
@ -1126,7 +1126,7 @@
<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#line652">line 652</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line673">line 673</a>
</li></ul></dd>
@ -1230,7 +1230,7 @@
<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#line638">line 638</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line659">line 659</a>
</li></ul></dd>
@ -1334,7 +1334,7 @@
<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#line66">line 66</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line75">line 75</a>
</li></ul></dd>
@ -1434,7 +1434,7 @@
<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#line513">line 513</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line534">line 534</a>
</li></ul></dd>
@ -1665,7 +1665,7 @@
<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#line536">line 536</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line557">line 557</a>
</li></ul></dd>
@ -1861,7 +1861,7 @@
<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#line574">line 574</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line595">line 595</a>
</li></ul></dd>
@ -2057,7 +2057,7 @@
<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#line583">line 583</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line604">line 604</a>
</li></ul></dd>
@ -2157,7 +2157,7 @@
<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#line90">line 90</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line111">line 111</a>
</li></ul></dd>
@ -2306,7 +2306,7 @@
<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#line424">line 424</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line445">line 445</a>
</li></ul></dd>
@ -2471,7 +2471,7 @@
<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#line220">line 220</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line241">line 241</a>
</li></ul></dd>
@ -2636,7 +2636,7 @@
<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#line212">line 212</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line233">line 233</a>
</li></ul></dd>
@ -2789,7 +2789,7 @@
<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#line436">line 436</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line457">line 457</a>
</li></ul></dd>
@ -2897,7 +2897,7 @@
<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#line599">line 599</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line620">line 620</a>
</li></ul></dd>
@ -3001,7 +3001,7 @@
<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#line617">line 617</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line638">line 638</a>
</li></ul></dd>
@ -3101,7 +3101,7 @@
<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#line180">line 180</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line201">line 201</a>
</li></ul></dd>
@ -3205,7 +3205,7 @@
<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#line664">line 664</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line685">line 685</a>
</li></ul></dd>
@ -3358,7 +3358,7 @@
<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#line430">line 430</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line451">line 451</a>
</li></ul></dd>
@ -3523,7 +3523,7 @@
<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#line236">line 236</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line257">line 257</a>
</li></ul></dd>
@ -3688,7 +3688,7 @@
<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#line228">line 228</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line249">line 249</a>
</li></ul></dd>
@ -3841,7 +3841,7 @@
<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#line448">line 448</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line469">line 469</a>
</li></ul></dd>
@ -3997,7 +3997,7 @@
<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#line442">line 442</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line463">line 463</a>
</li></ul></dd>
@ -4105,7 +4105,7 @@
<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#line590">line 590</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line611">line 611</a>
</li></ul></dd>
@ -4205,7 +4205,7 @@
<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#line161">line 161</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line182">line 182</a>
</li></ul></dd>
@ -4313,7 +4313,7 @@
<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#line608">line 608</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line629">line 629</a>
</li></ul></dd>
@ -4413,7 +4413,7 @@
<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#line187">line 187</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line208">line 208</a>
</li></ul></dd>
@ -4589,7 +4589,7 @@
<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#line317">line 317</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line338">line 338</a>
</li></ul></dd>
@ -4693,7 +4693,7 @@
<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#line631">line 631</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line652">line 652</a>
</li></ul></dd>
@ -4846,7 +4846,7 @@
<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#line412">line 412</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line433">line 433</a>
</li></ul></dd>
@ -4999,7 +4999,7 @@
<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#line418">line 418</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line439">line 439</a>
</li></ul></dd>
@ -5108,7 +5108,7 @@ Cache is note instance scoped.
<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#line244">line 244</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line265">line 265</a>
</li></ul></dd>
@ -5190,7 +5190,7 @@ Cache is note instance scoped.
<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#line149">line 149</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line170">line 170</a>
</li></ul></dd>
@ -5294,7 +5294,7 @@ Cache is note instance scoped.
<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#line141">line 141</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line162">line 162</a>
</li></ul></dd>
@ -5398,7 +5398,7 @@ Cache is note instance scoped.
<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#line136">line 136</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line157">line 157</a>
</li></ul></dd>
@ -5502,7 +5502,7 @@ Cache is note instance scoped.
<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#line131">line 131</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line152">line 152</a>
</li></ul></dd>
@ -5606,7 +5606,7 @@ Cache is note instance scoped.
<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#line154">line 154</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line175">line 175</a>
</li></ul></dd>
@ -5710,7 +5710,7 @@ Cache is note instance scoped.
<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#line249">line 249</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line270">line 270</a>
</li></ul></dd>
@ -5937,7 +5937,7 @@ Cache is note instance scoped.
<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#line395">line 395</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line416">line 416</a>
</li></ul></dd>
@ -6133,7 +6133,7 @@ Cache is note instance scoped.
<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#line499">line 499</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line520">line 520</a>
</li></ul></dd>
@ -6329,7 +6329,7 @@ Cache is note instance scoped.
<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#line508">line 508</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line529">line 529</a>
</li></ul></dd>
@ -6556,7 +6556,7 @@ Cache is note instance scoped.
<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#line369">line 369</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line390">line 390</a>
</li></ul></dd>
@ -6656,7 +6656,7 @@ Cache is note instance scoped.
<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#line97">line 97</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line118">line 118</a>
</li></ul></dd>
@ -6756,7 +6756,7 @@ Cache is note instance scoped.
<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#line126">line 126</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line147">line 147</a>
</li></ul></dd>
@ -6952,7 +6952,7 @@ Cache is note instance scoped.
<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#line481">line 481</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line502">line 502</a>
</li></ul></dd>
@ -7148,7 +7148,7 @@ Cache is note instance scoped.
<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#line490">line 490</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line511">line 511</a>
</li></ul></dd>
@ -7406,7 +7406,7 @@ Cache is note instance scoped.
<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#line352">line 352</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line373">line 373</a>
</li></ul></dd>
@ -7633,7 +7633,7 @@ Cache is note instance scoped.
<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#line462">line 462</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line483">line 483</a>
</li></ul></dd>
@ -7860,7 +7860,7 @@ Cache is note instance scoped.
<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#line472">line 472</a>
<a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line493">line 493</a>
</li></ul></dd>

View file

@ -90,10 +90,31 @@ class Note extends Entity {
}
}
/*
* Note content has quite special handling - it's not a separate entity, but a lazily loaded
* part of Note entity with it's own sync. Reasons behind this hybrid design has been:
*
* - content can be quite large and it's not necessary to load it / fill memory for any note access even if we don't need a content, especially for bulk operations like search
* - changes in the note metadata or title should not trigger note content sync (so we keep separate utcDateModified and sync rows)
* - but to the user note content and title changes are one and the same - single dateModified (so all changes must go through Note and content is not a separate entity)
*/
/** @returns {Promise&lt;*>} */
async getContent() {
async getContent(silentNotFoundError = false) {
if (this.content === undefined) {
this.content = await sql.getValue(`SELECT content FROM note_contents WHERE noteId = ?`, [this.noteId]);
const res = await sql.getRow(`SELECT content, hash FROM note_contents WHERE noteId = ?`, [this.noteId]);
if (!res) {
if (silentNotFoundError) {
return undefined;
}
else {
throw new Error("Cannot find note content for noteId=" + this.noteId);
}
}
this.content = res.content;
this.contentHash = res.contentHash; // used only for note_fulltext consistency check
if (this.isProtected) {
if (this.isContentAvailable) {
@ -123,6 +144,10 @@ class Note extends Entity {
/** @returns {Promise} */
async setContent(content) {
// force updating note itself so that dateChanged is represented correctly even for the content
this.forcedChange = true;
await this.save();
this.content = content;
const pojo = {
@ -144,10 +169,6 @@ class Note extends Entity {
await sql.upsert("note_contents", "noteId", pojo);
await syncTableService.addNoteContentSync(this.noteId);
this.forcedChange = true;
await this.save();
}
/** @returns {Promise} */
@ -736,6 +757,7 @@ class Note extends Entity {
delete pojo.isContentAvailable;
delete pojo.__attributeCache;
delete pojo.content;
delete pojo.contentHash;
}
async afterSaving() {

File diff suppressed because it is too large Load diff

View file

@ -199,7 +199,7 @@
<h4 class="name" id="utcDateCreated"><span class="type-signature"></span>utcDateCreated<span class="type-signature"></span></h4>
<h4 class="name" id="dateCreated"><span class="type-signature"></span>dateCreated<span class="type-signature"></span></h4>
@ -257,7 +257,7 @@
<h4 class="name" id="utcDateModified"><span class="type-signature"></span>utcDateModified<span class="type-signature"></span></h4>
<h4 class="name" id="dateModified"><span class="type-signature"></span>dateModified<span class="type-signature"></span></h4>
@ -314,6 +314,122 @@
<h4 class="name" id="utcDateCreated"><span class="type-signature"></span>utcDateCreated<span class="type-signature"></span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="entities_note_full.js.html">entities/note_full.js</a>, <a href="entities_note_full.js.html#line20">line 20</a>
</li></ul></dd>
</dl>
<h4 class="name" id="utcDateModified"><span class="type-signature"></span>utcDateModified<span class="type-signature"></span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="entities_note_full.js.html">entities/note_full.js</a>, <a href="entities_note_full.js.html#line23">line 23</a>
</li></ul></dd>
</dl>

View file

@ -38,6 +38,12 @@ class NoteFull extends NoteShort {
/** @param {string} */
this.content = row.content;
/** @param {string} */
this.dateCreated = row.dateCreated;
/** @param {string} */
this.dateModified = row.dateModified;
/** @param {string} */
this.utcDateCreated = row.utcDateCreated;

View file

@ -303,7 +303,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line49">line 49</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line53">line 53</a>
</li></ul></dd>

View file

@ -36,6 +36,7 @@ import noteDetailService from './note_detail.js';
import noteTypeService from './note_type.js';
import noteTooltipService from './note_tooltip.js';
import protectedSessionService from'./protected_session.js';
import dateNotesService from'./date_notes.js';
/**
* This is the main frontend API interface for scripts. It's published in the local "api" object.
@ -53,6 +54,9 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) {
/** @property {object|null} entity whose event triggered this execution */
this.originEntity = originEntity;
// to keep consistency with backend API
this.dayjs = dayjs;
/**
* Activates note in the tree and in the note detail.
*
@ -159,6 +163,14 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) {
}
};
/**
* Returns note by given noteId. If note is missing from cache, it's loaded.
**
* @param {string} noteId
* @return {Promise&lt;NoteShort>}
*/
this.getNote = async noteId => await treeCache.getNote(noteId);
/**
* Returns list of notes. If note is missing from cache, it's loaded.
*
@ -171,6 +183,18 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) {
*/
this.getNotes = async (noteIds, silentNotFoundError = false) => await treeCache.getNotes(noteIds, silentNotFoundError);
/**
* @param {string} noteId
* @method
*/
this.reloadChildren = async noteId => await treeCache.reloadChildren(noteId);
/**
* @param {string} noteId
* @method
*/
this.reloadParents = async noteId => await treeCache.reloadParents(noteId);
/**
* Instance name identifies particular Trilium instance. It can be useful for scripts
* if some action needs to happen on only one specific instance.
@ -238,6 +262,12 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) {
*/
this.getActiveNote = noteDetailService.getActiveNote;
/**
* @method
* @returns {string} returns note path of active note
*/
this.getActiveNotePath = treeService.getActiveNotePath;
/**
* This method checks whether user navigated away from the note from which the scripts has been started.
* This is necessary because script execution is async and by the time it is finished, the user might have
@ -285,6 +315,41 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) {
* @method
*/
this.protectActiveNote = protectedSessionService.protectNoteAndSendToServer;
/**
* Returns date-note for today. If it doesn't exist, it is automatically created.
*
* @method
* @return {Promise&lt;NoteShort>}
*/
this.getTodayNote = dateNotesService.getTodayNote;
/**
* Returns date-note. If it doesn't exist, it is automatically created.
*
* @method
* @param {string} date - e.g. "2019-04-29"
* @return {Promise&lt;NoteShort>}
*/
this.getDateNote = dateNotesService.getDateNote;
/**
* Returns month-note. If it doesn't exist, it is automatically created.
*
* @method
* @param {string} month - e.g. "2019-04"
* @return {Promise&lt;NoteShort>}
*/
this.getMonthNote = dateNotesService.getMonthNote;
/**
* Returns year-note. If it doesn't exist, it is automatically created.
*
* @method
* @param {string} year - e.g. "2019"
* @return {Promise&lt;NoteShort>}
*/
this.getYearNote = dateNotesService.getYearNote;
}
export default FrontendScriptApi;</code></pre>

View file

@ -8,6 +8,7 @@ import noteDetailService from './note_detail.js';
import noteTypeService from './note_type.js';
import noteTooltipService from './note_tooltip.js';
import protectedSessionService from'./protected_session.js';
import dateNotesService from'./date_notes.js';
/**
* This is the main frontend API interface for scripts. It's published in the local "api" object.
@ -286,6 +287,41 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) {
* @method
*/
this.protectActiveNote = protectedSessionService.protectNoteAndSendToServer;
/**
* Returns date-note for today. If it doesn't exist, it is automatically created.
*
* @method
* @return {Promise<NoteShort>}
*/
this.getTodayNote = dateNotesService.getTodayNote;
/**
* Returns date-note. If it doesn't exist, it is automatically created.
*
* @method
* @param {string} date - e.g. "2019-04-29"
* @return {Promise<NoteShort>}
*/
this.getDateNote = dateNotesService.getDateNote;
/**
* Returns month-note. If it doesn't exist, it is automatically created.
*
* @method
* @param {string} month - e.g. "2019-04"
* @return {Promise<NoteShort>}
*/
this.getMonthNote = dateNotesService.getMonthNote;
/**
* Returns year-note. If it doesn't exist, it is automatically created.
*
* @method
* @param {string} year - e.g. "2019"
* @return {Promise<NoteShort>}
*/
this.getYearNote = dateNotesService.getYearNote;
}
export default FrontendScriptApi;