2020-05-17 09:48:24 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-08-27 23:54:02 +02:00
|
|
|
const Note = require('./note.js');
|
2020-08-27 22:37:57 +02:00
|
|
|
|
2020-05-16 23:12:29 +02:00
|
|
|
class Attribute {
|
2020-05-17 10:11:19 +02:00
|
|
|
constructor(noteCache, row) {
|
|
|
|
/** @param {NoteCache} */
|
|
|
|
this.noteCache = noteCache;
|
2020-05-16 23:12:29 +02:00
|
|
|
/** @param {string} */
|
|
|
|
this.attributeId = row.attributeId;
|
|
|
|
/** @param {string} */
|
|
|
|
this.noteId = row.noteId;
|
|
|
|
/** @param {string} */
|
|
|
|
this.type = row.type;
|
|
|
|
/** @param {string} */
|
2020-12-12 12:07:15 +01:00
|
|
|
this.name = row.name;
|
2020-12-11 22:06:12 +01:00
|
|
|
/** @param {int} */
|
|
|
|
this.position = row.position;
|
2020-05-16 23:12:29 +02:00
|
|
|
/** @param {string} */
|
2020-12-13 23:27:42 +01:00
|
|
|
this.value = row.value;
|
2020-05-16 23:12:29 +02:00
|
|
|
/** @param {boolean} */
|
|
|
|
this.isInheritable = !!row.isInheritable;
|
|
|
|
|
2020-05-22 09:38:30 +02:00
|
|
|
this.noteCache.attributes[this.attributeId] = this;
|
2020-08-27 22:37:57 +02:00
|
|
|
|
|
|
|
if (!(this.noteId in this.noteCache.notes)) {
|
|
|
|
// entities can come out of order in sync, create skeleton which will be filled later
|
|
|
|
this.noteCache.notes[this.noteId] = new Note(this.noteCache, {noteId: this.noteId});
|
|
|
|
}
|
|
|
|
|
2020-05-17 10:11:19 +02:00
|
|
|
this.noteCache.notes[this.noteId].ownedAttributes.push(this);
|
2020-05-16 23:12:29 +02:00
|
|
|
|
2020-12-14 22:12:26 +01:00
|
|
|
const key = `${this.type}-${this.name.toLowerCase()}`;
|
2020-05-17 10:11:19 +02:00
|
|
|
this.noteCache.attributeIndex[key] = this.noteCache.attributeIndex[key] || [];
|
|
|
|
this.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 10:11:19 +02:00
|
|
|
return this.noteCache.notes[this.noteId];
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get targetNote() {
|
|
|
|
if (this.type === 'relation') {
|
2020-05-17 10:11:19 +02:00
|
|
|
return this.noteCache.notes[this.value];
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
}
|
2021-02-10 22:56:23 +01:00
|
|
|
|
|
|
|
// for logging etc
|
|
|
|
get pojo() {
|
|
|
|
const pojo = {...this};
|
|
|
|
|
|
|
|
delete pojo.noteCache;
|
|
|
|
|
|
|
|
return pojo;
|
|
|
|
}
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
2020-05-17 09:48:24 +02:00
|
|
|
|
|
|
|
module.exports = Attribute;
|