2021-10-16 22:13:34 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-04-09 21:48:15 +03:00
|
|
|
const AbstractShacaEntity = require('./abstract_shaca_entity');
|
2021-10-16 22:13:34 +02:00
|
|
|
|
2023-01-03 13:40:21 +01:00
|
|
|
class SAttribute extends AbstractShacaEntity {
|
2021-10-17 14:44:59 +02:00
|
|
|
constructor([attributeId, noteId, type, name, value, isInheritable, position]) {
|
|
|
|
super();
|
2021-10-16 22:13:34 +02:00
|
|
|
|
|
|
|
/** @param {string} */
|
|
|
|
this.attributeId = attributeId;
|
|
|
|
/** @param {string} */
|
|
|
|
this.noteId = noteId;
|
|
|
|
/** @param {string} */
|
|
|
|
this.type = type;
|
|
|
|
/** @param {string} */
|
|
|
|
this.name = name;
|
2023-06-29 23:32:19 +02:00
|
|
|
/** @param {int} */
|
2021-10-16 22:13:34 +02:00
|
|
|
this.position = position;
|
|
|
|
/** @param {string} */
|
|
|
|
this.value = value;
|
|
|
|
/** @param {boolean} */
|
|
|
|
this.isInheritable = !!isInheritable;
|
|
|
|
|
2021-10-17 14:44:59 +02:00
|
|
|
this.shaca.attributes[this.attributeId] = this;
|
|
|
|
this.shaca.notes[this.noteId].ownedAttributes.push(this);
|
2021-10-16 22:13:34 +02:00
|
|
|
|
|
|
|
const targetNote = this.targetNote;
|
|
|
|
|
|
|
|
if (targetNote) {
|
|
|
|
targetNote.targetRelations.push(this);
|
|
|
|
}
|
2021-10-19 22:48:38 +02:00
|
|
|
|
|
|
|
if (this.type === 'relation' && this.name === 'imageLink') {
|
|
|
|
const linkedChildNote = this.note.getChildNotes().find(childNote => childNote.noteId === this.value);
|
|
|
|
|
|
|
|
if (linkedChildNote) {
|
2022-04-15 23:09:07 +02:00
|
|
|
const branch = this.shaca.getBranchFromChildAndParent(linkedChildNote.noteId, this.noteId);
|
2021-10-19 22:48:38 +02:00
|
|
|
|
2022-03-22 23:17:47 +01:00
|
|
|
branch.isHidden = true;
|
2021-10-19 22:48:38 +02:00
|
|
|
}
|
|
|
|
}
|
2021-12-22 10:57:02 +01:00
|
|
|
|
|
|
|
if (this.type === 'label' && this.name === 'shareAlias' && this.value.trim()) {
|
|
|
|
this.shaca.aliasToNote[this.value.trim()] = this.note;
|
|
|
|
}
|
2022-01-17 23:13:56 +01:00
|
|
|
|
|
|
|
if (this.type === 'label' && this.name === 'shareRoot') {
|
|
|
|
this.shaca.shareRootNote = this.note;
|
|
|
|
}
|
2022-12-19 21:39:12 +01:00
|
|
|
|
|
|
|
if (this.type === 'label' && this.name === 'shareIndex') {
|
|
|
|
this.shaca.shareIndexEnabled = true;
|
|
|
|
}
|
2021-10-16 22:13:34 +02:00
|
|
|
}
|
|
|
|
|
2022-11-01 22:49:37 +01:00
|
|
|
/** @returns {boolean} */
|
2021-10-16 22:13:34 +02:00
|
|
|
get isAffectingSubtree() {
|
|
|
|
return this.isInheritable
|
2023-01-06 20:31:55 +01:00
|
|
|
|| (this.type === 'relation' && ['template', 'inherit'].includes(this.name));
|
2021-10-16 22:13:34 +02:00
|
|
|
}
|
|
|
|
|
2022-11-01 22:49:37 +01:00
|
|
|
/** @returns {string} */
|
2021-10-16 22:13:34 +02:00
|
|
|
get targetNoteId() { // alias
|
|
|
|
return this.type === 'relation' ? this.value : undefined;
|
|
|
|
}
|
|
|
|
|
2022-11-01 22:49:37 +01:00
|
|
|
/** @returns {boolean} */
|
2021-10-16 22:13:34 +02:00
|
|
|
isAutoLink() {
|
|
|
|
return this.type === 'relation' && ['internalLink', 'imageLink', 'relationMapLink', 'includeNoteLink'].includes(this.name);
|
|
|
|
}
|
|
|
|
|
2023-06-05 23:05:05 +02:00
|
|
|
/** @returns {SNote} */
|
2021-10-16 22:13:34 +02:00
|
|
|
get note() {
|
2021-10-17 14:44:59 +02:00
|
|
|
return this.shaca.notes[this.noteId];
|
2021-10-16 22:13:34 +02:00
|
|
|
}
|
|
|
|
|
2023-01-03 13:40:21 +01:00
|
|
|
/** @returns {SNote|null} */
|
2021-10-16 22:13:34 +02:00
|
|
|
get targetNote() {
|
|
|
|
if (this.type === 'relation') {
|
2021-10-17 14:44:59 +02:00
|
|
|
return this.shaca.notes[this.value];
|
2021-10-16 22:13:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-03 13:40:21 +01:00
|
|
|
/** @returns {SNote|null} */
|
2021-10-16 22:13:34 +02:00
|
|
|
getNote() {
|
2021-10-17 14:44:59 +02:00
|
|
|
return this.shaca.getNote(this.noteId);
|
2021-10-16 22:13:34 +02:00
|
|
|
}
|
|
|
|
|
2023-01-03 13:40:21 +01:00
|
|
|
/** @returns {SNote|null} */
|
2021-10-16 22:13:34 +02:00
|
|
|
getTargetNote() {
|
|
|
|
if (this.type !== 'relation') {
|
2023-05-04 22:16:18 +02:00
|
|
|
throw new Error(`Attribute '${this.attributeId}' is not relation`);
|
2021-10-16 22:13:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.value) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-10-17 14:44:59 +02:00
|
|
|
return this.shaca.getNote(this.value);
|
2021-10-16 22:13:34 +02:00
|
|
|
}
|
2022-01-01 13:23:09 +01:00
|
|
|
|
|
|
|
getPojo() {
|
|
|
|
return {
|
|
|
|
attributeId: this.attributeId,
|
|
|
|
noteId: this.noteId,
|
|
|
|
type: this.type,
|
|
|
|
name: this.name,
|
|
|
|
position: this.position,
|
|
|
|
value: this.value,
|
|
|
|
isInheritable: this.isInheritable
|
|
|
|
};
|
|
|
|
}
|
2021-10-16 22:13:34 +02:00
|
|
|
}
|
|
|
|
|
2023-01-03 13:40:21 +01:00
|
|
|
module.exports = SAttribute;
|