2018-12-22 22:16:32 +01:00
import server from '../services/server.js' ;
2019-08-19 20:12:00 +02:00
import Attribute from './attribute.js' ;
2020-05-02 18:19:41 +02:00
import noteAttributeCache from "../services/note_attribute_cache.js" ;
2018-12-22 22:16:32 +01:00
const LABEL = 'label' ;
const RELATION = 'relation' ;
2020-10-14 23:14:04 +02:00
const NOTE _TYPE _ICONS = {
"file" : "bx bx-file" ,
"image" : "bx bx-image" ,
"code" : "bx bx-code" ,
"render" : "bx bx-extension" ,
"search" : "bx bx-file-find" ,
"relation-map" : "bx bx-map-alt" ,
"book" : "bx bx-book"
} ;
2018-08-23 12:55:45 +02:00
/ * *
2020-05-03 13:15:08 +02:00
* FIXME : since there ' s no "full note" anymore we can rename this to Note
*
2018-08-23 12:55:45 +02:00
* This note ' s representation is used in note tree and is kept in TreeCache .
* /
2018-03-25 12:29:00 -04:00
class NoteShort {
2019-10-26 09:51:08 +02:00
/ * *
* @ param { TreeCache } treeCache
* @ param { Object . < string , Object > } row
* /
2020-01-31 20:52:31 +01:00
constructor ( treeCache , row ) {
2018-03-25 12:29:00 -04:00
this . treeCache = treeCache ;
2020-01-29 22:32:22 +01:00
2020-01-30 22:38:31 +01:00
/** @type {string[]} */
this . attributes = [ ] ;
/** @type {string[]} */
this . targetRelations = [ ] ;
/** @type {string[]} */
this . parents = [ ] ;
/** @type {string[]} */
this . children = [ ] ;
/** @type {Object.<string, string>} */
this . parentToBranch = { } ;
/** @type {Object.<string, string>} */
this . childToBranch = { } ;
2020-01-31 20:52:31 +01:00
this . update ( row ) ;
2020-01-29 22:32:22 +01:00
}
2020-01-31 20:52:31 +01:00
update ( row ) {
2018-08-23 12:55:45 +02:00
/** @param {string} */
2018-03-25 12:29:00 -04:00
this . noteId = row . noteId ;
2018-08-23 12:55:45 +02:00
/** @param {string} */
2018-03-25 12:29:00 -04:00
this . title = row . title ;
2018-08-23 12:55:45 +02:00
/** @param {boolean} */
2020-03-08 09:38:49 +01:00
this . isProtected = ! ! row . isProtected ;
2018-08-23 12:55:45 +02:00
/** @param {string} one of 'text', 'code', 'file' or 'render' */
2018-03-25 12:29:00 -04:00
this . type = row . type ;
2018-08-23 12:55:45 +02:00
/** @param {string} content-type, e.g. "application/json" */
2018-03-25 12:29:00 -04:00
this . mime = row . mime ;
2020-12-17 15:04:04 +01:00
/** @param {boolean} */
this . isDeleted = ! ! row . isDeleted ;
2019-10-26 09:51:08 +02:00
}
addParent ( parentNoteId , branchId ) {
2020-08-28 14:29:20 +02:00
if ( parentNoteId === 'none' ) {
return ;
}
2019-10-26 09:51:08 +02:00
if ( ! this . parents . includes ( parentNoteId ) ) {
this . parents . push ( parentNoteId ) ;
}
this . parentToBranch [ parentNoteId ] = branchId ;
}
2020-12-10 16:10:10 +01:00
addChild ( childNoteId , branchId , sort = true ) {
2020-12-14 22:12:26 +01:00
if ( ! ( childNoteId in this . childToBranch ) ) {
2019-10-26 09:51:08 +02:00
this . children . push ( childNoteId ) ;
}
this . childToBranch [ childNoteId ] = branchId ;
2020-12-10 16:10:10 +01:00
if ( sort ) {
this . sortChildren ( ) ;
}
2020-09-14 22:48:20 +02:00
}
sortChildren ( ) {
2019-10-26 09:51:08 +02:00
const branchIdPos = { } ;
for ( const branchId of Object . values ( this . childToBranch ) ) {
2019-10-26 20:48:56 +02:00
branchIdPos [ branchId ] = this . treeCache . getBranch ( branchId ) . notePosition ;
2019-10-26 09:51:08 +02:00
}
this . children . sort ( ( a , b ) => branchIdPos [ this . childToBranch [ a ] ] < branchIdPos [ this . childToBranch [ b ] ] ? - 1 : 1 ) ;
2018-03-25 12:29:00 -04:00
}
2018-08-23 12:55:45 +02:00
/** @returns {boolean} */
2018-03-25 23:25:17 -04:00
isJson ( ) {
return this . mime === "application/json" ;
}
2019-09-06 23:36:08 +02:00
async getContent ( ) {
// we're not caching content since these objects are in treeCache and as such pretty long lived
const note = await server . get ( "notes/" + this . noteId ) ;
return note . content ;
}
async getJsonContent ( ) {
const content = await this . getContent ( ) ;
try {
return JSON . parse ( content ) ;
}
catch ( e ) {
console . log ( ` Cannot parse content of note ${ this . noteId } : ` , e . message ) ;
return null ;
}
}
2020-02-03 20:07:34 +01:00
/** @returns {string[]} */
getBranchIds ( ) {
return Object . values ( this . parentToBranch ) ;
}
2020-03-18 22:35:54 +01:00
/** @returns {Branch[]} */
getBranches ( ) {
2019-10-26 09:51:08 +02:00
const branchIds = Object . values ( this . parentToBranch ) ;
2018-03-25 12:29:00 -04:00
2018-04-16 23:13:33 -04:00
return this . treeCache . getBranches ( branchIds ) ;
2018-03-25 12:29:00 -04:00
}
2018-08-23 12:55:45 +02:00
/** @returns {boolean} */
2018-04-16 20:40:18 -04:00
hasChildren ( ) {
2019-10-26 09:51:08 +02:00
return this . children . length > 0 ;
2018-04-16 20:40:18 -04:00
}
2020-03-18 22:35:54 +01:00
/** @returns {Branch[]} */
getChildBranches ( ) {
2019-10-27 22:39:38 +01:00
// don't use Object.values() to guarantee order
const branchIds = this . children . map ( childNoteId => this . childToBranch [ childNoteId ] ) ;
2018-03-25 12:29:00 -04:00
2019-10-26 09:58:00 +02:00
return this . treeCache . getBranches ( branchIds ) ;
2018-03-25 12:29:00 -04:00
}
2018-08-23 15:33:19 +02:00
/** @returns {string[]} */
2018-04-16 23:34:56 -04:00
getParentNoteIds ( ) {
2019-10-26 09:51:08 +02:00
return this . parents ;
2018-04-16 20:40:18 -04:00
}
2020-03-18 22:35:54 +01:00
/** @returns {NoteShort[]} */
getParentNotes ( ) {
return this . treeCache . getNotesFromCache ( this . parents ) ;
2018-04-16 23:34:56 -04:00
}
2018-08-23 15:33:19 +02:00
/** @returns {string[]} */
2018-04-16 23:34:56 -04:00
getChildNoteIds ( ) {
2019-10-26 09:51:08 +02:00
return this . children ;
2018-03-25 12:29:00 -04:00
}
2018-08-23 15:33:19 +02:00
/** @returns {Promise<NoteShort[]>} */
2018-03-25 12:29:00 -04:00
async getChildNotes ( ) {
2019-10-26 09:51:08 +02:00
return await this . treeCache . getNotes ( this . children ) ;
2018-03-25 12:29:00 -04:00
}
2020-01-25 13:27:23 +01:00
/ * *
* @ param { string } [ type ] - ( optional ) attribute type to filter
* @ param { string } [ name ] - ( optional ) attribute name to filter
* @ returns { Attribute [ ] } all note ' s attributes , including inherited ones
* /
getOwnedAttributes ( type , name ) {
const attrs = this . attributes
. map ( attributeId => this . treeCache . attributes [ attributeId ] )
2020-05-02 18:19:41 +02:00
. filter ( Boolean ) ; // filter out nulls;
2020-01-25 13:27:23 +01:00
2020-05-02 18:19:41 +02:00
return this . _ _filterAttrs ( attrs , type , name ) ;
2020-01-25 13:27:23 +01:00
}
2018-12-22 22:16:32 +01:00
/ * *
2019-12-01 12:22:22 +01:00
* @ param { string } [ type ] - ( optional ) attribute type to filter
* @ param { string } [ name ] - ( optional ) attribute name to filter
2020-03-18 22:35:54 +01:00
* @ returns { Attribute [ ] } all note ' s attributes , including inherited ones
2018-12-22 22:16:32 +01:00
* /
2020-03-18 22:35:54 +01:00
getAttributes ( type , name ) {
2020-06-04 12:27:41 +02:00
return this . _ _filterAttrs ( this . _ _getCachedAttributes ( [ ] ) , type , name ) ;
}
_ _getCachedAttributes ( path ) {
// notes/clones cannot form tree cycles, it is possible to create attribute inheritance cycle via templates
// when template instance is a parent of template itself
if ( path . includes ( this . noteId ) ) {
return [ ] ;
}
2020-06-27 00:40:35 +02:00
if ( ! ( this . noteId in noteAttributeCache . attributes ) ) {
2020-06-04 12:27:41 +02:00
const newPath = [ ... path , this . noteId ] ;
2020-06-27 00:40:35 +02:00
const attrArrs = [ this . getOwnedAttributes ( ) ] ;
2020-01-25 13:27:23 +01:00
2020-05-02 18:19:41 +02:00
if ( this . noteId !== 'root' ) {
for ( const parentNote of this . getParentNotes ( ) ) {
// these virtual parent-child relationships are also loaded into frontend tree cache
if ( parentNote . type !== 'search' ) {
2020-06-04 12:27:41 +02:00
attrArrs . push ( parentNote . _ _getInheritableAttributes ( newPath ) ) ;
2020-05-02 18:19:41 +02:00
}
2020-03-29 20:37:40 +02:00
}
2020-01-25 13:27:23 +01:00
}
2020-06-27 00:40:35 +02:00
for ( const templateAttr of attrArrs . flat ( ) . filter ( attr => attr . type === 'relation' && attr . name === 'template' ) ) {
const templateNote = this . treeCache . notes [ templateAttr . value ] ;
if ( templateNote && templateNote . noteId !== this . noteId ) {
attrArrs . push ( templateNote . _ _getCachedAttributes ( newPath ) ) ;
}
}
2020-09-30 22:34:18 +02:00
noteAttributeCache . attributes [ this . noteId ] = [ ] ;
const addedAttributeIds = new Set ( ) ;
for ( const attr of attrArrs . flat ( ) ) {
if ( ! addedAttributeIds . has ( attr . attributeId ) ) {
addedAttributeIds . add ( attr . attributeId ) ;
noteAttributeCache . attributes [ this . noteId ] . push ( attr ) ;
}
}
2020-05-02 18:19:41 +02:00
}
2020-01-25 13:27:23 +01:00
2020-06-04 12:27:41 +02:00
return noteAttributeCache . attributes [ this . noteId ] ;
2020-01-25 13:27:23 +01:00
}
_ _filterAttrs ( attributes , type , name ) {
2020-05-02 18:19:41 +02:00
if ( ! type && ! name ) {
return attributes ;
} else if ( type && name ) {
2020-01-25 13:27:23 +01:00
return attributes . filter ( attr => attr . type === type && attr . name === name ) ;
} else if ( type ) {
return attributes . filter ( attr => attr . type === type ) ;
} else if ( name ) {
return attributes . filter ( attr => attr . name === name ) ;
2018-12-22 22:16:32 +01:00
}
}
2020-06-04 12:27:41 +02:00
_ _getInheritableAttributes ( path ) {
const attrs = this . _ _getCachedAttributes ( path ) ;
2020-01-25 13:27:23 +01:00
return attrs . filter ( attr => attr . isInheritable ) ;
}
/ * *
* @ param { string } [ name ] - label name to filter
* @ returns { Attribute [ ] } all note ' s labels ( attributes with type label ) , including inherited ones
* /
getOwnedLabels ( name ) {
return this . getOwnedAttributes ( LABEL , name ) ;
}
2018-12-22 22:16:32 +01:00
/ * *
* @ param { string } [ name ] - label name to filter
2020-03-18 22:35:54 +01:00
* @ returns { Attribute [ ] } all note ' s labels ( attributes with type label ) , including inherited ones
2018-12-22 22:16:32 +01:00
* /
2020-03-18 22:35:54 +01:00
getLabels ( name ) {
return this . getAttributes ( LABEL , name ) ;
2018-12-22 22:16:32 +01:00
}
2020-10-14 23:14:04 +02:00
getIcon ( isFolder = false ) {
2020-11-25 20:25:55 +01:00
const iconClassLabels = this . getLabels ( 'iconClass' ) ;
const workspaceIconClass = this . getWorkspaceIconClass ( ) ;
2020-10-14 23:14:04 +02:00
2020-11-25 20:25:55 +01:00
if ( iconClassLabels . length > 0 ) {
return iconClassLabels . map ( l => l . value ) . join ( ' ' ) ;
}
else if ( workspaceIconClass ) {
return workspaceIconClass ;
2020-10-14 23:14:04 +02:00
}
else if ( this . noteId === 'root' ) {
return "bx bx-chevrons-right" ;
}
else if ( this . type === 'text' ) {
if ( isFolder ) {
return "bx bx-folder" ;
}
else {
return "bx bx-note" ;
}
}
else if ( this . type === 'code' && this . mime . startsWith ( 'text/x-sql' ) ) {
return "bx bx-data" ;
}
else {
return NOTE _TYPE _ICONS [ this . type ] ;
}
}
2020-01-25 13:27:23 +01:00
/ * *
* @ param { string } [ name ] - relation name to filter
* @ returns { Attribute [ ] } all note ' s relations ( attributes with type relation ) , including inherited ones
* /
getOwnedRelations ( name ) {
return this . getOwnedAttributes ( RELATION , name ) ;
}
2018-12-22 22:16:32 +01:00
/ * *
* @ param { string } [ name ] - relation name to filter
2020-03-18 22:35:54 +01:00
* @ returns { Attribute [ ] } all note ' s relations ( attributes with type relation ) , including inherited ones
2018-12-22 22:16:32 +01:00
* /
2020-03-18 22:35:54 +01:00
getRelations ( name ) {
return this . getAttributes ( RELATION , name ) ;
2018-12-22 22:16:32 +01:00
}
/ * *
* @ param { string } type - attribute type ( label , relation , etc . )
* @ param { string } name - attribute name
2020-03-18 22:35:54 +01:00
* @ returns { boolean } true if note has an attribute with given type and name ( including inherited )
2018-12-22 22:16:32 +01:00
* /
2020-03-18 22:35:54 +01:00
hasAttribute ( type , name ) {
return ! ! this . getAttribute ( type , name ) ;
2018-12-22 22:16:32 +01:00
}
2020-01-25 13:27:23 +01:00
/ * *
* @ param { string } type - attribute type ( label , relation , etc . )
* @ param { string } name - attribute name
* @ returns { boolean } true if note has an attribute with given type and name ( including inherited )
* /
hasOwnedAttribute ( type , name ) {
return ! ! this . getOwnedAttribute ( type , name ) ;
}
/ * *
* @ param { string } type - attribute type ( label , relation , etc . )
* @ param { string } name - attribute name
* @ returns { 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 .
* /
getOwnedAttribute ( type , name ) {
const attributes = this . getOwnedAttributes ( type , name ) ;
return attributes . length > 0 ? attributes [ 0 ] : 0 ;
}
2018-12-22 22:16:32 +01:00
/ * *
* @ param { string } type - attribute type ( label , relation , etc . )
* @ param { string } name - attribute name
2020-03-18 22:35:54 +01:00
* @ returns { 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 .
2018-12-22 22:16:32 +01:00
* /
2020-03-18 22:35:54 +01:00
getAttribute ( type , name ) {
const attributes = this . getAttributes ( type , name ) ;
2020-01-25 13:27:23 +01:00
2020-10-08 22:08:58 +02:00
return attributes . length > 0 ? attributes [ 0 ] : null ;
2020-01-25 13:27:23 +01:00
}
/ * *
* @ param { string } type - attribute type ( label , relation , etc . )
* @ param { string } name - attribute name
* @ returns { string } attribute value of given type and name or null if no such attribute exists .
* /
getOwnedAttributeValue ( type , name ) {
const attr = this . getOwnedAttribute ( type , name ) ;
2018-12-22 22:16:32 +01:00
2020-01-25 13:27:23 +01:00
return attr ? attr . value : null ;
2018-12-22 22:16:32 +01:00
}
/ * *
* @ param { string } type - attribute type ( label , relation , etc . )
* @ param { string } name - attribute name
2020-03-18 22:35:54 +01:00
* @ returns { string } attribute value of given type and name or null if no such attribute exists .
2018-12-22 22:16:32 +01:00
* /
2020-03-18 22:35:54 +01:00
getAttributeValue ( type , name ) {
const attr = this . getAttribute ( type , name ) ;
2018-12-22 22:16:32 +01:00
return attr ? attr . value : null ;
}
2020-01-25 13:27:23 +01:00
/ * *
* @ param { string } name - label name
* @ returns { boolean } true if label exists ( excluding inherited )
* /
hasOwnedLabel ( name ) { return this . hasOwnedAttribute ( LABEL , name ) ; }
2018-12-22 22:16:32 +01:00
/ * *
* @ param { string } name - label name
2020-03-18 22:35:54 +01:00
* @ returns { boolean } true if label exists ( including inherited )
2018-12-22 22:16:32 +01:00
* /
2020-03-18 22:35:54 +01:00
hasLabel ( name ) { return this . hasAttribute ( LABEL , name ) ; }
2018-12-22 22:16:32 +01:00
2020-01-25 13:27:23 +01:00
/ * *
* @ param { string } name - relation name
* @ returns { boolean } true if relation exists ( excluding inherited )
* /
hasOwnedRelation ( name ) { return this . hasOwnedAttribute ( RELATION , name ) ; }
2018-12-22 22:16:32 +01:00
/ * *
* @ param { string } name - relation name
2020-03-18 22:35:54 +01:00
* @ returns { boolean } true if relation exists ( including inherited )
2018-12-22 22:16:32 +01:00
* /
2020-03-18 22:35:54 +01:00
hasRelation ( name ) { return this . hasAttribute ( RELATION , name ) ; }
2018-12-22 22:16:32 +01:00
2020-01-25 13:27:23 +01:00
/ * *
* @ param { string } name - label name
* @ returns { Attribute } label if it exists , null otherwise
* /
getOwnedLabel ( name ) { return this . getOwnedAttribute ( LABEL , name ) ; }
2018-12-22 22:16:32 +01:00
/ * *
* @ param { string } name - label name
2020-03-18 22:35:54 +01:00
* @ returns { Attribute } label if it exists , null otherwise
2018-12-22 22:16:32 +01:00
* /
2020-03-18 22:35:54 +01:00
getLabel ( name ) { return this . getAttribute ( LABEL , name ) ; }
2018-12-22 22:16:32 +01:00
2020-01-25 13:27:23 +01:00
/ * *
* @ param { string } name - relation name
* @ returns { Attribute } relation if it exists , null otherwise
* /
getOwnedRelation ( name ) { return this . getOwnedAttribute ( RELATION , name ) ; }
2018-12-22 22:16:32 +01:00
/ * *
* @ param { string } name - relation name
2020-03-18 22:35:54 +01:00
* @ returns { Attribute } relation if it exists , null otherwise
2018-12-22 22:16:32 +01:00
* /
2020-03-18 22:35:54 +01:00
getRelation ( name ) { return this . getAttribute ( RELATION , name ) ; }
2018-12-22 22:16:32 +01:00
2020-01-25 13:27:23 +01:00
/ * *
* @ param { string } name - label name
* @ returns { string } label value if label exists , null otherwise
* /
getOwnedLabelValue ( name ) { return this . getOwnedAttributeValue ( LABEL , name ) ; }
2018-12-22 22:16:32 +01:00
/ * *
* @ param { string } name - label name
2020-03-18 22:35:54 +01:00
* @ returns { string } label value if label exists , null otherwise
2018-12-22 22:16:32 +01:00
* /
2020-03-18 22:35:54 +01:00
getLabelValue ( name ) { return this . getAttributeValue ( LABEL , name ) ; }
2018-12-22 22:16:32 +01:00
2020-01-25 13:27:23 +01:00
/ * *
* @ param { string } name - relation name
* @ returns { string } relation value if relation exists , null otherwise
* /
getOwnedRelationValue ( name ) { return this . getOwnedAttributeValue ( RELATION , name ) ; }
2018-12-22 22:16:32 +01:00
/ * *
* @ param { string } name - relation name
2020-03-18 22:35:54 +01:00
* @ returns { string } relation value if relation exists , null otherwise
2018-12-22 22:16:32 +01:00
* /
2020-03-18 22:35:54 +01:00
getRelationValue ( name ) { return this . getAttributeValue ( RELATION , name ) ; }
2018-12-22 22:16:32 +01:00
/ * *
* @ param { string } name
2019-08-17 11:28:36 +02:00
* @ returns { Promise < NoteShort > | null } target note of the relation or null ( if target is empty or note was not found )
2018-12-22 22:16:32 +01:00
* /
async getRelationTarget ( name ) {
2019-08-17 11:28:36 +02:00
const targets = await this . getRelationTargets ( name ) ;
2018-12-22 22:16:32 +01:00
2019-08-17 11:28:36 +02:00
return targets . length > 0 ? targets [ 0 ] : null ;
}
/ * *
* @ param { string } [ name ] - relation name to filter
* @ returns { Promise < NoteShort [ ] > }
* /
async getRelationTargets ( name ) {
2020-03-18 22:42:29 +01:00
const relations = this . getRelations ( name ) ;
2019-08-17 11:28:36 +02:00
const targets = [ ] ;
for ( const relation of relations ) {
targets . push ( await this . treeCache . getNote ( relation . value ) ) ;
}
return targets ;
2018-12-22 22:16:32 +01:00
}
2020-06-09 22:59:22 +02:00
/ * *
* @ returns { NoteShort [ ] }
* /
getTemplateNotes ( ) {
const relations = this . getRelations ( 'template' ) ;
return relations . map ( rel => this . treeCache . notes [ rel . value ] ) ;
}
2021-01-23 21:41:02 +01:00
getPromotedDefinitionAttributes ( ) {
if ( this . hasLabel ( 'hidePromotedAttributes' ) ) {
return [ ] ;
}
return this . getAttributes ( )
. filter ( attr => attr . isDefinition ( ) )
. filter ( attr => {
const def = attr . getDefinition ( ) ;
return def && def . isPromoted ;
} ) ;
}
2021-02-09 20:15:14 +01:00
hasAncestor ( ancestorNote , visitedNoteIds ) {
2020-06-09 22:59:22 +02:00
if ( this . noteId === ancestorNote . noteId ) {
return true ;
}
2021-02-09 20:15:14 +01:00
if ( ! visitedNoteIds ) {
visitedNoteIds = new Set ( ) ;
} else if ( visitedNoteIds . has ( this . noteId ) ) {
// to avoid infinite cycle when template is descendent of the instance
return false ;
}
visitedNoteIds . add ( this . noteId ) ;
2020-06-09 22:59:22 +02:00
for ( const templateNote of this . getTemplateNotes ( ) ) {
2021-02-09 20:26:10 +01:00
if ( templateNote . hasAncestor ( ancestorNote , visitedNoteIds ) ) {
2020-06-09 22:59:22 +02:00
return true ;
}
}
for ( const parentNote of this . getParentNotes ( ) ) {
2021-02-09 20:26:10 +01:00
if ( parentNote . hasAncestor ( ancestorNote , visitedNoteIds ) ) {
2020-06-09 22:59:22 +02:00
return true ;
}
}
return false ;
}
2018-12-22 22:16:32 +01:00
/ * *
* Clear note ' s attributes cache to force fresh reload for next attribute request .
* Cache is note instance scoped .
* /
2020-01-25 11:52:45 +01:00
invalidateAttributeCache ( ) {
2019-12-01 12:22:22 +01:00
this . _ _attributeCache = null ;
2018-12-22 22:16:32 +01:00
}
2019-08-19 20:12:00 +02:00
/ * *
2019-08-19 20:59:40 +02:00
* Get relations which target this note
*
2020-01-25 13:27:23 +01:00
* @ returns { Attribute [ ] }
2019-08-19 20:12:00 +02:00
* /
2020-01-25 13:27:23 +01:00
getTargetRelations ( ) {
return this . targetRelations
. map ( attributeId => this . treeCache . attributes [ attributeId ] ) ;
2019-08-19 20:12:00 +02:00
}
2020-09-05 22:45:26 +02:00
/ * *
* Get relations which target this note
*
* @ returns { NoteShort [ ] }
* /
async getTargetRelationSourceNotes ( ) {
const targetRelations = this . getTargetRelations ( ) ;
return await this . treeCache . getNotes ( targetRelations . map ( tr => tr . noteId ) ) ;
}
2020-06-14 14:30:57 +02:00
/ * *
* Return note complement which is most importantly note ' s content
*
* @ return { Promise < NoteComplement > }
* /
async getNoteComplement ( ) {
return await this . treeCache . getNoteComplement ( this . noteId ) ;
}
2018-03-25 12:29:00 -04:00
get toString ( ) {
return ` Note(noteId= ${ this . noteId } , title= ${ this . title } ) ` ;
}
2018-04-08 08:21:49 -04:00
get dto ( ) {
const dto = Object . assign ( { } , this ) ;
delete dto . treeCache ;
return dto ;
}
2020-02-25 09:40:49 +01:00
2020-03-18 22:42:29 +01:00
getCssClass ( ) {
const labels = this . getLabels ( 'cssClass' ) ;
2020-02-25 09:40:49 +01:00
return labels . map ( l => l . value ) . join ( ' ' ) ;
}
2020-11-24 23:24:05 +01:00
2020-11-25 20:25:55 +01:00
getWorkspaceIconClass ( ) {
const labels = this . getLabels ( 'workspaceIconClass' ) ;
return labels . length > 0 ? labels [ 0 ] . value : "" ;
}
getWorkspaceTabBackgroundColor ( ) {
const labels = this . getLabels ( 'workspaceTabBackgroundColor' ) ;
return labels . length > 0 ? labels [ 0 ] . value : "" ;
2020-11-24 23:24:05 +01:00
}
2018-03-25 12:29:00 -04:00
}
2020-06-04 12:27:41 +02:00
export default NoteShort ;