From 6a786cad83d3aaca4b267b7aa6c708b28bc1672b Mon Sep 17 00:00:00 2001 From: azivner Date: Sat, 22 Dec 2018 22:28:49 +0100 Subject: [PATCH] updated API docs --- docs/backend_api/BackendScriptApi.html | 2 +- docs/backend_api/Note.html | 1428 ++++----- docs/backend_api/entities_attribute.js.html | 5 + docs/backend_api/entities_branch.js.html | 5 + docs/backend_api/entities_note.js.html | 62 +- .../services_backend_script_api.js.html | 2 + docs/frontend_api/FrontendScriptApi.html | 173 +- docs/frontend_api/NoteShort.html | 2540 ++++++++++++++++- docs/frontend_api/entities_attribute.js.html | 84 + docs/frontend_api/entities_branch.js.html | 2 +- docs/frontend_api/entities_note_short.js.html | 144 +- docs/frontend_api/global.html | 2 +- .../services_frontend_script_api.js.html | 7 + 13 files changed, 3737 insertions(+), 719 deletions(-) create mode 100644 docs/frontend_api/entities_attribute.js.html diff --git a/docs/backend_api/BackendScriptApi.html b/docs/backend_api/BackendScriptApi.html index 986d1d842..2ce1c467d 100644 --- a/docs/backend_api/BackendScriptApi.html +++ b/docs/backend_api/BackendScriptApi.html @@ -3010,7 +3010,7 @@ the backend.
Source:
diff --git a/docs/backend_api/Note.html b/docs/backend_api/Note.html index fc34ea9bc..bf222ab85 100644 --- a/docs/backend_api/Note.html +++ b/docs/backend_api/Note.html @@ -373,7 +373,7 @@
Source:
@@ -438,625 +438,6 @@ -

(async) findChildNotesWithAttribute(type, name, valueopt) → {Promise.<Array.<Note>>}

- - - - - - -
- Finds child notes with given attribute name and value. Only own attributes are considered, not inherited ones -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
type - - -string - - - - - - - - - - attribute type (label, relation, etc.)
name - - -string - - - - - - - - - - attribute name
value - - -string - - - - - - <optional>
- - - - - -
attribute value
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -Promise.<Array.<Note>> - - -
-
- - - - - - - - - - - - - -

(async) findChildNotesWithLabel(name, valueopt) → {Promise.<Array.<Note>>}

- - - - - - -
- Finds notes with given label name and value. Only own labels are considered, not inherited ones -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
name - - -string - - - - - - - - - - label name
value - - -string - - - - - - <optional>
- - - - - -
label value
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -Promise.<Array.<Note>> - - -
-
- - - - - - - - - - - - - -

(async) findChildNotesWithRelation(name, valueopt) → {Promise.<Array.<Note>>}

- - - - - - -
- Finds notes with given relation name and value. Only own relations are considered, not inherited ones -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
name - - -string - - - - - - - - - - relation name
value - - -string - - - - - - <optional>
- - - - - -
relation value
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -Promise.<Array.<Note>> - - -
-
- - - - - - - - - - - - -

(async) getAttribute(type, name) → {Promise.<Attribute>}

@@ -1177,7 +558,7 @@
Source:
@@ -1342,7 +723,7 @@
Source:
@@ -1518,7 +899,7 @@
Source:
@@ -1622,7 +1003,7 @@
Source:
@@ -1722,7 +1103,7 @@
Source:
@@ -1826,7 +1207,7 @@
Source:
@@ -1882,6 +1263,729 @@ +

(async) getDescendantNoteIds() → {Promise.<Array.<string>>}

+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ return list of all descendant noteIds of this note. Returning just noteIds because number of notes can be huge. Includes also this note's noteId +
+ + + +
+
+ Type +
+
+ +Promise.<Array.<string>> + + +
+
+ + + + + + + + + + + + + +

