X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=webapp-frontend%2Fsrc%2Fapp%2Fac-xapp%2Fac-xapp.component.ts;h=f85f18e7526e5603080ccea8eabfb4a436d0901f;hb=b7d7982bbfbf3a1333feb8b811f99497752d3722;hp=1e0df3b5955340cce56a0b1b85d46991a9601a47;hpb=53f1fcf033e3a166d7203e0a1c5e0971f9c6bc16;p=portal%2Fric-dashboard.git diff --git a/webapp-frontend/src/app/ac-xapp/ac-xapp.component.ts b/webapp-frontend/src/app/ac-xapp/ac-xapp.component.ts index 1e0df3b5..f85f18e7 100644 --- a/webapp-frontend/src/app/ac-xapp/ac-xapp.component.ts +++ b/webapp-frontend/src/app/ac-xapp/ac-xapp.component.ts @@ -18,13 +18,15 @@ * ========================LICENSE_END=================================== */ -import { Component, OnInit } from '@angular/core'; -import { FormGroup, FormControl, Validators } from '@angular/forms'; -import { ACAdmissionIntervalControl, ACAdmissionIntervalControlAck } from '../interfaces/ac-xapp.types'; +import { HttpErrorResponse } from '@angular/common/http'; +import { Component, OnInit, OnDestroy } from '@angular/core'; +import { FormControl, FormGroup, Validators } from '@angular/forms'; +import { ACAdmissionIntervalControl } from '../interfaces/ac-xapp.types'; import { ACXappService } from '../services/ac-xapp/ac-xapp.service'; import { ErrorDialogService } from '../services/ui/error-dialog.service'; import { NotificationService } from './../services/ui/notification.service'; -import { HttpErrorResponse } from '@angular/common/http'; +import { Subscription } from 'rxjs'; +import { InstanceSelectorService } from '../services/instance-selector/instance-selector.service'; @Component({ selector: 'rd-ac-xapp', @@ -34,16 +36,20 @@ import { HttpErrorResponse } from '@angular/common/http'; export class AcXappComponent implements OnInit { private acForm: FormGroup; + private instanceChange: Subscription; + private instanceKey: string; constructor( private acXappService: ACXappService, private errorDialogService: ErrorDialogService, - private notificationService: NotificationService) { } + private notificationService: NotificationService, + public instanceSelectorService: InstanceSelectorService, ) { } ngOnInit() { const windowLengthPattern = /^([0-9]{1}|[1-5][0-9]{1}|60)$/; const blockingRatePattern = /^([0-9]{1,2}|100)$/; const triggerPattern = /^([0-9]+)$/; + this.acForm = new FormGroup({ // Names must match the ACAdmissionIntervalControl interface enforce: new FormControl(true, [Validators.required]), @@ -51,18 +57,28 @@ export class AcXappComponent implements OnInit { blocking_rate: new FormControl('', [Validators.required, Validators.pattern(blockingRatePattern)]), trigger_threshold: new FormControl('', [Validators.required, Validators.pattern(triggerPattern)]) }); - // TODO: show pending action indicator - this.acXappService.getPolicy().subscribe((res: ACAdmissionIntervalControl) => { - this.acForm.controls['enforce'].setValue(res.enforce); - this.acForm.controls['window_length'].setValue(res.window_length); - this.acForm.controls['blocking_rate'].setValue(res.blocking_rate); - this.acForm.controls['trigger_threshold'].setValue(res.trigger_threshold); - // TODO: clear pending action indicator - }, - (error: HttpErrorResponse) => { - // TODO: clear pending action indicator - this.errorDialogService.displayError(error.message); - }); + + this.instanceChange = this.instanceSelectorService.getSelectedInstancekey().subscribe((instanceKey: string) => { + if (instanceKey) { + // TODO: show pending action indicator + this.instanceKey = instanceKey; + this.acXappService.getPolicy(instanceKey).subscribe((res: ACAdmissionIntervalControl) => { + this.acForm.controls['enforce'].setValue(res.enforce); + this.acForm.controls['window_length'].setValue(res.window_length); + this.acForm.controls['blocking_rate'].setValue(res.blocking_rate); + this.acForm.controls['trigger_threshold'].setValue(res.trigger_threshold); + // TODO: clear pending action indicator + }, + (error: HttpErrorResponse) => { + // TODO: clear pending action indicator + this.errorDialogService.displayError(error.message); + }); + } + }) + } + + ngOnDestroy() { + this.instanceChange.unsubscribe(); } updateAc = (acFormValue: ACAdmissionIntervalControl) => { @@ -74,7 +90,7 @@ export class AcXappComponent implements OnInit { blocking_rate: +acFormValue.blocking_rate, trigger_threshold: +acFormValue.trigger_threshold }; - this.acXappService.putPolicy(acFormValueConverted).subscribe( + this.acXappService.putPolicy(this.instanceKey, acFormValueConverted).subscribe( response => { if (response.status === 200) { this.notificationService.success('AC update policy succeeded!');