X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Fapp%2Fpackages%2Finstantiate-ns%2FInstantiateNsComponent.ts;h=1043f9a3fe50c85342e3833b4a4116d99cb9fd97;hb=refs%2Fchanges%2F80%2F12480%2F3;hp=515a24bb865e17bb77d4f0f421cbb17e8047031f;hpb=3b4814aa2d3dec621dadb52f058ba95a3dc3a86a;p=osm%2FNG-UI.git diff --git a/src/app/packages/instantiate-ns/InstantiateNsComponent.ts b/src/app/packages/instantiate-ns/InstantiateNsComponent.ts index 515a24b..1043f9a 100644 --- a/src/app/packages/instantiate-ns/InstantiateNsComponent.ts +++ b/src/app/packages/instantiate-ns/InstantiateNsComponent.ts @@ -75,6 +75,9 @@ export class InstantiateNsComponent implements OnInit { /** Give the message for the loading @public */ public message: string = 'PLEASEWAIT'; + /** Contains Selected VIM Details @public */ + public selectedVIMDetails: VimAccountDetails = null; + /** Element ref for fileInputConfig @public */ @ViewChild('fileInputConfig', { static: true }) public fileInputConfig: ElementRef; @@ -197,8 +200,11 @@ export class InstantiateNsComponent implements OnInit { }); delete this.instantiateForm.value.config; } else { - this.notifierService.notify('error', this.translateService.instant('INVALIDCONFIG')); - return; + const getConfigJson: string = jsyaml.load(this.instantiateForm.value.config, { json: true }); + Object.keys(getConfigJson).forEach((item: string) => { + this.instantiateForm.value[item] = getConfigJson[item]; + }); + delete this.instantiateForm.value.config; } } const apiURLHeader: APIURLHEADER = { @@ -246,23 +252,46 @@ export class InstantiateNsComponent 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.instantiateForm.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 => { + // tslint:disable-next-line: no-backbone-get-set-outside-model + this.instantiateForm.get('config').setValue(fileContent); + }).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.instantiateForm.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; } + + /** Get Selected VIM details @public */ + public getSelectedVIMDetails(vimDetails: VimAccountDetails): void { + if (!isNullOrUndefined(vimDetails.resources)) { + this.selectedVIMDetails = vimDetails; + } + } }