(async) getDescendantNotesWithAttribute(type, name, valueopt) → {Promise.<Array.<Note>>}

+ + + + + + +
+ Finds descendant notes with given attribute name and value. Only own attributes are considered, not inherited ones +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
type + + +string + + + + + + + + + + attribute type (label, relation, etc.)
name + + +string + + + + + + + + + + attribute name
value + + +string + + + + + + <optional>
+ + + + + +
attribute value
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Array.<Note>> + + +
+
+ + + + + + + + + + + + + +

(async) getDescendantNotesWithLabel(name, valueopt) → {Promise.<Array.<Note>>}

+ + + + + + +
+ Finds descendant notes with given label name and value. Only own labels are considered, not inherited ones +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
name + + +string + + + + + + + + + + label name
value + + +string + + + + + + <optional>
+ + + + + +
label value
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Array.<Note>> + + +
+
+ + + + + + + + + + + + + +

(async) getDescendantNotesWithRelation(name, valueopt) → {Promise.<Array.<Note>>}

+ + + + + + +
+ Finds descendant notes with given relation name and value. Only own relations are considered, not inherited ones +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
name + + +string + + + + + + + + + + relation name
value + + +string + + + + + + <optional>
+ + + + + +
relation value
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Array.<Note>> + + +
+
+ + + + + + + + + + + + +

(async) getLabel(name) → {Promise.<Attribute>}

