support-multiple-ric-instances
[portal/ric-dashboard.git] / webapp-frontend / src / app / caas-ingress / caas-ingress.component.ts
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property
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
21 import { Component, Input, OnInit, ViewChild } from '@angular/core';
22 import { MatSort } from '@angular/material/sort';
23 import { Subscription } from 'rxjs';
24 import { CaasIngressService } from '../services/caas-ingress/caas-ingress.service';
25 import { InstanceSelectorService } from '../services/instance-selector/instance-selector.service';
26 import { ConfirmDialogService } from '../services/ui/confirm-dialog.service';
27 import { ErrorDialogService } from '../services/ui/error-dialog.service';
28 import { LoadingDialogService } from '../services/ui/loading-dialog.service';
29 import { NotificationService } from '../services/ui/notification.service';
30 import { CaasIngressDataSource } from './caas-ingress.datasource';
31
32 @Component({
33   selector: 'rd-caas-ingress',
34   templateUrl: './caas-ingress.component.html',
35   styleUrls: ['./caas-ingress.component.scss']
36 })
37 export class CaasIngressComponent implements OnInit {
38
39   // Cluster name is displayed in page title
40   @Input() cluster: string;
41   // Namespace is used to query backend
42   @Input() namespace: string;
43
44   dataSource: CaasIngressDataSource;
45   displayedColumns: string[] = ['namespace', 'name', 'status', 'ip', 'containers', 'restartCount', 'creationTime'];
46   @ViewChild(MatSort, { static: true }) sort: MatSort;
47   private instanceChange: Subscription;
48
49   constructor(
50     private caasIngressSvc: CaasIngressService,
51     private confirmDialogService: ConfirmDialogService,
52     private errorDialogService: ErrorDialogService,
53     private loadingDialogService: LoadingDialogService,
54     public instanceSelectorService: InstanceSelectorService,
55     private notificationService: NotificationService) { }
56
57   ngOnInit() {
58     this.dataSource = new CaasIngressDataSource(this.caasIngressSvc, this.sort, this.notificationService);
59     this.instanceChange = this.instanceSelectorService.getSelectedInstancekey().subscribe((instanceKey: string) => {
60       if (instanceKey) {
61         this.dataSource.loadTable(instanceKey, this.cluster, this.namespace);
62       }
63     })
64   }
65
66   ngOnDestroy() {
67     this.instanceChange.unsubscribe();
68   }
69
70 }