From c06d020cdcebbaeeb6130e163d37864e3d73a00e Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Fri, 12 Jan 2024 13:59:58 +0200 Subject: [PATCH] [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. --- .../ISVocabularies.service.ts | 51 +++++++++++++------ 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/utils/staticAutoComplete/ISVocabularies.service.ts b/utils/staticAutoComplete/ISVocabularies.service.ts index 074afa4e..7a880f44 100644 --- a/utils/staticAutoComplete/ISVocabularies.service.ts +++ b/utils/staticAutoComplete/ISVocabularies.service.ts @@ -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; }