@@ -1979,7 +2083,7 @@
Source:
@@ -2144,7 +2248,7 @@
Source:
@@ -2309,7 +2413,7 @@
Source:
@@ -2462,7 +2566,7 @@
Source:
@@ -2570,7 +2674,7 @@
Source:
@@ -2674,7 +2778,7 @@
Source:
@@ -2774,7 +2878,7 @@
Source:
@@ -2878,7 +2982,7 @@
Source:
@@ -3031,7 +3135,7 @@
Source:
@@ -3196,7 +3300,7 @@
Source:
@@ -3361,7 +3465,7 @@
Source:
@@ -3514,7 +3618,7 @@
Source:
@@ -3670,7 +3774,7 @@
Source:
@@ -3778,7 +3882,7 @@
Source:
@@ -3878,7 +3982,7 @@
Source:
@@ -3986,7 +4090,7 @@
Source:
@@ -4086,7 +4190,7 @@
Source:
@@ -4262,7 +4366,7 @@
Source:
@@ -4366,7 +4470,7 @@
Source:
@@ -4519,7 +4623,7 @@
Source:
@@ -4672,7 +4776,7 @@
Source:
@@ -4781,7 +4885,7 @@ Cache is note instance scoped.
Source:
@@ -4863,7 +4967,7 @@ Cache is note instance scoped.
Source:
@@ -4967,7 +5071,7 @@ Cache is note instance scoped.
Source:
@@ -5071,7 +5175,7 @@ Cache is note instance scoped.
Source:
@@ -5175,7 +5279,7 @@ Cache is note instance scoped.
Source:
@@ -5279,7 +5383,7 @@ Cache is note instance scoped.
Source:
@@ -5506,7 +5610,7 @@ Cache is note instance scoped.
Source:
@@ -5702,7 +5806,7 @@ Cache is note instance scoped.
Source:
@@ -5898,7 +6002,7 @@ Cache is note instance scoped.
Source:
@@ -6125,7 +6229,7 @@ Cache is note instance scoped.
Source:
@@ -6321,7 +6425,7 @@ Cache is note instance scoped.
Source:
@@ -6517,7 +6621,7 @@ Cache is note instance scoped.
Source:
@@ -6775,7 +6879,7 @@ Cache is note instance scoped.
Source:
@@ -7002,7 +7106,7 @@ Cache is note instance scoped.
Source:
@@ -7229,7 +7333,7 @@ Cache is note instance scoped.
Source:
diff --git a/docs/backend_api/entities_attribute.js.html b/docs/backend_api/entities_attribute.js.html index f77e6a54d..646b5a067 100644 --- a/docs/backend_api/entities_attribute.js.html +++ b/docs/backend_api/entities_attribute.js.html @@ -133,6 +133,11 @@ class Attribute extends Entity { this.dateModified = dateUtils.nowDate(); } } + + // cannot be static! + updatePojo(pojo) { + delete pojo.isOwned; + } } module.exports = Attribute; diff --git a/docs/backend_api/entities_branch.js.html b/docs/backend_api/entities_branch.js.html index 041584115..1f0ab47fb 100644 --- a/docs/backend_api/entities_branch.js.html +++ b/docs/backend_api/entities_branch.js.html @@ -87,6 +87,11 @@ class Branch extends Entity { this.dateModified = dateUtils.nowDate(); } } + + // cannot be static! + updatePojo(pojo) { + delete pojo.origParentNoteId; + } } module.exports = Branch; diff --git a/docs/backend_api/entities_note.js.html b/docs/backend_api/entities_note.js.html index e72456186..07e582d58 100644 --- a/docs/backend_api/entities_note.js.html +++ b/docs/backend_api/entities_note.js.html @@ -32,6 +32,7 @@ const Entity = require('./entity'); const Attribute = require('./attribute'); const protectedSessionService = require('../services/protected_session'); const repository = require('../services/repository'); +const sql = require('../services/sql'); const dateUtils = require('../services/date_utils'); const LABEL = 'label'; @@ -102,7 +103,9 @@ class Note extends Entity { /** @returns {boolean} true if this note is JavaScript (code or attachment) */ isJavaScript() { return (this.type === "code" || this.type === "file") - && (this.mime.startsWith("application/javascript") || this.mime === "application/x-javascript"); + && (this.mime.startsWith("application/javascript") + || this.mime === "application/x-javascript" + || this.mime === "text/javascript"); } /** @returns {boolean} true if this note is HTML */ @@ -394,6 +397,16 @@ class Note extends Entity { */ async getRelationValue(name) { return await this.getAttributeValue(RELATION, name); } + /** + * @param {string} name + * @returns {Promise<Note>|null} target note of the relation or null (if target is empty or note was not found) + */ + async getRelationTarget(name) { + const relation = await this.getRelation(name); + + return relation ? await repository.getNote(relation.value) : null; + } + /** * Based on enabled, label is either set or removed. * @@ -451,24 +464,32 @@ class Note extends Entity { async removeRelation(name, value) { return await this.removeAttribute(RELATION, name, value); } /** - * @param {string} name - * @returns {Promise<Note>|null} target note of the relation or null (if target is empty or note was not found) + * @return {Promise<string[]>} return list of all descendant noteIds of this note. Returning just noteIds because number of notes can be huge. Includes also this note's noteId */ - async getRelationTarget(name) { - const relation = await this.getRelation(name); - - return relation ? await repository.getNote(relation.value) : null; + async getDescendantNoteIds() { + return await sql.getColumn(` + WITH RECURSIVE + tree(noteId) AS ( + SELECT ? + UNION + SELECT branches.noteId FROM branches + JOIN tree ON branches.parentNoteId = tree.noteId + JOIN notes ON notes.noteId = branches.noteId + WHERE notes.isDeleted = 0 + AND branches.isDeleted = 0 + ) + SELECT noteId FROM tree`, [this.noteId]); } /** - * Finds child notes with given attribute name and value. Only own attributes are considered, not inherited ones + * Finds descendant notes with given attribute name and value. Only own attributes are considered, not inherited ones * * @param {string} type - attribute type (label, relation, etc.) * @param {string} name - attribute name * @param {string} [value] - attribute value * @returns {Promise<Note[]>} */ - async findChildNotesWithAttribute(type, name, value) { + async getDescendantNotesWithAttribute(type, name, value) { const params = [this.noteId, name]; let valueCondition = ""; @@ -500,22 +521,22 @@ class Note extends Entity { } /** - * Finds notes with given label name and value. Only own labels are considered, not inherited ones + * Finds descendant notes with given label name and value. Only own labels are considered, not inherited ones * * @param {string} name - label name * @param {string} [value] - label value * @returns {Promise<Note[]>} */ - async findChildNotesWithLabel(name, value) { return await this.findChildNotesWithAttribute(LABEL, name, value); } + async getDescendantNotesWithLabel(name, value) { return await this.getDescendantNotesWithAttribute(LABEL, name, value); } /** - * Finds notes with given relation name and value. Only own relations are considered, not inherited ones + * Finds descendant notes with given relation name and value. Only own relations are considered, not inherited ones * * @param {string} name - relation name * @param {string} [value] - relation value * @returns {Promise<Note[]>} */ - async findChildNotesWithRelation(name, value) { return await this.findChildNotesWithAttribute(RELATION, name, value); } + async getDescendantNotesWithRelation(name, value) { return await this.getDescendantNotesWithAttribute(RELATION, name, value); } /** * Returns note revisions of this note. @@ -615,10 +636,6 @@ class Note extends Entity { // we do this here because encryption needs the note ID for the IV this.generateIdIfNecessary(); - if (this.isProtected) { - protectedSessionService.encryptNote(this); - } - if (!this.isDeleted) { this.isDeleted = false; } @@ -633,6 +650,17 @@ class Note extends Entity { this.dateModified = dateUtils.nowDate(); } } + + // cannot be static! + updatePojo(pojo) { + if (pojo.isProtected) { + protectedSessionService.encryptNote(pojo); + } + + delete pojo.jsonContent; + delete pojo.isContentAvailable; + delete pojo.__attributeCache; + } } module.exports = Note; diff --git a/docs/backend_api/services_backend_script_api.js.html b/docs/backend_api/services_backend_script_api.js.html index 914220018..5cc8cc393 100644 --- a/docs/backend_api/services_backend_script_api.js.html +++ b/docs/backend_api/services_backend_script_api.js.html @@ -253,6 +253,8 @@ function BackendScriptApi(startNote, currentNote, originEntity) { */ this.transactional = sql.transactional; + this.sql = sql; + /** * Trigger tree refresh in all connected clients. This is required when some tree change happens in * the backend. diff --git a/docs/frontend_api/FrontendScriptApi.html b/docs/frontend_api/FrontendScriptApi.html index f2a68ba02..1cbea7dd9 100644 --- a/docs/frontend_api/FrontendScriptApi.html +++ b/docs/frontend_api/FrontendScriptApi.html @@ -81,7 +81,7 @@
Source:
@@ -221,7 +221,7 @@
Source:
@@ -334,7 +334,7 @@
Source:
@@ -444,7 +444,7 @@
Source:
@@ -573,7 +573,7 @@
Source:
@@ -726,7 +726,7 @@
Source:
@@ -879,7 +879,7 @@
Source:
@@ -1057,7 +1057,7 @@
Source:
@@ -1188,7 +1188,7 @@
Source:
@@ -1292,7 +1292,7 @@
Source:
@@ -1396,7 +1396,7 @@
Source:
@@ -1500,7 +1500,7 @@
Source:
@@ -1609,7 +1609,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -1808,7 +1808,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -1957,7 +1957,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -2088,7 +2088,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -2196,7 +2196,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -2373,7 +2373,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -2526,7 +2526,138 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

setupElementTooltip($el)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
$el + + +object + + + + jquery object on which to setup the tooltip
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
@@ -2661,7 +2792,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -2796,7 +2927,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
diff --git a/docs/frontend_api/NoteShort.html b/docs/frontend_api/NoteShort.html index e9a05c8b8..a637cb8ba 100644 --- a/docs/frontend_api/NoteShort.html +++ b/docs/frontend_api/NoteShort.html @@ -94,7 +94,7 @@ Its notable omission is the note content.
Source:
@@ -182,7 +182,7 @@ Its notable omission is the note content.
Source:
@@ -240,7 +240,7 @@ Its notable omission is the note content.
Source:
@@ -298,7 +298,7 @@ Its notable omission is the note content.
Source:
@@ -356,7 +356,7 @@ Its notable omission is the note content.
Source:
@@ -414,7 +414,7 @@ Its notable omission is the note content.
Source:
@@ -472,7 +472,7 @@ Its notable omission is the note content.
Source:
@@ -500,6 +500,519 @@ Its notable omission is the note content. +

(async) getAttribute(type, name) → {Promise.<Attribute>}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +string + + + + attribute type (label, relation, etc.)
name + + +string + + + + attribute name
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ attribute of given type and name. If there's more such attributes, first is returned. Returns null if there's no such attribute belonging to this note. +
+ + + +
+
+ Type +
+
+ +Promise.<Attribute> + + +
+
+ + + + + + + + + + + + + +

