Use O-RAN-SC
[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, Inject } from '@angular/core';
21 import { LocalDataSource } from 'ng2-smart-table';
22 import { CatalogService } from '../services/catalog/catalog.service';
23 import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
24
25 export interface DialogData {
26     name: string;
27 }
28
29
30 @Component({
31   selector: 'app-catalog',
32   templateUrl: './catalog.component.html',
33   styleUrls: ['./catalog.component.css']
34 })
35 export class CatalogComponent {
36
37   settings = {
38     hideSubHeader: true,
39     actions: {
40       columnTitle: 'Actions',
41       add: false,
42       edit: false,
43       delete: false,
44       custom: [
45       { name: 'deployxApp', title: 'Deploy'},
46     ],
47       position: 'right'
48
49     },
50     columns: {
51       name: {
52         title: 'xApp Name',
53         type: 'string',
54       },
55       version: {
56         title: 'xApp Version',
57         type: 'string',
58       },
59       status: {
60         title: 'Status',
61         type: 'string',
62       },
63     },
64   };
65
66   source: LocalDataSource = new LocalDataSource();
67
68     constructor(private service: CatalogService, public dialog: MatDialog) {
69     this.service.getAll().subscribe((val:any[]) => this.source.load(val));
70   }
71
72
73     onDeployxApp(event): void {
74         const dialogRef = this.dialog.open(AppCatalogDeployDialog, {
75             width: '400px',
76             data: { name: event.data.name }
77         });
78
79         dialogRef.afterClosed().subscribe(result => {
80             console.log('The dialog was closed');
81         });
82     }
83
84 }
85
86 @Component({
87     selector: 'app-catalog-deploy-dialog',
88     templateUrl: 'catalog.component.deploy-dialog.html',
89     styleUrls: ['./catalog.component.css']
90 })
91
92 export class AppCatalogDeployDialog{
93
94     constructor(
95         public dialogRef: MatDialogRef<AppCatalogDeployDialog>,
96         private service: CatalogService,
97         @Inject(MAT_DIALOG_DATA) public data: DialogData) { }
98
99     onNoClick(): void {
100         this.dialogRef.close();
101     }
102
103     deployXapp(): void {
104         this.service.deployXapp(this.data.name).subscribe((val: any[]) => console.log(val));;
105         this.dialogRef.close();
106     }
107
108 }