2018-12-22 22:16:32 +01:00
|
|
|
class Attribute {
|
|
|
|
constructor(treeCache, row) {
|
|
|
|
this.treeCache = treeCache;
|
2020-01-29 22:32:22 +01:00
|
|
|
|
|
|
|
this.update(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
update(row) {
|
2018-12-22 22:16:32 +01:00
|
|
|
/** @param {string} attributeId */
|
|
|
|
this.attributeId = row.attributeId;
|
|
|
|
/** @param {string} noteId */
|
|
|
|
this.noteId = row.noteId;
|
|
|
|
/** @param {string} type */
|
|
|
|
this.type = row.type;
|
|
|
|
/** @param {string} name */
|
|
|
|
this.name = row.name;
|
|
|
|
/** @param {string} value */
|
|
|
|
this.value = row.value;
|
|
|
|
/** @param {int} position */
|
|
|
|
this.position = row.position;
|
|
|
|
/** @param {boolean} isInheritable */
|
|
|
|
this.isInheritable = row.isInheritable;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @returns {NoteShort} */
|
2020-06-09 22:59:22 +02:00
|
|
|
getNote() {
|
|
|
|
return this.treeCache.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-04-04 22:40:32 +02:00
|
|
|
get jsonValue() {
|
|
|
|
try {
|
|
|
|
return JSON.parse(this.value);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {boolean} - returns true if this attribute has the potential to influence the note in the argument.
|
|
|
|
* That can happen in multiple ways:
|
|
|
|
* 1. attribute is owned by the note
|
|
|
|
* 2. attribute is owned by the template of the note
|
|
|
|
* 3. attribute is owned by some note's ancestor and is inheritable
|
|
|
|
*/
|
|
|
|
isAffecting(affectedNote) {
|
2020-06-27 00:40:35 +02:00
|
|
|
if (!affectedNote) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-09 22:59:22 +02:00
|
|
|
const attrNote = this.getNote();
|
|
|
|
const owningNotes = [affectedNote, ...affectedNote.getTemplateNotes()];
|
|
|
|
|
|
|
|
for (const owningNote of owningNotes) {
|
|
|
|
if (owningNote.noteId === attrNote.noteId) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.isInheritable) {
|
|
|
|
for (const owningNote of owningNotes) {
|
|
|
|
if (owningNote.hasAncestor(attrNote)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2018-12-28 22:05:04 +01:00
|
|
|
}
|
|
|
|
|
2020-05-28 23:59:08 +02:00
|
|
|
export default Attribute;
|