X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Fapp%2Fpackages%2Finstantiate-net-slice-template%2FInstantiateNetSliceTemplateComponent.ts;h=330edf85eb39e1df4aa9f864b5e4303fb3d597ca;hb=40cc37ef2bbc4aac5debc9dea0baeb6dbd87a2d7;hp=ed5e4147f7c4083aa3b2627e100a7292174748ee;hpb=3b4814aa2d3dec621dadb52f058ba95a3dc3a86a;p=osm%2FNG-UI.git diff --git a/src/app/packages/instantiate-net-slice-template/InstantiateNetSliceTemplateComponent.ts b/src/app/packages/instantiate-net-slice-template/InstantiateNetSliceTemplateComponent.ts index ed5e414..330edf8 100644 --- a/src/app/packages/instantiate-net-slice-template/InstantiateNetSliceTemplateComponent.ts +++ b/src/app/packages/instantiate-net-slice-template/InstantiateNetSliceTemplateComponent.ts @@ -207,8 +207,11 @@ export class InstantiateNetSliceTemplateComponent implements OnInit { }); delete this.netSliceInstantiateForm.value.config; } else { - this.notifierService.notify('error', this.translateService.instant('INVALIDCONFIG')); - return; + const getConfigJson: string = jsyaml.load(this.netSliceInstantiateForm.value.config, { json: true }); + Object.keys(getConfigJson).forEach((item: string) => { + this.netSliceInstantiateForm.value[item] = getConfigJson[item]; + }); + delete this.netSliceInstantiateForm.value.config; } } this.isLoadingResults = true; @@ -259,24 +262,40 @@ export class InstantiateNetSliceTemplateComponent implements OnInit { /** Config file process @private */ public configFile(files: FileList): void { if (files && files.length === 1) { - this.sharedService.getFileString(files, 'yaml').then((fileContent: string): void => { - const getConfigJson: string = jsyaml.load(fileContent, { json: true }); - // tslint:disable-next-line: no-backbone-get-set-outside-model - this.netSliceInstantiateForm.get('config').setValue(JSON.stringify(getConfigJson)); - }).catch((err: string): void => { - if (err === 'typeError') { - this.notifierService.notify('error', this.translateService.instant('YAMLFILETYPEERRROR')); - } else { - this.notifierService.notify('error', this.translateService.instant('ERROR')); - } - this.fileInputConfigLabel.nativeElement.innerText = this.translateService.instant('CHOOSEFILE'); - this.fileInputConfig.nativeElement.value = null; - }); + const fileFormat: string = this.sharedService.fetchFileExtension(files).toLocaleLowerCase(); + if (fileFormat === 'yaml' || fileFormat === 'yml') { + this.sharedService.getFileString(files, 'yaml').then((fileContent: string): void => { + const getConfigJson: string = jsyaml.load(fileContent, { json: true }); + // tslint:disable-next-line: no-backbone-get-set-outside-model + this.netSliceInstantiateForm.get('config').setValue(JSON.stringify(getConfigJson)); + }).catch((err: string): void => { + if (err === 'typeError') { + this.notifierService.notify('error', this.translateService.instant('YAMLFILETYPEERRROR')); + } else { + this.notifierService.notify('error', this.translateService.instant('ERROR')); + } + this.fileInputConfigLabel.nativeElement.innerText = this.translateService.instant('CHOOSEFILE'); + this.fileInputConfig.nativeElement.value = null; + }); + } else if (fileFormat === 'json') { + this.sharedService.getFileString(files, 'json').then((fileContent: string): void => { + const getConfigJson: string = jsyaml.load(fileContent, { json: true }); + // tslint:disable-next-line: no-backbone-get-set-outside-model + this.netSliceInstantiateForm.get('config').setValue(JSON.stringify(getConfigJson)); + }).catch((err: string): void => { + if (err === 'typeError') { + this.notifierService.notify('error', this.translateService.instant('JSONFILETYPEERRROR')); + } else { + this.notifierService.notify('error', this.translateService.instant('ERROR')); + } + this.fileInputConfigLabel.nativeElement.innerText = this.translateService.instant('CHOOSEFILE'); + this.fileInputConfig.nativeElement.value = null; + }); + } } else if (files && files.length > 1) { this.notifierService.notify('error', this.translateService.instant('DROPFILESVALIDATION')); } this.fileInputConfigLabel.nativeElement.innerText = files[0].name; this.fileInputConfig.nativeElement.value = null; } - }