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