2020-07-18 23:45:28 +02:00
|
|
|
import promotedAttributeDefinitionParser from '../services/promoted_attribute_definition_parser.js';
|
|
|
|
|
2018-12-22 22:16:32 +01:00
|
|
|
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 */
|
2018-12-22 22:16:32 +01:00
|
|
|
this.attributeId = row.attributeId;
|
2021-10-29 21:37:12 +02:00
|
|
|
/** @type {string} noteId */
|
2018-12-22 22:16:32 +01:00
|
|
|
this.noteId = row.noteId;
|
2021-10-29 21:37:12 +02:00
|
|
|
/** @type {string} type */
|
2018-12-22 22:16:32 +01:00
|
|
|
this.type = row.type;
|
2021-10-29 21:37:12 +02:00
|
|
|
/** @type {string} name */
|
2018-12-22 22:16:32 +01:00
|
|
|
this.name = row.name;
|
2021-10-29 21:37:12 +02:00
|
|
|
/** @type {string} value */
|
2018-12-22 22:16:32 +01:00
|
|
|
this.value = row.value;
|
2021-10-29 21:37:12 +02:00
|
|
|
/** @type {int} position */
|
2018-12-22 22:16:32 +01:00
|
|
|
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;
|
2018-12-22 22:16:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @returns {NoteShort} */
|
2020-06-09 22:59:22 +02:00
|
|
|
getNote() {
|
2021-04-16 22:57:37 +02:00
|
|
|
return this.froca.notes[this.noteId];
|
2018-12-22 22:16:32 +01:00
|
|
|
}
|
|
|
|
|
2020-06-14 14:30:57 +02:00
|
|
|
get targetNoteId() { // alias
|
|
|
|
return this.type === 'relation' ? this.value : undefined;
|
2018-12-22 22:16:32 +01:00
|
|
|
}
|
|
|
|
|
2020-05-28 23:59:08 +02:00
|
|
|
get isAutoLink() {
|
|
|
|
return this.type === 'relation' && ['internalLink', 'imageLink', 'relationMapLink', 'includeNoteLink'].includes(this.name);
|
|
|
|
}
|
|
|
|
|
2018-12-22 22:16:32 +01:00
|
|
|
get toString() {
|
2020-01-25 11:52:45 +01:00
|
|
|
return `Attribute(attributeId=${this.attributeId}, type=${this.type}, name=${this.name}, value=${this.value})`;
|
2018-12-22 22:16:32 +01:00
|
|
|
}
|
2020-06-09 22:59:22 +02:00
|
|
|
|
2020-07-01 00:02:13 +02:00
|
|
|
isDefinition() {
|
|
|
|
return this.type === 'label' && (this.name.startsWith('label:') || this.name.startsWith('relation:'));
|
|
|
|
}
|
|
|
|
|
|
|
|
getDefinition() {
|
2020-07-18 23:45:28 +02:00
|
|
|
return promotedAttributeDefinitionParser.parse(this.value);
|
2020-07-01 00:02:13 +02:00
|
|
|
}
|
2021-01-19 22:10:24 +01:00
|
|
|
|
2021-01-23 21:41:02 +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
|
|
|
}
|
|
|
|
|
2020-05-28 23:59:08 +02:00
|
|
|
export default Attribute;
|