df43995943f8659c6d9a11bdd8b0daf86f12d166
[portal/ric-dashboard.git] / dashboard / webapp-frontend / src / app / catalog / catalog.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 import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
21 import { MatDialog } from '@angular/material/dialog';
22 import { MatSort } from '@angular/material/sort';
23 import { Subscription } from 'rxjs';
24 import { XMXapp } from '../interfaces/app-mgr.types';
25 import { RicInstance } from '../interfaces/dashboard.types';
26 import { AppMgrService } from '../services/app-mgr/app-mgr.service';
27 import { InstanceSelectorService } from '../services/instance-selector/instance-selector.service';
28 import { ConfirmDialogService } from '../services/ui/confirm-dialog.service';
29 import { LoadingDialogService } from '../services/ui/loading-dialog.service';
30 import { NotificationService } from '../services/ui/notification.service';
31 import { UiService } from '../services/ui/ui.service';
32 import { DeployDialogComponent } from '../ui/deploy-dialog/deploy-dialog.component';
33 import { AppConfigurationComponent } from './../app-configuration/app-configuration.component';
34 import { OnboardComponent } from './../onboard/onboard.component';
35 import { CatalogDataSource } from './catalog.datasource';
36
37 @Component({
38   selector: 'rd-app-catalog',
39   templateUrl: './catalog.component.html',
40   styleUrls: ['./catalog.component.scss'],
41 })
42 export class CatalogComponent implements OnInit, OnDestroy {
43
44   darkMode: boolean;
45   panelClass: string;
46   displayedColumns: string[] = ['name', 'version', 'action'];
47   dataSource: CatalogDataSource;
48   private instanceChange: Subscription;
49   private instanceKey: string;
50
51   @ViewChild(MatSort, { static: true }) sort: MatSort;
52
53   constructor(
54     private appMgrService: AppMgrService,
55     private confirmDialogService: ConfirmDialogService,
56     private dialog: MatDialog,
57     private loadingDialogService: LoadingDialogService,
58     private notificationService: NotificationService,
59     public instanceSelectorService: InstanceSelectorService,
60     public ui: UiService) { }
61
62   ngOnInit() {
63     this.dataSource = new CatalogDataSource(this.appMgrService, this.sort, this.notificationService);
64     this.ui.darkModeState.subscribe((isDark) => {
65       this.darkMode = isDark;
66     });
67
68     this.instanceChange = this.instanceSelectorService.getSelectedInstance().subscribe((instance: RicInstance) => {
69       if (instance.key) {
70         this.instanceKey = instance.key;
71         this.dataSource.loadTable(instance.key);
72       }
73     });
74   }
75
76   ngOnDestroy() {
77     this.instanceChange.unsubscribe();
78   }
79
80   onConfigureApp(xapp: XMXapp): void {
81     if (this.darkMode) {
82       this.panelClass = 'dark-theme';
83     } else {
84       this.panelClass = '';
85     }
86     const dialogRef = this.dialog.open(AppConfigurationComponent, {
87       panelClass: this.panelClass,
88       width: '40%',
89       maxHeight: '500px',
90       position: {
91         top: '10%'
92       },
93       data: {
94         xapp: xapp,
95         instanceKey: this.instanceKey
96       }
97
98     });
99   }
100
101   onDeployApp(app: XMXapp): void {
102     if (this.darkMode) {
103       this.panelClass = 'dark-theme';
104     } else {
105       this.panelClass = '';
106     }
107     const dialogRef = this.dialog.open(DeployDialogComponent, {
108       panelClass: this.panelClass,
109       width: '400px',
110       maxHeight: '1000px',
111       position: {
112         top: '10%'
113       },
114       data: {
115         xappName: app.name,
116         instanceKey: this.instanceKey
117       }
118
119     });
120   }
121
122   onboard(): void {
123     if (this.darkMode) {
124       this.panelClass = 'dark-theme';
125     } else {
126       this.panelClass = '';
127     }
128     const dialogRef = this.dialog.open(OnboardComponent, {
129       panelClass: this.panelClass,
130       width: '400px',
131       maxHeight: '1000px',
132       position: {
133         top: '10%'
134       },
135       data: {
136         instanceKey: this.instanceKey
137       }
138
139     });
140   }
141
142 }