new frontend API - getCurrentNoteContent and onNoteChange

This commit is contained in:
azivner
2018-09-03 16:05:28 +02:00
parent a3feaa13b3
commit c7a609e349
42 changed files with 817 additions and 106 deletions

View File

@@ -127,23 +127,37 @@ class Note extends Entity {
return await repository.getEntities(`SELECT * FROM attributes WHERE isDeleted = 0 AND noteId = ?`, [this.noteId]);
}
/** @returns {Promise<Attribute[]>} all note's attributes, including inherited ones */
async getAttributes() {
/**
* @param {string} [name] - attribute name to filter
* @returns {Promise<Attribute[]>} all note's attributes, including inherited ones
*/
async getAttributes(name) {
if (!this.__attributeCache) {
await this.loadAttributesToCache();
}
return this.__attributeCache;
if (name) {
return this.__attributeCache.filter(attr => attr.name === name);
}
else {
return this.__attributeCache;
}
}
/** @returns {Promise<Attribute[]>} all note's labels (attributes with type label), including inherited ones */
async getLabels() {
return (await this.getAttributes()).filter(attr => attr.type === LABEL);
/**
* @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);
}
/** @returns {Promise<Attribute[]>} all note's relations (attributes with type relation), including inherited ones */
async getRelations() {
return (await this.getAttributes()).filter(attr => attr.type === RELATION);
/**
* @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);
}
/**
@@ -496,6 +510,13 @@ class Note extends Entity {
return await repository.getEntities("SELECT * FROM branches WHERE isDeleted = 0 AND noteId = ?", [this.noteId]);
}
/**
* @returns {boolean} - true if note has children
*/
async hasChildren() {
return (await this.getChildNotes()).length > 0;
}
/**
* @returns {Promise<Note[]>} child notes of this note
*/
@@ -580,7 +601,7 @@ module.exports = Note;</code></pre>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Aug 29 2018 20:44:06 GMT+0200 (CEST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Sep 03 2018 16:04:45 GMT+0200 (CEST)
</footer>
<script> prettyPrint(); </script>