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