X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Fapp-control%2Fapp-control.component.ts;fp=webapp-frontend%2Fsrc%2Fapp%2Fapp-control%2Fapp-control.component.ts;h=35770dc8bdc819a70fa619afa47b3586bfa6f2d0;hb=b7d7982bbfbf3a1333feb8b811f99497752d3722;hp=c97a1950d7a761c09a07d2dfe178fd13edfef0b6;hpb=53f1fcf033e3a166d7203e0a1c5e0971f9c6bc16;p=portal%2Fric-dashboard.git diff --git a/webapp-frontend/src/app/app-control/app-control.component.ts b/webapp-frontend/src/app/app-control/app-control.component.ts index c97a1950..35770dc8 100644 --- a/webapp-frontend/src/app/app-control/app-control.component.ts +++ b/webapp-frontend/src/app/app-control/app-control.component.ts @@ -21,15 +21,17 @@ import { HttpErrorResponse, HttpResponse } from '@angular/common/http'; import { Component, OnInit, ViewChild } from '@angular/core'; import { MatSort } from '@angular/material/sort'; import { Router } from '@angular/router'; +import { Subscription } from 'rxjs'; +import { finalize } from 'rxjs/operators'; import { XappControlRow } from '../interfaces/app-mgr.types'; import { AppMgrService } from '../services/app-mgr/app-mgr.service'; +import { InstanceSelectorService } from '../services/instance-selector/instance-selector.service'; import { ConfirmDialogService } from '../services/ui/confirm-dialog.service'; import { ErrorDialogService } from '../services/ui/error-dialog.service'; import { LoadingDialogService } from '../services/ui/loading-dialog.service'; import { NotificationService } from '../services/ui/notification.service'; import { AppControlAnimations } from './app-control.animations'; import { AppControlDataSource } from './app-control.datasource'; -import { finalize } from 'rxjs/operators'; @Component({ selector: 'rd-app-control', @@ -41,7 +43,9 @@ export class AppControlComponent implements OnInit { displayedColumns: string[] = ['xapp', 'name', 'status', 'ip', 'port', 'action']; dataSource: AppControlDataSource; - @ViewChild(MatSort, {static: true}) sort: MatSort; + @ViewChild(MatSort, { static: true }) sort: MatSort; + private instanceChange: Subscription; + private instanceKey: string; constructor( private appMgrSvc: AppMgrService, @@ -49,48 +53,59 @@ export class AppControlComponent implements OnInit { private confirmDialogService: ConfirmDialogService, private errorDialogService: ErrorDialogService, private loadingDialogService: LoadingDialogService, + public instanceSelectorService: InstanceSelectorService, private notificationService: NotificationService) { } + ngOnInit() { this.dataSource = new AppControlDataSource(this.appMgrSvc, this.sort, this.notificationService); - this.dataSource.loadTable(); + this.instanceChange = this.instanceSelectorService.getSelectedInstancekey().subscribe((instanceKey: string) => { + if (instanceKey) { + this.instanceKey = instanceKey; + this.dataSource.loadTable(instanceKey); + } + }) + } + + ngOnDestroy() { + this.instanceChange.unsubscribe(); } controlApp(app: XappControlRow): void { // TODO: identify apps without hardcoding to names - const acAppPattern0 = /[Aa][Dd][Mm][Ii][Nn]/; - const acAppPattern1 = /[Aa][Dd][Mm][Ii][Ss]{2}[Ii][Oo][Nn]/; + const acAppPattern0 = /[Aa][Dd][Mm][Ii][Nn]/; + const acAppPattern1 = /[Aa][Dd][Mm][Ii][Ss]{2}[Ii][Oo][Nn]/; if (acAppPattern0.test(app.xapp) || acAppPattern1.test(app.xapp)) { this.router.navigate(['/ac']); - } else { + } else { this.errorDialogService.displayError('No control available for ' + app.xapp + ' (yet)'); } } onUndeployApp(app: XappControlRow): void { this.confirmDialogService.openConfirmDialog('Are you sure you want to undeploy App ' + app.xapp + '?') - .afterClosed().subscribe( (res: boolean) => { + .afterClosed().subscribe((res: boolean) => { if (res) { this.loadingDialogService.startLoading("Undeploying " + app.xapp); - this.appMgrSvc.undeployXapp(app.xapp) + this.appMgrSvc.undeployXapp(this.instanceKey, app.xapp) .pipe( finalize(() => this.loadingDialogService.stopLoading()) ) .subscribe( - ( httpResponse: HttpResponse) => { - // Answers 204/No content on success - this.notificationService.success('App undeployed successfully!'); - this.dataSource.loadTable(); - }, - ( (her: HttpErrorResponse) => { - // the error field should have an ErrorTransport object - let msg = her.message; - if (her.error && her.error.message) { - msg = her.error.message; - } - this.notificationService.warn('App undeploy failed: ' + msg); - }) - ); + (httpResponse: HttpResponse) => { + // Answers 204/No content on success + this.notificationService.success('App undeployed successfully!'); + this.dataSource.loadTable(this.instanceKey); + }, + ((her: HttpErrorResponse) => { + // the error field should have an ErrorTransport object + let msg = her.message; + if (her.error && her.error.message) { + msg = her.error.message; + } + this.notificationService.warn('App undeploy failed: ' + msg); + }) + ); } }); }