4eab40831c004bbfed11f9bc603a9dd1ee19e8af
[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
30 @Component({
31   selector: 'rd-app-catalog',
32   templateUrl: './catalog.component.html',
33   styleUrls: ['./catalog.component.scss'],
34 })
35 export class CatalogComponent implements OnInit {
36
37   displayedColumns: string[] = ['name', 'version', 'action'];
38   dataSource: CatalogDataSource;
39   @ViewChild(MatSort, {static: true}) sort: MatSort;
40
41   constructor(
42     private appMgrService: AppMgrService,
43     private confirmDialogService: ConfirmDialogService,
44     private errorDiaglogService: ErrorDialogService,
45     private notificationService: NotificationService) { }
46
47   ngOnInit() {
48     this.dataSource = new CatalogDataSource(this.appMgrService, this.sort, this.notificationService );
49     this.dataSource.loadTable();
50   }
51
52   onConfigureApp(name: string): void {
53     const aboutError = 'Configure not implemented (yet)';
54     this.errorDiaglogService.displayError(aboutError);
55   }
56
57   onDeployApp(app: XMDeployableApp): void {
58     this.confirmDialogService.openConfirmDialog('Deploy application ' + app.name + '?')
59       .afterClosed().subscribe( (res: boolean) => {
60         if (res) {
61           this.appMgrService.deployXapp(app.name).subscribe(
62             (response: HttpResponse<Object>) => {
63               this.notificationService.success('Deploy succeeded!');
64             },
65             (error: HttpErrorResponse) => {
66               this.notificationService.warn('Deploy failed: ' + error.message);
67             }
68           );
69         }
70       }
71     );
72   }
73
74 }