Add table with automatic neighbor relation data
[portal/ric-dashboard.git] / webapp-frontend / src / app / control / control.component.ts
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property and Nokia
6  * %%
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20 import { Component, OnInit } from '@angular/core';
21 import { XappMgrService } from '../services/xapp-mgr/xapp-mgr.service';
22 import { Router } from '@angular/router';
23 import { ErrorDialogService } from './../services/ui/error-dialog.service';
24 import { ConfirmDialogService } from './../services/ui/confirm-dialog.service';
25 import { NotificationService } from './../services/ui/notification.service';
26 import { XappControlRow } from '../interfaces/xapp-mgr.types';
27 import { ControlAnimations } from './control.animations';
28 import { ControlDataSource } from './control.datasource';
29 import { routerNgProbeToken } from '@angular/router/src/router_module';
30
31 @Component({
32   selector: 'app-control',
33   templateUrl: './control.component.html',
34   styleUrls: ['./control.component.css'],
35   animations: [ControlAnimations.messageTrigger],
36 })
37 export class ControlComponent implements OnInit {
38
39   displayedColumns: string[] = ['xapp', 'name', 'status', 'ip', 'port', 'action'];
40   dataSource: ControlDataSource;
41
42   constructor(
43     private xappMgrSvc: XappMgrService,
44     private router: Router,
45     private confirmDialogService: ConfirmDialogService,
46     private errorDialogService: ErrorDialogService,
47     private notification: NotificationService) { }
48
49   ngOnInit() {
50     this.dataSource = new ControlDataSource(this.xappMgrSvc);
51     this.dataSource.loadTable();
52   }
53
54   controlApp(app: XappControlRow): void {
55     const anrXappPattern = /[Aa][Nn][Rr]/;
56     if (anrXappPattern.test(app.xapp)) {
57       this.router.navigate(['/anr']);
58     } else {
59       this.errorDialogService.displayError('No control available for ' + app.xapp + ' (yet)');
60     }
61   }
62
63   undeployApp(app: XappControlRow): void {
64     this.confirmDialogService.openConfirmDialog('Are you sure you want to undeploy xApp ' + app.xapp + '?')
65       .afterClosed().subscribe(res => {
66         if (res) {
67           this.xappMgrSvc.undeployXapp(app.xapp).subscribe(
68             response => {
69               this.dataSource.loadTable();
70               switch (response.status) {
71                 case 200:
72                   this.notification.success('xApp undeployed successfully!');
73                   break;
74                 default:
75                   this.notification.warn('xApp undeploy failed.');
76               }
77             }
78           );
79         }
80       });
81   }
82
83 }