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';
30 import { XMXappConfig } from "../interfaces/app-mgr.types"
33 selector: 'rd-app-configuration',
34 templateUrl: './app-configuration.component.html',
35 styleUrls: ['./app-configuration.component.scss']
37 export class AppConfigurationComponent implements OnInit {
39 private loadingSubject = new BehaviorSubject<boolean>(false);
40 public loading$ = this.loadingSubject.asObservable();
43 private dialogRef: MatDialogRef<AppConfigurationComponent>,
44 private appMgrService: AppMgrService,
45 private errorDiaglogService: ErrorDialogService,
46 private loadingDialogService: LoadingDialogService,
47 private notificationService: NotificationService,
48 @Inject(MAT_DIALOG_DATA) private data
51 xappConfig: XMXappConfig
54 this.loadingSubject.next(true);
55 this.appMgrService.getConfig(this.data.instanceKey)
57 finalize(() => this.loadingSubject.next(false))
61 this.loadConfigForm(this.data.xapp, allConfig);
66 updateconfig(config: any) {
67 this.loadingDialogService.startLoading('Updating ' + this.data.xapp + ' configuration');
68 this.appMgrService.putConfig(this.data.instanceKey, JSON.parse(config))
71 this.loadingDialogService.stopLoading();
72 this.dialogRef.close();
76 (response: HttpResponse<Object>) => {
77 this.notificationService.success('Configuration update succeeded!');
79 ((her: HttpErrorResponse) => {
80 let msg = her.message;
81 if (her.error && her.error.message) {
82 msg = her.error.message;
84 this.notificationService.warn('Configuration update failed: ' + msg);
89 loadConfigForm(name: string, allConfig: any) {
90 const xappConfig = allConfig.find(xapp => xapp.metadata.name === name);
91 if (xappConfig != null) {
92 this.xappConfig = xappConfig
94 this.errorDiaglogService.displayError('Cannot find configration data for ' + name);
95 this.dialogRef.close();