Apply mat-table to control and catalog
[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 { ConfirmDialogService } from './../services/ui/confirm-dialog.service'
24 import { NotificationService } from './../services/ui/notification.service'
25 import { XMXapp } from '../interfaces/xapp-mgr.types';
26 import { ControlAnimations } from './control.animations';
27 import { ControlDataSource } from './control.datasource';
28
29
30 @Component({
31   selector: 'app-control',
32   templateUrl: './control.component.html',
33   styleUrls: ['./control.component.css'],
34   animations: [ControlAnimations.messageTrigger],
35 })
36 export class ControlComponent implements OnInit {
37
38   displayedColumns: string[] = ['xapp', 'name', 'status', 'ip', 'port', 'action'];
39   dataSource: ControlDataSource;
40
41   constructor(
42     private xappMgrSvc: XappMgrService,
43     private router: Router,
44     private confirmDialogService: ConfirmDialogService,
45     private notification: NotificationService) { }
46
47   ngOnInit() {
48     this.dataSource = new ControlDataSource(this.xappMgrSvc);
49     this.dataSource.loadTable();
50   }
51
52   view(): void {
53     const url = '/xapp';
54     this.router.navigate([url]);
55   }
56
57   undeploy(name: string): void {
58     this.confirmDialogService.openConfirmDialog('Are you sure you want to undeploy this xApp ?')
59       .afterClosed().subscribe(res => {
60         if (res) {
61           this.xappMgrSvc.undeployXapp(name).subscribe(
62             response => {
63               this.dataSource.loadTable();
64               switch (response.status) {
65                 case 200:
66                   this.notification.success('xApp undeployed successfully!');
67                   break;
68                 default:
69                   this.notification.warn('xApp undeploy failed.');
70               }
71             }
72           );
73         }
74       });
75   }
76
77
78
79 }