update configure workflow
[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 { OnboardComponent } from './../onboard/onboard.component';
34 import { CatalogDataSource } from './catalog.datasource';
35
36 @Component({
37   selector: 'rd-app-catalog',
38   templateUrl: './catalog.component.html',
39   styleUrls: ['./catalog.component.scss'],
40 })
41 export class CatalogComponent implements OnInit, OnDestroy {
42
43   darkMode: boolean;
44   panelClass: string;
45   displayedColumns: string[] = ['name', 'version', 'action'];
46   dataSource: CatalogDataSource;
47   private instanceChange: Subscription;
48   private instanceKey: string;
49
50   @ViewChild(MatSort, { static: true }) sort: MatSort;
51
52   constructor(
53     private appMgrService: AppMgrService,
54     private dialog: MatDialog,
55     private notificationService: NotificationService,
56     public instanceSelectorService: InstanceSelectorService,
57     public ui: UiService) { }
58
59   ngOnInit() {
60     this.dataSource = new CatalogDataSource(this.appMgrService, this.sort, this.notificationService);
61     this.ui.darkModeState.subscribe((isDark) => {
62       this.darkMode = isDark;
63     });
64
65     this.instanceChange = this.instanceSelectorService.getSelectedInstance().subscribe((instance: RicInstance) => {
66       if (instance.key) {
67         this.instanceKey = instance.key;
68         this.dataSource.loadTable(instance.key);
69       }
70     });
71   }
72
73   ngOnDestroy() {
74     this.instanceChange.unsubscribe();
75   }
76
77   onDeployApp(app: XMXapp): void {
78     if (this.darkMode) {
79       this.panelClass = 'dark-theme';
80     } else {
81       this.panelClass = '';
82     }
83     const dialogRef = this.dialog.open(DeployDialogComponent, {
84       panelClass: this.panelClass,
85       width: '400px',
86       maxHeight: '1000px',
87       position: {
88         top: '10%'
89       },
90       data: {
91         xappName: app.name,
92         instanceKey: this.instanceKey
93       }
94
95     });
96   }
97
98   onboard(): void {
99     if (this.darkMode) {
100       this.panelClass = 'dark-theme';
101     } else {
102       this.panelClass = '';
103     }
104     const dialogRef = this.dialog.open(OnboardComponent, {
105       panelClass: this.panelClass,
106       width: '400px',
107       maxHeight: '1000px',
108       position: {
109         top: '10%'
110       },
111       data: {
112         instanceKey: this.instanceKey
113       }
114
115     });
116   }
117
118 }