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 { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
23 import { BehaviorSubject } from 'rxjs/BehaviorSubject';
24 import { finalize } from 'rxjs/operators';
25 import { XappOnboarderService } from '../services/xapp-onboarder/xapp-onboarder.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 { FormControl, FormGroup, Validators } from '@angular/forms';
33 selector: 'rd-onboard',
34 templateUrl: './onboard.component.html',
35 styleUrls: ['./onboard.component.scss']
37 export class OnboardComponent implements OnInit {
39 private loadingSubject = new BehaviorSubject<boolean>(false);
40 public loading$ = this.loadingSubject.asObservable();
41 public urlOnboardForm: FormGroup;
44 private dialogRef: MatDialogRef<OnboardComponent>,
45 private xappOnboarderService: XappOnboarderService,
46 private errorDiaglogService: ErrorDialogService,
47 private loadingDialogService: LoadingDialogService,
48 private notificationService: NotificationService,
49 @Inject(MAT_DIALOG_DATA) private data
53 this.urlOnboardForm = new FormGroup({
54 configURL: new FormControl('', [Validators.required]),
55 schemaURL: new FormControl('')
62 "config-file.json": {},
65 "config-file.json_url": "",
69 this.loadingDialogService.startLoading('Onboarding xApp');
70 this.xappOnboarderService.onboardXappFile(this.descriptor, this.data.instanceKey)
73 this.loadingDialogService.stopLoading();
74 this.dialogRef.close();
78 (response: HttpResponse<Object>) => {
79 this.notificationService.success('Onboard succeeded!');
81 ((her: HttpErrorResponse) => {
82 let msg = her.message;
83 if (her.error && her.error.message) {
84 msg = her.error.message;
86 this.notificationService.warn('Onboard failed: ' + msg);
92 this.descriptor_url["config-file.json_url"] = data.configURL;
94 this.descriptor_url["controls-schema.json_url"] = data.schemaURL;
96 this.loadingDialogService.startLoading('Onboarding xApp');
97 this.xappOnboarderService.onboardXappURL(this.descriptor_url, this.data.instanceKey)
100 this.loadingDialogService.stopLoading();
101 this.dialogRef.close();
105 (response: HttpResponse<Object>) => {
106 this.notificationService.success('Onboard succeeded!');
108 ((her: HttpErrorResponse) => {
109 let msg = her.message;
110 if (her.error && her.error.message) {
111 msg = her.error.message;
113 this.notificationService.warn('Onboard failed: ' + msg);
119 selectConfigFile(event) {
120 if (event.target.files.length) {
121 this.configFile = event.target.files[0];
122 let fileReader = new FileReader();
123 fileReader.onload = (e) => {
124 this.descriptor["config-file.json"] = JSON.parse(fileReader.result as string);
126 fileReader.readAsText(this.configFile);
130 selectControlsSchema(event) {
131 if (event.target.files.length) {
132 this.controlsSchema = event.target.files[0];
133 let fileReader = new FileReader();
134 fileReader.onload = (e) => {
135 this.descriptor["controls-schema.json"] = JSON.parse(fileReader.result as string);
137 fileReader.readAsText(this.controlsSchema);