(async) getAttributes(nameopt) → {Promise.<Array.<Attribute>>}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
name + + +string + + + + + + <optional>
+ + + + + +
attribute name to filter
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Array.<Attribute>> + + +
+
+ + + + + + + + + + + + + +

(async) getAttributeValue(type, name) → {Promise.<string>}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +string + + + + attribute type (label, relation, etc.)
name + + +string + + + + attribute name
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ attribute value of given type and name or null if no such attribute exists. +
+ + + +
+
+ Type +
+
+ +Promise.<string> + + +
+
+ + + + + + + + + + + + +

(async) getBranches() → {Promise.<Array.<Branch>>}

@@ -548,7 +1061,7 @@ Its notable omission is the note content.
Source:
@@ -648,7 +1161,7 @@ Its notable omission is the note content.
Source:
@@ -748,7 +1261,7 @@ Its notable omission is the note content.
Source:
@@ -848,7 +1361,7 @@ Its notable omission is the note content.
Source:
@@ -900,6 +1413,642 @@ Its notable omission is the note content. +

(async) getLabel(name) → {Promise.<Attribute>}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +string + + + + label name
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ label if it exists, null otherwise +
+ + + +
+
+ Type +
+
+ +Promise.<Attribute> + + +
+
+ + + + + + + + + + + + + +

(async) getLabelDefinitions(nameopt) → {Promise.<Array.<Attribute>>}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
name + + +string + + + + + + <optional>
+ + + + + +
label name to filter
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ all note's label definitions, including inherited ones +
+ + + +
+
+ Type +
+
+ +Promise.<Array.<Attribute>> + + +
+
+ + + + + + + + + + + + + +

(async) getLabels(nameopt) → {Promise.<Array.<Attribute>>}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
name + + +string + + + + + + <optional>
+ + + + + +
label name to filter
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ all note's labels (attributes with type label), including inherited ones +
+ + + +
+
+ Type +
+
+ +Promise.<Array.<Attribute>> + + +
+
+ + + + + + + + + + + + + +

(async) getLabelValue(name) → {Promise.<string>}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +string + + + + label name
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ label value if label exists, null otherwise +
+ + + +
+
+ Type +
+
+ +Promise.<string> + + +
+
+ + + + + + + + + + + + +

getParentNoteIds() → {Array.<string>}

@@ -948,7 +2097,7 @@ Its notable omission is the note content.
Source:
@@ -1048,7 +2197,7 @@ Its notable omission is the note content.
Source:
@@ -1100,6 +2249,974 @@ Its notable omission is the note content. +

(async) getRelation(name) → {Promise.<Attribute>}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +string + + + + relation name
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ relation if it exists, null otherwise +
+ + + +
+
+ Type +
+
+ +Promise.<Attribute> + + +
+
+ + + + + + + + + + + + + +

