X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Fran-control%2Fran-connection-dialog.component.ts;fp=webapp-frontend%2Fsrc%2Fapp%2Fran-control%2Fran-connection-dialog.component.ts;h=25442f7761cbd5f4d7b6104400dc1416b574e4d2;hb=fa50e55b6e8977ad0a6a28096fe58fb54924ca2b;hp=7f0c368ea14f80cb5d0b32b8a6afaa4c81717513;hpb=4d3a7c62ddcab6abc5ca45e6cabc90258025a768;p=portal%2Fric-dashboard.git diff --git a/webapp-frontend/src/app/ran-control/ran-connection-dialog.component.ts b/webapp-frontend/src/app/ran-control/ran-connection-dialog.component.ts index 7f0c368e..25442f77 100644 --- a/webapp-frontend/src/app/ran-control/ran-connection-dialog.component.ts +++ b/webapp-frontend/src/app/ran-control/ran-connection-dialog.component.ts @@ -18,13 +18,14 @@ * ========================LICENSE_END=================================== */ import { Component, OnInit, Inject } from '@angular/core'; +import { HttpResponse, HttpErrorResponse } from '@angular/common/http'; import { FormGroup, FormControl, Validators } from '@angular/forms'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { Observable } from 'rxjs'; import { E2ManagerService } from '../services/e2-mgr/e2-mgr.service'; import { NotificationService } from '../services/ui/notification.service'; import { ErrorDialogService } from '../services/ui/error-dialog.service'; -import { E2SetupRequest } from '../interfaces/e2-mgr.types'; -import { HttpErrorResponse } from '@angular/common/http'; +import { E2SetupRequest, RanDialogFormData } from '../interfaces/e2-mgr.types'; @Component({ selector: 'rd-ran-control-connect-dialog', @@ -35,13 +36,14 @@ import { HttpErrorResponse } from '@angular/common/http'; export class RanControlConnectDialogComponent implements OnInit { public ranDialogForm: FormGroup; + public processing = false; constructor( private dialogRef: MatDialogRef, private service: E2ManagerService, private errorService: ErrorDialogService, - private notifService: NotificationService, - @Inject(MAT_DIALOG_DATA) public data: E2SetupRequest) { + private notifService: NotificationService) { + // opens with empty fields; accepts no data to display } ngOnInit() { @@ -55,64 +57,55 @@ export class RanControlConnectDialogComponent implements OnInit { ranIp: new FormControl('', [Validators.required, Validators.pattern(ipPattern)]), ranPort: new FormControl('', [Validators.required, Validators.pattern(portPattern)]) }); - } onCancel() { - this.dialogRef.close(); + this.dialogRef.close(false); } - public setupConnection = (ranFormValue) => { - if (this.ranDialogForm.valid) { - this.executeSetupConnection(ranFormValue); + setupConnection = (ranFormValue: RanDialogFormData) => { + if (!this.ranDialogForm.valid) { + // should never happen + return; } - } - - private executeSetupConnection = (ranFormValue) => { - let httpErrRes: HttpErrorResponse; - const aboutError = 'RAN Connection Failed: '; + this.processing = true; const setupRequest: E2SetupRequest = { ranName: ranFormValue.ranName, ranIp: ranFormValue.ranIp, ranPort: ranFormValue.ranPort }; + let observable: Observable>; if (ranFormValue.ranType === 'endc') { - this.service.endcSetup(setupRequest).subscribe( - (response: any) => { - this.notifService.success('Endc connect succeeded!'); - this.dialogRef.close(); - }, - (error => { - httpErrRes = error; - this.errorService.displayError(aboutError + httpErrRes.message); - }) - ); + observable = this.service.endcSetup(setupRequest); } else { - this.service.x2Setup(setupRequest).subscribe( - (response: any) => { - this.notifService.success('X2 connect succeeded!'); - this.dialogRef.close(); - }, - (error => { - httpErrRes = error; - this.errorService.displayError(aboutError + httpErrRes.message); - }) - ); + observable = this.service.x2Setup(setupRequest); } + observable.subscribe( + (response: any) => { + this.processing = false; + this.notifService.success('Connect succeeded!'); + this.dialogRef.close(true); + }, + ( (error: HttpErrorResponse) => { + this.processing = false; + this.errorService.displayError('RAN Connection Failed: ' + error.message); + // keep the dialog open + }) + ); } - public hasError(controlName: string, errorName: string) { + hasError(controlName: string, errorName: string) { if (this.ranDialogForm.controls[controlName].hasError(errorName)) { return true; } return false; } - public validateControl(controlName: string) { + validateControl(controlName: string) { if (this.ranDialogForm.controls[controlName].invalid && this.ranDialogForm.controls[controlName].touched) { return true; } return false; } -} // class AppRANConnectDialog +}