[develop | DONE | CHANGED]: ISVocabularies.service.ts: Updated method "parseFOS()" to parse all Fields of Science by visiting hierarchy from fos.json using an iterative DFS (Depth First Search), instead of looping each level - this does not depend on the number of levels specified in the vocabulary file.

This commit is contained in:
Konstantina Galouni 2024-01-12 13:59:58 +02:00
parent c2312e297e
commit c06d020cdc
1 changed files with 36 additions and 15 deletions

View File

@ -143,28 +143,49 @@ export class ISVocabulariesService {
parseFOS(data: any): AutoCompleteValue[] {
let array: AutoCompleteValue[] = []
for (let fos of data) {
let children = data.reverse();
while(children && children.length > 0) {
let fos = children.pop();
let value: AutoCompleteValue = new AutoCompleteValue();
value.id = fos.id;//data[i].code;
value.label = fos.label;
array.push(value);
if(fos.children) {
for (let fos2 of fos.children) {
let value: AutoCompleteValue = new AutoCompleteValue();
value.id = fos2.id;//data[i].code;
value.label = fos2.label;
array.push(value);
if(fos2.children) {
for (let fos3 of fos2.children) {
let value: AutoCompleteValue = new AutoCompleteValue();
value.id = fos3.id;//data[i].code;
value.label = fos3.label;
array.push(value);
}
}
if(fos.children && fos.children.length > 0) {
for (let i=fos.children.length-1; i>=0; i--) {
children.push(fos.children[i]);
}
}
}
// for (let fos of data) {
// let value: AutoCompleteValue = new AutoCompleteValue();
// value.id = fos.id;//data[i].code;
// value.label = fos.label;
// array.push(value);
// if(fos.children) {
// for (let fos2 of fos.children) {
// let value: AutoCompleteValue = new AutoCompleteValue();
// value.id = fos2.id;//data[i].code;
// value.label = fos2.label;
// array.push(value);
// if(fos2.children) {
// for (let fos3 of fos2.children) {
// let value: AutoCompleteValue = new AutoCompleteValue();
// value.id = fos3.id;//data[i].code;
// value.label = fos3.label;
// array.push(value);
// // if(fos3.children) {
// // for (let fos4 of fos3.children) {
// // let value: AutoCompleteValue = new AutoCompleteValue();
// // value.id = fos4.id;//data[i].code;
// // value.label = fos4.label;
// // array.push(value);
// // }
// // }
// }
// }
// }
// }
// }
return array;
}