(async) getRelationDefinitions(nameopt) → {Promise.<Array.<Attribute>>}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
name + + +string + + + + + + <optional>
+ + + + + +
relation name to filter
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ all note's relation definitions including inherited ones +
+ + + +
+
+ Type +
+
+ +Promise.<Array.<Attribute>> + + +
+
+ + + + + + + + + + + + + +

(async) getRelations(nameopt) → {Promise.<Array.<Attribute>>}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
name + + +string + + + + + + <optional>
+ + + + + +
relation name to filter
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ all note's relations (attributes with type relation), including inherited ones +
+ + + +
+
+ Type +
+
+ +Promise.<Array.<Attribute>> + + +
+
+ + + + + + + + + + + + + +

(async) getRelationTarget(name) → {Promise.<Note>|null}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +string + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ target note of the relation or null (if target is empty or note was not found) +
+ + + +
+
+ Type +
+
+ +Promise.<Note> +| + +null + + +
+
+ + + + + + + + + + + + + +

(async) getRelationValue(name) → {Promise.<string>}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +string + + + + relation name
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ relation value if relation exists, null otherwise +
+ + + +
+
+ Type +
+
+ +Promise.<string> + + +
+
+ + + + + + + + + + + + + +

(async) hasAttribute(type, name) → {Promise.<boolean>}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +string + + + + attribute type (label, relation, etc.)
name + + +string + + + + attribute name
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ true if note has an attribute with given type and name (including inherited) +
+ + + +
+
+ Type +
+
+ +Promise.<boolean> + + +
+
+ + + + + + + + + + + + +

hasChildren() → {boolean}

@@ -1148,7 +3265,7 @@ Its notable omission is the note content.
Source:
@@ -1196,6 +3313,399 @@ Its notable omission is the note content. + + + + +

(async) hasLabel(name) → {Promise.<boolean>}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +string + + + + label name
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ true if label exists (including inherited) +
+ + + +
+
+ Type +
+
+ +Promise.<boolean> + + +
+
+ + + + + + + + + + + + + +

(async) hasRelation(name) → {Promise.<boolean>}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +string + + + + relation name
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ true if relation exists (including inherited) +
+ + + +
+
+ Type +
+
+ +Promise.<boolean> + + +
+
+ + + + + + + + + + + + + +

invalidateAttributeCache()

+ + + + + + +
+ Clear note's attributes cache to force fresh reload for next attribute request. +Cache is note instance scoped. +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + @@ -1248,7 +3758,7 @@ Its notable omission is the note content.
Source:
diff --git a/docs/frontend_api/entities_attribute.js.html b/docs/frontend_api/entities_attribute.js.html new file mode 100644 index 000000000..bdba252b1 --- /dev/null +++ b/docs/frontend_api/entities_attribute.js.html @@ -0,0 +1,84 @@ + + + + + JSDoc: Source: entities/attribute.js + + + + + + + + + + +
+ +

Source: entities/attribute.js

