| 
									
										
										
										
											2020-05-17 09:48:24 +02:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const noteCache = require('../note_cache'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  | class Attribute { | 
					
						
							|  |  |  |     constructor(row) { | 
					
						
							|  |  |  |         /** @param {string} */ | 
					
						
							|  |  |  |         this.attributeId = row.attributeId; | 
					
						
							|  |  |  |         /** @param {string} */ | 
					
						
							|  |  |  |         this.noteId = row.noteId; | 
					
						
							|  |  |  |         /** @param {string} */ | 
					
						
							|  |  |  |         this.type = row.type; | 
					
						
							|  |  |  |         /** @param {string} */ | 
					
						
							|  |  |  |         this.name = row.name; | 
					
						
							|  |  |  |         /** @param {string} */ | 
					
						
							|  |  |  |         this.value = row.value; | 
					
						
							|  |  |  |         /** @param {boolean} */ | 
					
						
							|  |  |  |         this.isInheritable = !!row.isInheritable; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-17 09:48:24 +02:00
										 |  |  |         noteCache.notes[this.noteId].ownedAttributes.push(this); | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const key = `${this.type-this.name}`; | 
					
						
							| 
									
										
										
										
											2020-05-17 09:48:24 +02:00
										 |  |  |         noteCache.attributeIndex[key] = noteCache.attributeIndex[key] || []; | 
					
						
							|  |  |  |         noteCache.attributeIndex[key].push(this); | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const targetNote = this.targetNote; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (targetNote) { | 
					
						
							|  |  |  |             targetNote.targetRelations.push(this); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     get isAffectingSubtree() { | 
					
						
							|  |  |  |         return this.isInheritable | 
					
						
							|  |  |  |             || (this.type === 'relation' && this.name === 'template'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     get note() { | 
					
						
							| 
									
										
										
										
											2020-05-17 09:48:24 +02:00
										 |  |  |         return noteCache.notes[this.noteId]; | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     get targetNote() { | 
					
						
							|  |  |  |         if (this.type === 'relation') { | 
					
						
							| 
									
										
										
										
											2020-05-17 09:48:24 +02:00
										 |  |  |             return noteCache.notes[this.value]; | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-17 09:48:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | module.exports = Attribute; |