X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Fapp%2Futilities%2Fscaling%2FScalingComponent.ts;h=be15660f67724ef5d821ad59e18f4267d1eefc2f;hb=c7e646225214c583463c859f267d314fb04e829e;hp=111c3b85b9b47cdae857a9c325ede497b3938575;hpb=2e02e7d676dc5a87e2d68437f30b6e41037ea7a4;p=osm%2FNG-UI.git diff --git a/src/app/utilities/scaling/ScalingComponent.ts b/src/app/utilities/scaling/ScalingComponent.ts index 111c3b8..be15660 100644 --- a/src/app/utilities/scaling/ScalingComponent.ts +++ b/src/app/utilities/scaling/ScalingComponent.ts @@ -18,6 +18,7 @@ /** * @file Scaling Component */ +import { isNullOrUndefined } from 'util'; import { HttpHeaders } from '@angular/common/http'; import { Component, Injector, Input, OnInit } from '@angular/core'; import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms'; @@ -26,12 +27,10 @@ import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import { TranslateService } from '@ngx-translate/core'; import { APIURLHEADER, ERRORDATA, MODALCLOSERESPONSEDATA, URLPARAMS } from 'CommonModel'; import { environment } from 'environment'; -import { DF as NSDF, VNFPROFILE } from 'NSDModel'; import { RestService } from 'RestService'; import { SharedService } from 'SharedService'; -import { isNullOrUndefined } from 'util'; import { DF, SCALING, VNFD } from 'VNFDModel'; - +import { InstanceData, VNFInstanceDetails } from 'VNFInstanceModel'; /** * Creating component * @Component takes ScalingComponent.html as template url @@ -53,7 +52,9 @@ export class ScalingComponent implements OnInit { /** Contains the scaling group descriptor names @public */ public scalingGroup: {}[]; /** Member index of the NS @public */ - public memberVNFIndex: {}[]; + public memberVNFIndex: {}[] = []; + /** Items for the memberVNFIndex @public */ + public memberTypes: {}[]; /** handles the selected VNFID @public */ public selectedVNFID: string = ''; /** Items for the Scale Types @public */ @@ -62,6 +63,8 @@ export class ScalingComponent implements OnInit { public scalingForm: FormGroup; /** Form valid on submit trigger @public */ public submitted: boolean = false; + /** Array holds VNFR Data filtered with nsr ID @private */ + private nsIdFilteredData: {}[] = []; /** FormBuilder instance added to the formBuilder @private */ private formBuilder: FormBuilder; /** Instance of the rest service @private */ @@ -118,19 +121,45 @@ export class ScalingComponent implements OnInit { /** Get the member-vnf-index from NS Package -> vnf-profile @public */ public getmemberIndex(): void { - if (this.params.nsd.df.length > 0) { - const getconstituentVNFD: {}[] = []; - this.params.nsd.df.forEach((data: NSDF): void => { - data['vnf-profile'].forEach((vnfProfile: VNFPROFILE): void => { - const assignMemberIndex: {} = { - id: vnfProfile.id, - name: vnfProfile['vnfd-id'] - }; - getconstituentVNFD.push(assignMemberIndex); - }); + this.isLoadingResults = true; + const vnfInstanceData: {}[] = []; + this.restService.getResource(environment.VNFINSTANCES_URL).subscribe((vnfInstancesData: VNFInstanceDetails[]): void => { + vnfInstancesData.forEach((vnfData: VNFInstanceDetails): void => { + const vnfdRef: string = 'vnfd-ref'; + const memberIndex: string = 'member-vnf-index-ref'; + const nsrId: string = 'nsr-id-ref'; + const vnfId: string = 'vnfd-id'; + const vnfDataObj: {} = + { + // eslint-disable-next-line security/detect-object-injection + VNFD: vnfData[vnfdRef], + VNFInstanceId: vnfData._id, + // eslint-disable-next-line security/detect-object-injection + MemberIndex: vnfData[memberIndex], + // eslint-disable-next-line security/detect-object-injection + NS: vnfData[nsrId], + // eslint-disable-next-line security/detect-object-injection + VNFID: vnfData[vnfId] + }; + vnfInstanceData.push(vnfDataObj); }); - this.memberVNFIndex = getconstituentVNFD; - } + const nsId: string = 'NS'; + // eslint-disable-next-line security/detect-object-injection + this.nsIdFilteredData = vnfInstanceData.filter((vnfdData: {}[]): boolean => vnfdData[nsId] === this.params.id); + this.nsIdFilteredData.forEach((resVNF: InstanceData): void => { + const assignMemberIndex: {} = { + id: resVNF.MemberIndex, + vnfinstanceId: resVNF.VNFInstanceId, + vnfdRef: resVNF.VNFD + }; + this.memberVNFIndex.push(assignMemberIndex); + }); + this.memberTypes = this.memberVNFIndex; + this.isLoadingResults = false; + }, (error: ERRORDATA): void => { + this.restService.handleError(error, 'get'); + this.isLoadingResults = false; + }); } /** Get the scaling-group-descriptor name @public */ @@ -185,7 +214,9 @@ export class ScalingComponent implements OnInit { }; this.restService.postResource(apiURLHeader, scalingPayload).subscribe((result: {}): void => { this.activeModal.close(modalData); - this.router.navigate(['/instances/ns/history-operations/' + this.params.id]).catch(); + this.router.navigate(['/instances/ns/history-operations/' + this.params.id]).catch((): void => { + // Catch Navigation Error + }); }, (error: ERRORDATA): void => { this.restService.handleError(error, 'post'); this.isLoadingResults = false; @@ -194,6 +225,7 @@ export class ScalingComponent implements OnInit { /** Used to get the AbstractControl of controlName passed @private */ private getFormControl(controlName: string): AbstractControl { + // eslint-disable-next-line security/detect-object-injection return this.scalingForm.controls[controlName]; } }