+ + + + + + +
+
+
class Attribute {
+    constructor(treeCache, row) {
+        this.treeCache = treeCache;
+        /** @param {string} attributeId */
+        this.attributeId = row.attributeId;
+        /** @param {string} noteId */
+        this.noteId = row.noteId;
+        /** @param {string} type */
+        this.type = row.type;
+        /** @param {string} name */
+        this.name = row.name;
+        /** @param {string} value */
+        this.value = row.value;
+        /** @param {int} position */
+        this.position = row.position;
+        /** @param {boolean} isInheritable */
+        this.isInheritable = row.isInheritable;
+        /** @param {boolean} isDeleted */
+        this.isDeleted = row.isDeleted;
+        /** @param {string} dateCreated */
+        this.dateCreated = row.dateCreated;
+        /** @param {string} dateModified */
+        this.dateModified = row.dateModified;
+    }
+
+    /** @returns {NoteShort} */
+    async getNote() {
+        return await this.treeCache.getNote(this.noteId);
+    }
+
+    get toString() {
+        return `Attribute(attributeId=${this.attributeId}, type=${this.type}, name=${this.name})`;
+    }
+}
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/frontend_api/entities_branch.js.html b/docs/frontend_api/entities_branch.js.html index 28f5c6d0e..3062203ad 100644 --- a/docs/frontend_api/entities_branch.js.html +++ b/docs/frontend_api/entities_branch.js.html @@ -42,7 +42,7 @@ class Branch { /** @param {string} */ this.prefix = row.prefix; /** @param {boolean} */ - this.isExpanded = row.isExpanded; + this.isExpanded = !!row.isExpanded; } /** @returns {NoteShort} */ diff --git a/docs/frontend_api/entities_note_short.js.html b/docs/frontend_api/entities_note_short.js.html index 8e27bc89c..1ade082db 100644 --- a/docs/frontend_api/entities_note_short.js.html +++ b/docs/frontend_api/entities_note_short.js.html @@ -26,7 +26,14 @@
-
/**
+            
import server from '../services/server.js';
+
+const LABEL = 'label';
+const LABEL_DEFINITION = 'label-definition';
+const RELATION = 'relation';
+const RELATION_DEFINITION = 'relation-definition';
+
+/**
  * This note's representation is used in note tree and is kept in TreeCache.
  * Its notable omission is the note content.
  */
@@ -99,6 +106,140 @@ class NoteShort {
         return await this.treeCache.getNotes(this.getChildNoteIds());
     }
 
+    /**
+     * @param {string} [name] - attribute name to filter
+     * @returns {Promise<Attribute[]>}
+     */
+    async getAttributes(name) {
+        if (!this.attributeCache) {
+            this.attributeCache = await server.get('notes/' + this.noteId + '/attributes');
+        }
+
+        if (name) {
+            return this.attributeCache.filter(attr => attr.name === name);
+        }
+        else {
+            return this.attributeCache;
+        }
+    }
+
+    /**
+     * @param {string} [name] - label name to filter
+     * @returns {Promise<Attribute[]>} all note's labels (attributes with type label), including inherited ones
+     */
+    async getLabels(name) {
+        return (await this.getAttributes(name)).filter(attr => attr.type === LABEL);
+    }
+
+    /**
+     * @param {string} [name] - label name to filter
+     * @returns {Promise<Attribute[]>} all note's label definitions, including inherited ones
+     */
+    async getLabelDefinitions(name) {
+        return (await this.getAttributes(name)).filter(attr => attr.type === LABEL_DEFINITION);
+    }
+
+    /**
+     * @param {string} [name] - relation name to filter
+     * @returns {Promise<Attribute[]>} all note's relations (attributes with type relation), including inherited ones
+     */
+    async getRelations(name) {
+        return (await this.getAttributes(name)).filter(attr => attr.type === RELATION);
+    }
+
+    /**
+     * @param {string} [name] - relation name to filter
+     * @returns {Promise<Attribute[]>} all note's relation definitions including inherited ones
+     */
+    async getRelationDefinitions(name) {
+        return (await this.getAttributes(name)).filter(attr => attr.type === RELATION_DEFINITION);
+    }
+
+    /**
+     * @param {string} type - attribute type (label, relation, etc.)
+     * @param {string} name - attribute name
+     * @returns {Promise<boolean>} true if note has an attribute with given type and name (including inherited)
+     */
+    async hasAttribute(type, name) {
+        return !!await this.getAttribute(type, name);
+    }
+
+    /**
+     * @param {string} type - attribute type (label, relation, etc.)
+     * @param {string} name - attribute name
+     * @returns {Promise<Attribute>} attribute of given type and name. If there's more such attributes, first is  returned. Returns null if there's no such attribute belonging to this note.
+     */
+    async getAttribute(type, name) {
+        const attributes = await this.getAttributes();
+
+        return attributes.find(attr => attr.type === type && attr.name === name);
+    }
+
+    /**
+     * @param {string} type - attribute type (label, relation, etc.)
+     * @param {string} name - attribute name
+     * @returns {Promise<string>} attribute value of given type and name or null if no such attribute exists.
+     */
+    async getAttributeValue(type, name) {
+        const attr = await this.getAttribute(type, name);
+
+        return attr ? attr.value : null;
+    }
+
+    /**
+     * @param {string} name - label name
+     * @returns {Promise<boolean>} true if label exists (including inherited)
+     */
+    async hasLabel(name) { return await this.hasAttribute(LABEL, name); }
+
+    /**
+     * @param {string} name - relation name
+     * @returns {Promise<boolean>} true if relation exists (including inherited)
+     */
+    async hasRelation(name) { return await this.hasAttribute(RELATION, name); }
+
+    /**
+     * @param {string} name - label name
+     * @returns {Promise<Attribute>} label if it exists, null otherwise
+     */
+    async getLabel(name) { return await this.getAttribute(LABEL, name); }
+
+    /**
+     * @param {string} name - relation name
+     * @returns {Promise<Attribute>} relation if it exists, null otherwise
+     */
+    async getRelation(name) { return await this.getAttribute(RELATION, name); }
+
+    /**
+     * @param {string} name - label name
+     * @returns {Promise<string>} label value if label exists, null otherwise
+     */
+    async getLabelValue(name) { return await this.getAttributeValue(LABEL, name); }
+
+    /**
+     * @param {string} name - relation name
+     * @returns {Promise<string>} relation value if relation exists, null otherwise
+     */
+    async getRelationValue(name) { return await this.getAttributeValue(RELATION, name); }
+
+    /**
+     * @param {string} name
+     * @returns {Promise<Note>|null} target note of the relation or null (if target is empty or note was not found)
+     */
+    async getRelationTarget(name) {
+        const relation = await this.getRelation(name);
+
+        return relation ? await repository.getNote(relation.value) : null;
+    }
+
+    /**
+     * Clear note's attributes cache to force fresh reload for next attribute request.
+     * Cache is note instance scoped.
+     */
+    invalidateAttributeCache() {
+        this.attributeCache = null;
+    }
+
     get toString() {
         return `Note(noteId=${this.noteId}, title=${this.title})`;
     }
@@ -107,6 +248,7 @@ class NoteShort {
         const dto = Object.assign({}, this);
         delete dto.treeCache;
         delete dto.archived;
+        delete dto.attributeCache;
 
         return dto;
     }
diff --git a/docs/frontend_api/global.html b/docs/frontend_api/global.html
index 369553f4c..a73e78e1b 100644
--- a/docs/frontend_api/global.html
+++ b/docs/frontend_api/global.html
@@ -303,7 +303,7 @@
     
     
Source:
diff --git a/docs/frontend_api/services_frontend_script_api.js.html b/docs/frontend_api/services_frontend_script_api.js.html index 20a3ecf24..9ce981b93 100644 --- a/docs/frontend_api/services_frontend_script_api.js.html +++ b/docs/frontend_api/services_frontend_script_api.js.html @@ -34,6 +34,7 @@ import linkService from './link.js'; import treeCache from './tree_cache.js'; import noteDetailService from './note_detail.js'; import noteTypeService from './note_type.js'; +import noteTooltipService from './note_tooltip.js'; /** * This is the main frontend API interface for scripts. It's published in the local "api" object. @@ -253,6 +254,12 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) { * @param {array} types - list of mime types to be used */ this.setCodeMimeTypes = noteTypeService.setCodeMimeTypes; + + /** + * @method + * @param {object} $el - jquery object on which to setup the tooltip + */ + this.setupElementTooltip = noteTooltipService.setupElementTooltip } export default FrontendScriptApi;