X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Fapp%2Futilities%2Fvertical-scaling%2FVerticalScalingComponent.ts;h=7b4c0871ee5126823ac98d38617a4806e9002021;hb=c7e646225214c583463c859f267d314fb04e829e;hp=69eb9eb9237e8e6be74096bfac76c02b104c4cab;hpb=017df364be742ba4d89013ae32572c2b300e2a29;p=osm%2FNG-UI.git diff --git a/src/app/utilities/vertical-scaling/VerticalScalingComponent.ts b/src/app/utilities/vertical-scaling/VerticalScalingComponent.ts index 69eb9eb..7b4c087 100644 --- a/src/app/utilities/vertical-scaling/VerticalScalingComponent.ts +++ b/src/app/utilities/vertical-scaling/VerticalScalingComponent.ts @@ -18,6 +18,7 @@ /** * @file VerticalScaling 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'; @@ -30,8 +31,7 @@ import { environment } from 'environment'; import { VerticalScaling } from 'NSInstanceModel'; import { RestService } from 'RestService'; import { SharedService } from 'SharedService'; -import { isNullOrUndefined } from 'util'; -import { VDUR, VNFInstanceDetails } from 'VNFInstanceModel'; +import { InstanceData, VDUR, VNFInstanceDetails } from 'VNFInstanceModel'; /** * Creating component @@ -67,6 +67,10 @@ export class VerticalScalingComponent implements OnInit { public nsIdFilteredData: {}[] = []; /** Form valid on submit trigger @public */ public submitted: boolean = false; + /** Contains vduId @public */ + public vduId: {}; + /** Items for countIndex @public */ + public countIndex: {}[]; /** Input contains component objects @private */ @Input() private params: URLPARAMS; /** FormBuilder instance added to the formBuilder @private */ @@ -121,27 +125,35 @@ export class VerticalScalingComponent implements OnInit { /** Getting MemberVnfIndex using VNFInstances API @public */ public getMemberVnfIndex(): void { + 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: {} = { - VNFD: vnfData['vnfd-ref'], + // eslint-disable-next-line security/detect-object-injection + VNFD: vnfData[vnfdRef], VNFInstanceId: vnfData._id, - MemberIndex: vnfData['member-vnf-index-ref'], - NS: vnfData['nsr-id-ref'], - VNFID: vnfData['vnfd-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); }); 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: {}[]): void => { - const memberIndex: string = 'MemberIndex'; - const vnfinstanceID: string = 'VNFInstanceId'; + this.nsIdFilteredData.forEach((resVNF: InstanceData): void => { const assignMemberIndex: {} = { - id: resVNF[memberIndex], - vnfinstanceId: resVNF[vnfinstanceID] + id: resVNF.MemberIndex, + vnfinstanceId: resVNF.VNFInstanceId }; this.memberVnfIndex.push(assignMemberIndex); }); @@ -164,17 +176,25 @@ export class VerticalScalingComponent implements OnInit { this.instanceId = id; this.selectedvnfId = vnfInstanceDetail['vnfd-ref']; const VDU: string = 'vdur'; + // eslint-disable-next-line security/detect-object-injection if (vnfInstanceDetail[VDU] !== undefined) { + // eslint-disable-next-line security/detect-object-injection vnfInstanceDetail[VDU].forEach((vdu: VDUR): void => { const vnfInstanceDataObj: {} = { 'count-index': vdu['count-index'], VDU: vdu['vdu-id-ref'] - }; vnfInstanceData.push(vnfInstanceDataObj); }); this.vdu = vnfInstanceData; + const vduName: string = 'VDU'; + this.vduId = this.vdu.filter((vdu: {}, index: number, self: {}[]): {} => + index === self.findIndex((t: {}): {} => ( + // eslint-disable-next-line security/detect-object-injection + t[vduName] === vdu[vduName] + )) + ); } }, (error: ERRORDATA): void => { this.restService.handleError(error, 'get'); @@ -183,6 +203,13 @@ export class VerticalScalingComponent implements OnInit { } } + /** Getting count-index by filtering id */ + public getCountIndex(id: string): void { + const VDU: string = 'VDU'; + // eslint-disable-next-line security/detect-object-injection + this.countIndex = this.vdu.filter((vnfdData: {}[]): boolean => vnfdData[VDU] === id); + } + /** Vertical Scaling on submit */ public triggerVerticalScaling(): void { this.submitted = true; @@ -219,7 +246,9 @@ export class VerticalScalingComponent 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; @@ -228,6 +257,7 @@ export class VerticalScalingComponent 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]; } }