diff --git a/src/app/appmarket/appmanagement/app-add-json-app/app-add-json-app.component.html b/src/app/appmarket/appmanagement/app-add-json-app/app-add-json-app.component.html index 308e3ad22cff13505b7bfa16e2545a9837b60e8c..a89537de67dd331f96c4f8c290963b0eb15ef966 100644 --- a/src/app/appmarket/appmanagement/app-add-json-app/app-add-json-app.component.html +++ b/src/app/appmarket/appmanagement/app-add-json-app/app-add-json-app.component.html @@ -25,6 +25,10 @@ {{error}} </div> + <div *ngIf="JsonError" style="color: indianred"> + {{'APPS_MANAGEMENT.JSON_ERROR' | translate}} + </div> + </div> <div class="nmaas-modal-footer"> diff --git a/src/app/appmarket/appmanagement/app-add-json-app/app-add-json-app.component.ts b/src/app/appmarket/appmanagement/app-add-json-app/app-add-json-app.component.ts index 595cfe1c0fc6ec2f6143e2bf03f04c0c637fb985..62638c292ab2e1df41073e8aa0f606e036379548 100644 --- a/src/app/appmarket/appmanagement/app-add-json-app/app-add-json-app.component.ts +++ b/src/app/appmarket/appmanagement/app-add-json-app/app-add-json-app.component.ts @@ -1,75 +1,85 @@ import {Component, OnInit, ViewChild} from '@angular/core'; import {ModalComponent} from '../../../shared'; import {AppsService} from '../../../service'; -import {HttpHeaders} from '@angular/common/http'; import {Router} from '@angular/router'; @Component({ - selector: 'app-app-add-json-app', - templateUrl: './app-add-json-app.component.html', - styleUrls: ['./app-add-json-app.component.css'] + selector: 'app-app-add-json-app', + templateUrl: './app-add-json-app.component.html', + styleUrls: ['./app-add-json-app.component.css'] }) export class AppAddJsonAppComponent implements OnInit { - @ViewChild(ModalComponent, { static: true }) - public readonly modal: ModalComponent; + @ViewChild(ModalComponent, {static: true}) + public readonly modal: ModalComponent; - public jsonText = ''; - public error = ''; + public jsonText = ''; + public error = ''; + public JsonError = false; - constructor(private readonly appsService: AppsService, - private readonly router: Router) { } - - + constructor(private readonly appsService: AppsService, + private readonly router: Router) { + } - ngOnInit(): void { - } - onUpload(event: any) { - console.log(event); - const file = event.files[0]; - console.log(file); - const fileReader = new FileReader(); - fileReader.readAsText(file); - fileReader.onload = () => { - if (typeof fileReader.result === 'string') { - console.log(JSON.parse(fileReader.result)); - this.appsService.createApplicationDTO(JSON.parse(fileReader.result)).subscribe(result => { - console.log('uploaded', result); - this.modal.hide(); - this.router.navigate(['apps', result.id]) - }, - error => { - console.log(error) - this.error = error.message - }) - } + ngOnInit(): void { } - fileReader.onerror = (error) => { - console.log(error); - } - } - public sendJsonText() { - if (this.jsonText.length > 0) { - this.appsService.createApplicationDTO(JSON.parse(this.jsonText)).subscribe(result => { - console.log('uploaded', result); - this.modal.hide(); - this.router.navigate(['apps', result.id]) - }, - error => { - console.log(error) - this.error = error.message - }) + onUpload(event: any) { + console.log(event); + const file = event.files[0]; + console.log(file); + const fileReader = new FileReader(); + fileReader.readAsText(file); + fileReader.onload = () => { + if (typeof fileReader.result === 'string') { + try { + JSON.parse(fileReader.result); + this.appsService.createApplicationDTO(JSON.parse(fileReader.result)).subscribe(result => { + console.log('uploaded', result); + this.modal.hide(); + this.router.navigate(['apps', result.id]) + }, + error => { + console.log(error) + this.error = error.message + }) + } catch (e) { + console.warn('invalid json') + this.JsonError = true; + } + } + } + fileReader.onerror = (error) => { + console.log(error); + } + } + public sendJsonText() { + if (this.jsonText.length > 0) { + try { + JSON.parse(this.jsonText); + this.appsService.createApplicationDTO(JSON.parse(this.jsonText)).subscribe(result => { + console.log('uploaded', result); + this.modal.hide(); + this.router.navigate(['apps', result.id]) + }, + error => { + console.log(error) + this.error = error.message + }) + } catch (e) { + console.warn('invalid json') + this.JsonError = true; + } + } } - } - public show() { - this.modal.show(); - } + public show() { + this.modal.show(); + } } diff --git a/src/app/appmarket/appmanagement/app-add-json-version-app/app-add-json-version-app.component.ts b/src/app/appmarket/appmanagement/app-add-json-version-app/app-add-json-version-app.component.ts index 49986732502c852119bb74b905ddb4fd239b3bcd..2fce47d03be8e981e698199ad4f4981a4d4b41ba 100644 --- a/src/app/appmarket/appmanagement/app-add-json-version-app/app-add-json-version-app.component.ts +++ b/src/app/appmarket/appmanagement/app-add-json-version-app/app-add-json-version-app.component.ts @@ -16,6 +16,9 @@ export class AppAddJsonVersionAppComponent implements OnInit { public jsonText = ''; public error = ''; + public JsonError = false; + + @Output() public refresh: EventEmitter<boolean> = new EventEmitter<boolean>(); @@ -36,15 +39,21 @@ export class AppAddJsonVersionAppComponent implements OnInit { fileReader.onload = () => { if (typeof fileReader.result === 'string') { console.log(JSON.parse(fileReader.result)); - this.appsService.createApplication(JSON.parse(fileReader.result)).subscribe(result => { - console.log('uploaded', result); - this.modal.hide(); + try { + JSON.parse(fileReader.result); + this.appsService.createApplication(JSON.parse(fileReader.result)).subscribe(result => { + console.log('uploaded', result); + this.modal.hide(); this.refresh.emit(true); - }, - error => { - console.log(error) - this.error = error.message - }) + }, + error => { + console.log(error) + this.error = error.message + }) + } catch (e) { + console.warn('invalid json') + this.JsonError = true; + } } } fileReader.onerror = (error) => { @@ -54,16 +63,21 @@ export class AppAddJsonVersionAppComponent implements OnInit { public sendJsonText() { if (this.jsonText.length > 0) { - this.appsService.createApplication(JSON.parse(this.jsonText)).subscribe(result => { - console.log('uploaded', result); - this.modal.hide(); - this.refresh.emit(true); - }, - error => { - console.log(error) - this.error = error.message - }) - + try { + JSON.parse(this.jsonText); + this.appsService.createApplication(JSON.parse(this.jsonText)).subscribe(result => { + console.log('uploaded', result); + this.modal.hide(); + this.refresh.emit(true); + }, + error => { + console.log(error) + this.error = error.message + }) + } catch (e) { + console.warn('invalid json') + this.JsonError = true; + } } }