Skip to content
Snippets Groups Projects
Verified Commit 81a98516 authored by Jan Loewe's avatar Jan Loewe :speech_balloon:
Browse files

fix(richContentType): add getContent method

parent d63f9a00
No related branches found
No related tags found
No related merge requests found
......@@ -296,6 +296,34 @@ export class RichContentType extends DCCXMLElement {
if (el.file) this.file = ensureArray(el.file).map((x) => new ByteDataType(x));
if (el.formula) this.formula = ensureArray(el.formula).map((x) => new FormulaType(x));
}
getContent(lang?: string): StringWithLangType | undefined {
if(!this.content) return null;
// item with undefined as lang is default
const def = this.content.find((x) => x._attr == null || x._attr.lang == null);
const items = this.content.filter((x) => x._attr != null && x._attr.lang === lang);
// if there is more than one content element
// concat the text of all content elements with same lang
if (items.length > 1) {
items.forEach((item) => {
this.content.splice(this.content.indexOf(item), 1);
});
const grouped = items.reduce((prev, curr) => {
prev._text += `\n${curr._text}`;
return prev;
});
this.content.push(grouped);
return grouped;
} else {
return items.length ? items[0] : def;
}
}
}
/** List of measuring equipment and instruments */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment