51890ee64853371dd3fc074ad64da00a0e0ccd53
[portal/ric-dashboard.git] / 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 { HttpErrorResponse, HttpResponse } from '@angular/common/http';
21 import { Component, OnInit, ViewChild } from '@angular/core';
22 import { MatDialog } from '@angular/material/dialog';
23 import { MatSort } from '@angular/material/sort';
24 import { finalize } from 'rxjs/operators';
25 import { XMDeployableApp } from '../interfaces/app-mgr.types';
26 import { AppMgrService } from '../services/app-mgr/app-mgr.service';
27 import { ErrorDialogService } from '../services/ui/error-dialog.service';
28 import { LoadingDialogService } from '../services/ui/loading-dialog.service';
29 import { AppConfigurationComponent } from './../app-configuration/app-configuration.component';
30 import { ConfirmDialogService } from './../services/ui/confirm-dialog.service';
31 import { NotificationService } from './../services/ui/notification.service';
32 import { CatalogDataSource } from './catalog.datasource';
33
34 @Component({
35   selector: 'rd-app-catalog',
36   templateUrl: './catalog.component.html',
37   styleUrls: ['./catalog.component.scss'],
38 })
39 export class CatalogComponent implements OnInit {
40
41   displayedColumns: string[] = ['name', 'version', 'action'];
42   dataSource: CatalogDataSource;
43   @ViewChild(MatSort, { static: true }) sort: MatSort;
44
45   constructor(
46     private appMgrService: AppMgrService,
47     private confirmDialogService: ConfirmDialogService,
48     private dialog: MatDialog,
49     private errorDiaglogService: ErrorDialogService,
50     private loadingDialogService: LoadingDialogService,
51     private notificationService: NotificationService) { }
52
53   ngOnInit() {
54     this.dataSource = new CatalogDataSource(this.appMgrService, this.sort, this.notificationService);
55     this.dataSource.loadTable();
56   }
57
58   onConfigureApp(xapp: XMDeployableApp): void {
59     const dialogRef = this.dialog.open(AppConfigurationComponent, {
60       width: '40%',
61       maxHeight: '500px',
62       position: {
63         top: '10%'
64       },
65       data: xapp
66     });
67
68   }
69
70   onDeployApp(app: XMDeployableApp): void {
71     this.confirmDialogService.openConfirmDialog('Deploy application ' + app.name + '?')
72       .afterClosed().subscribe((res: boolean) => {
73         if (res) {
74           this.loadingDialogService.startLoading('Deploying ' + app.name);
75           this.appMgrService.deployXapp(app.name)
76             .pipe(
77               finalize(() => this.loadingDialogService.stopLoading())
78             )
79             .subscribe(
80               (response: HttpResponse<Object>) => {
81                 this.notificationService.success('App deploy succeeded!');
82               },
83               ((her: HttpErrorResponse) => {
84                 // the error field should have an ErrorTransport object
85                 let msg = her.message;
86                 if (her.error && her.error.message) {
87                   msg = her.error.message;
88                 }
89                 this.notificationService.warn('App deploy failed: ' + msg);
90               })
91             );
92         }
93       }
94       );
95   }
96
97 }