mirror of
https://github.com/zadam/trilium.git
synced 2025-10-28 00:36:33 +01:00
docs update
This commit is contained in:
@@ -90,8 +90,9 @@ class Attribute extends AbstractEntity {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
init() {
|
||||
this.validate();
|
||||
|
||||
if (this.attributeId) {
|
||||
this.becca.attributes[this.attributeId] = this;
|
||||
}
|
||||
@@ -114,6 +115,16 @@ class Attribute extends AbstractEntity {
|
||||
}
|
||||
}
|
||||
|
||||
validate() {
|
||||
if (!["label", "relation"].includes(this.type)) {
|
||||
throw new Error(`Invalid attribute type '${this.type}' in attribute '${this.attributeId}'`);
|
||||
}
|
||||
|
||||
if (!this.name?.trim()) {
|
||||
throw new Error(`Invalid empty name in attribute '${this.attributeId}'`);
|
||||
}
|
||||
}
|
||||
|
||||
get isAffectingSubtree() {
|
||||
return this.isInheritable
|
||||
|| (this.type === 'relation' && this.name === 'template');
|
||||
@@ -141,7 +152,13 @@ class Attribute extends AbstractEntity {
|
||||
* @returns {Note|null}
|
||||
*/
|
||||
getNote() {
|
||||
return this.becca.getNote(this.noteId);
|
||||
const note = this.becca.getNote(this.noteId);
|
||||
|
||||
if (!note) {
|
||||
throw new Error(`Note '${this.noteId}' of attribute '${this.attributeId}', type '${this.type}', name '${this.name}' does not exist.`);
|
||||
}
|
||||
|
||||
return note;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,11 +202,13 @@ class Attribute extends AbstractEntity {
|
||||
}
|
||||
|
||||
beforeSaving() {
|
||||
if (!this.value) {
|
||||
if (this.type === 'relation') {
|
||||
throw new Error(`Cannot save relation ${this.name} since it does not target any note.`);
|
||||
}
|
||||
this.validate();
|
||||
|
||||
if (this.type === 'relation') {
|
||||
if (!(this.value in this.becca.notes)) {
|
||||
throw new Error(`Cannot save relation '${this.name}' since it target not existing note '${this.value}'.`);
|
||||
}
|
||||
} else if (!this.value) {
|
||||
// null value isn't allowed
|
||||
this.value = "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user