Notes/src/public/app/entities/attribute.js

65 lines
1.7 KiB
JavaScript
Raw Normal View History

import promotedAttributeDefinitionParser from '../services/promoted_attribute_definition_parser.js';
class Attribute {
2021-04-16 22:57:37 +02:00
constructor(froca, row) {
this.froca = froca;
2020-01-29 22:32:22 +01:00
this.update(row);
}
update(row) {
2021-10-29 21:37:12 +02:00
/** @type {string} attributeId */
this.attributeId = row.attributeId;
2021-10-29 21:37:12 +02:00
/** @type {string} noteId */
this.noteId = row.noteId;
2021-10-29 21:37:12 +02:00
/** @type {string} type */
this.type = row.type;
2021-10-29 21:37:12 +02:00
/** @type {string} name */
this.name = row.name;
2021-10-29 21:37:12 +02:00
/** @type {string} value */
this.value = row.value;
2021-10-29 21:37:12 +02:00
/** @type {int} position */
this.position = row.position;
2021-10-29 21:37:12 +02:00
/** @type {boolean} isInheritable */
2020-07-13 23:27:23 +02:00
this.isInheritable = !!row.isInheritable;
}
/** @returns {NoteShort} */
getNote() {
2021-04-16 22:57:37 +02:00
return this.froca.notes[this.noteId];
}
2020-06-14 14:30:57 +02:00
get targetNoteId() { // alias
return this.type === 'relation' ? this.value : undefined;
}
get isAutoLink() {
return this.type === 'relation' && ['internalLink', 'imageLink', 'relationMapLink', 'includeNoteLink'].includes(this.name);
}
get toString() {
return `Attribute(attributeId=${this.attributeId}, type=${this.type}, name=${this.name}, value=${this.value})`;
}
2020-07-01 00:02:13 +02:00
isDefinition() {
return this.type === 'label' && (this.name.startsWith('label:') || this.name.startsWith('relation:'));
}
getDefinition() {
return promotedAttributeDefinitionParser.parse(this.value);
2020-07-01 00:02:13 +02:00
}
2021-01-19 22:10:24 +01:00
isDefinitionFor(attr) {
return this.type === 'label' && this.name === `${attr.type}:${attr.name}`;
}
2021-01-19 22:10:24 +01:00
get dto() {
const dto = Object.assign({}, this);
2021-04-16 22:57:37 +02:00
delete dto.froca;
2021-01-19 22:10:24 +01:00
return dto;
}
2018-12-28 22:05:04 +01:00
}
export default Attribute;