2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
20 import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
21 import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
22 import { MatDialog } from '@angular/material/dialog';
23 import { MatSort } from '@angular/material/sort';
24 import { Subscription } from 'rxjs';
25 import { finalize } from 'rxjs/operators';
26 import { XMDeployableApp } from '../interfaces/app-mgr.types';
27 import { AppMgrService } from '../services/app-mgr/app-mgr.service';
28 import { InstanceSelectorService } from '../services/instance-selector/instance-selector.service';
29 import { LoadingDialogService } from '../services/ui/loading-dialog.service';
30 import { UiService } from '../services/ui/ui.service';
31 import { AppConfigurationComponent } from './../app-configuration/app-configuration.component';
32 import { ConfirmDialogService } from './../services/ui/confirm-dialog.service';
33 import { NotificationService } from './../services/ui/notification.service';
34 import { CatalogDataSource } from './catalog.datasource';
37 selector: 'rd-app-catalog',
38 templateUrl: './catalog.component.html',
39 styleUrls: ['./catalog.component.scss'],
41 export class CatalogComponent implements OnInit, OnDestroy {
44 panelClass: string = "";
45 displayedColumns: string[] = ['name', 'version', 'action'];
46 dataSource: CatalogDataSource;
47 private instanceChange: Subscription;
48 private instanceKey: string;
50 @ViewChild(MatSort, { static: true }) sort: MatSort;
53 private appMgrService: AppMgrService,
54 private confirmDialogService: ConfirmDialogService,
55 private dialog: MatDialog,
56 private loadingDialogService: LoadingDialogService,
57 private notificationService: NotificationService,
58 public instanceSelectorService: InstanceSelectorService,
59 public ui: UiService) { }
62 this.dataSource = new CatalogDataSource(this.appMgrService, this.sort, this.notificationService);
63 this.ui.darkModeState.subscribe((isDark) => {
64 this.darkMode = isDark;
67 this.instanceChange = this.instanceSelectorService.getSelectedInstancekey().subscribe((instanceKey: string) => {
69 this.instanceKey = instanceKey;
70 this.dataSource.loadTable(instanceKey);
76 this.instanceChange.unsubscribe();
79 onConfigureApp(xapp: XMDeployableApp): void {
81 this.panelClass = "dark-theme";
85 const dialogRef = this.dialog.open(AppConfigurationComponent, {
86 panelClass: this.panelClass,
94 instanceKey: this.instanceKey
100 onDeployApp(app: XMDeployableApp): void {
101 this.confirmDialogService.openConfirmDialog('Deploy application ' + app.name + '?')
102 .afterClosed().subscribe((res: boolean) => {
104 this.loadingDialogService.startLoading('Deploying ' + app.name);
105 this.appMgrService.deployXapp(this.instanceKey, app.name)
107 finalize(() => this.loadingDialogService.stopLoading())
110 (response: HttpResponse<Object>) => {
111 this.notificationService.success('App deploy succeeded!');
113 ((her: HttpErrorResponse) => {
114 // the error field should have an ErrorTransport object
115 let msg = her.message;
116 if (her.error && her.error.message) {
117 msg = her.error.message;
119 this.notificationService.warn('App deploy failed: ' + msg);