2 * ========================LICENSE_START=================================
5 * Copyright (C) 2020 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 { FormControl, FormGroup, Validators } from '@angular/forms';
23 import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
24 import { BehaviorSubject } from 'rxjs/BehaviorSubject';
25 import { finalize } from 'rxjs/operators';
26 import { XMXappDescriptor} from '../../interfaces/app-mgr.types';
27 import { AppMgrService } from '../../services/app-mgr/app-mgr.service';
28 import { NotificationService } from '../../services/ui/notification.service';
29 import { LoadingDialogService } from '../../services/ui/loading-dialog.service';
30 import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
33 selector: 'rd-deploy-dialog',
34 templateUrl: './deploy-dialog.component.html',
35 styleUrls: ['./deploy-dialog.component.scss']
37 export class DeployDialogComponent implements OnInit {
39 private loadingSubject = new BehaviorSubject<boolean>(false);
40 public loading$ = this.loadingSubject.asObservable();
41 public deployForm: FormGroup;
42 xappDescriptor: XMXappDescriptor ;
46 private dialogRef: MatDialogRef<DeployDialogComponent>,
47 private appMgrService: AppMgrService,
48 private loadingDialogService: LoadingDialogService,
49 private notificationService: NotificationService,
50 @Inject(MAT_DIALOG_DATA) private data
54 this.deployForm = new FormGroup({
55 xappName: new FormControl(this.data.xappName, [Validators.required]),
56 helmVersion: new FormControl(''),
57 releaseName: new FormControl(''),
58 namespace: new FormControl(''),
59 overrideFile: new FormControl({}),
63 selectoverrideFile(event) {
64 if (event.target.files.length) {
65 this.overrideFile = event.target.files[0];
66 let fileReader = new FileReader();
67 fileReader.onload = (e) => {
68 this.deployForm.value.overrideFile = JSON.parse(fileReader.result as string);
70 fileReader.readAsText(this.overrideFile);
73 this.deployForm.value.overrideFile =null
77 deploy(xapp: XMXappDescriptor) {
78 this.xappDescriptor = xapp
79 this.loadingDialogService.startLoading('Deploying ' + this.xappDescriptor.xappName);
80 this.appMgrService.deployXapp(this.data.instanceKey, this.xappDescriptor)
83 this.loadingDialogService.stopLoading();
84 this.dialogRef.close();
88 (response: HttpResponse<Object>) => {
89 this.notificationService.success('App deploy succeeded!');
91 ((her: HttpErrorResponse) => {
92 // the error field should have an ErrorTransport object
93 let msg = her.message;
94 if (her.error && her.error.message) {
95 msg = her.error.message;
97 this.notificationService.warn('App deploy failed: ' + msg);