| 
									
										
										
										
											2018-03-25 12:29:00 -04:00
										 |  |  | class NoteShort { | 
					
						
							|  |  |  |     constructor(treeCache, row) { | 
					
						
							|  |  |  |         this.treeCache = treeCache; | 
					
						
							|  |  |  |         this.noteId = row.noteId; | 
					
						
							|  |  |  |         this.title = row.title; | 
					
						
							|  |  |  |         this.isProtected = row.isProtected; | 
					
						
							|  |  |  |         this.type = row.type; | 
					
						
							|  |  |  |         this.mime = row.mime; | 
					
						
							| 
									
										
										
										
											2018-06-07 19:26:28 -04:00
										 |  |  |         this.archived = row.archived; | 
					
						
							| 
									
										
										
										
											2018-08-13 10:59:31 +02:00
										 |  |  |         this.cssClass = row.cssClass; | 
					
						
							| 
									
										
										
										
											2018-03-25 12:29:00 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 23:25:17 -04:00
										 |  |  |     isJson() { | 
					
						
							|  |  |  |         return this.mime === "application/json"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 12:29:00 -04:00
										 |  |  |     async getBranches() { | 
					
						
							| 
									
										
										
										
											2018-04-16 23:13:33 -04:00
										 |  |  |         const branchIds = this.treeCache.parents[this.noteId].map( | 
					
						
							|  |  |  |             parentNoteId => this.treeCache.getBranchIdByChildParent(this.noteId, parentNoteId)); | 
					
						
							| 
									
										
										
										
											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-04-16 20:40:18 -04:00
										 |  |  |     hasChildren() { | 
					
						
							|  |  |  |         return this.treeCache.children[this.noteId] | 
					
						
							|  |  |  |             && this.treeCache.children[this.noteId].length > 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 12:29:00 -04:00
										 |  |  |     async getChildBranches() { | 
					
						
							| 
									
										
										
										
											2018-04-10 23:15:41 -04:00
										 |  |  |         if (!this.treeCache.children[this.noteId]) { | 
					
						
							| 
									
										
										
										
											2018-04-10 21:08:00 -04:00
										 |  |  |             return []; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-16 23:13:33 -04:00
										 |  |  |         const branchIds = this.treeCache.children[this.noteId].map( | 
					
						
							|  |  |  |             childNoteId => this.treeCache.getBranchIdByChildParent(childNoteId, this.noteId)); | 
					
						
							| 
									
										
										
										
											2018-03-25 12:29:00 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-16 23:13:33 -04:00
										 |  |  |         return await this.treeCache.getBranches(branchIds); | 
					
						
							| 
									
										
										
										
											2018-03-25 12:29:00 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-16 23:34:56 -04:00
										 |  |  |     getParentNoteIds() { | 
					
						
							|  |  |  |         return this.treeCache.parents[this.noteId] || []; | 
					
						
							| 
									
										
										
										
											2018-04-16 20:40:18 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 12:29:00 -04:00
										 |  |  |     async getParentNotes() { | 
					
						
							| 
									
										
										
										
											2018-04-16 23:34:56 -04:00
										 |  |  |         return await this.treeCache.getNotes(this.getParentNoteIds()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     getChildNoteIds() { | 
					
						
							|  |  |  |         return this.treeCache.children[this.noteId] || []; | 
					
						
							| 
									
										
										
										
											2018-03-25 12:29:00 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async getChildNotes() { | 
					
						
							| 
									
										
										
										
											2018-04-16 23:34:56 -04:00
										 |  |  |         return await this.treeCache.getNotes(this.getChildNoteIds()); | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2018-06-07 19:26:28 -04:00
										 |  |  |         delete dto.archived; | 
					
						
							| 
									
										
										
										
											2018-04-08 08:21:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return dto; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-03-25 12:29:00 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default NoteShort; |