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===================================
21 import { Component, Inject, OnInit } from '@angular/core';
22 import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
23 import { BehaviorSubject } from 'rxjs/BehaviorSubject';
24 import { finalize } from 'rxjs/operators';
25 import { AppMgrService } from '../services/app-mgr/app-mgr.service';
26 import { ErrorDialogService } from '../services/ui/error-dialog.service';
27 import { LoadingDialogService } from '../services/ui/loading-dialog.service';
28 import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
29 import { NotificationService } from './../services/ui/notification.service';
32 selector: 'rd-app-configuration',
33 templateUrl: './app-configuration.component.html',
34 styleUrls: ['./app-configuration.component.scss']
36 export class AppConfigurationComponent implements OnInit {
38 private loadingSubject = new BehaviorSubject<boolean>(false);
39 public loading$ = this.loadingSubject.asObservable();
42 private dialogRef: MatDialogRef<AppConfigurationComponent>,
43 private appMgrService: AppMgrService,
44 private errorDiaglogService: ErrorDialogService,
45 private loadingDialogService: LoadingDialogService,
46 private notificationService: NotificationService,
47 @Inject(MAT_DIALOG_DATA) private data
51 xappConfigSchema: any;
55 this.loadingSubject.next(true);
56 this.appMgrService.getConfig()
58 finalize(() => this.loadingSubject.next(false))
62 this.loadConfigForm(this.data.name, allConfig)
69 metadata: this.xappMetadata,
70 descriptor: this.xappConfigSchema,
72 layout: this.xappLayout
74 this.loadingDialogService.startLoading("Updating " + this.data.name + " configuration");
75 this.appMgrService.putConfig(config)
78 this.loadingDialogService.stopLoading();
79 this.dialogRef.close();
83 (response: HttpResponse<Object>) => {
84 this.notificationService.success('Configuration update succeeded!');
86 ((her: HttpErrorResponse) => {
87 let msg = her.message;
88 if (her.error && her.error.message) {
89 msg = her.error.message;
91 this.notificationService.warn('Configuration update failed: ' + msg);
96 loadConfigForm(name: string, allConfig: any) {
97 var xappConfig = allConfig.find(xapp => xapp.metadata.name == name)
98 if (xappConfig != null) {
99 this.xappMetadata = xappConfig.metadata
100 this.xappConfigSchema = xappConfig.descriptor;
101 this.xappConfigData = xappConfig.config;
102 this.xappLayout = xappConfig.layout;
104 this.errorDiaglogService.displayError("Cannot find configration data for " + name);
105 this.dialogRef.close();