fixing promoted attributes

This commit is contained in:
zadam
2020-07-01 00:02:13 +02:00
parent c012620338
commit bf073690e0
2 changed files with 51 additions and 27 deletions

View File

@@ -31,15 +31,6 @@ class Attribute {
return this.type === 'relation' ? this.value : undefined;
}
get jsonValue() {
try {
return JSON.parse(this.value);
}
catch (e) {
return null;
}
}
get isAutoLink() {
return this.type === 'relation' && ['internalLink', 'imageLink', 'relationMapLink', 'includeNoteLink'].includes(this.name);
}
@@ -79,6 +70,42 @@ class Attribute {
return false;
}
isDefinition() {
return this.type === 'label' && (this.name.startsWith('label:') || this.name.startsWith('relation:'));
}
getDefinition() {
const tokens = this.value.split(',').map(t => t.trim());
const defObj = {};
for (const token of tokens) {
if (token === 'promoted') {
defObj.isPromoted = true;
}
else if (['text', 'number', 'boolean', 'date', 'url'].includes(token)) {
defObj.labelType = token;
}
else if (['single', 'multi'].includes(token)) {
defObj.multiplicity = token;
}
else if (token.startsWith('precision')) {
const chunks = token.split('=');
defObj.numberPrecision = parseInt(chunks[1]);
}
else if (token.startsWith('inverse')) {
const chunks = token.split('=');
defObj.inverseRelation = chunks[1];
}
else {
console.log("Unrecognized attribute definition token:", token);
}
}
return defObj;
}
}
export default Attribute;