1- import { Component , EventEmitter , Input , OnChanges , OnInit , Output , SimpleChanges } from '@angular/core'
1+ import { Component , EventEmitter , Input , OnChanges , OnInit , Output , SimpleChanges , ViewChild } from '@angular/core'
22import { FormArray , FormBuilder , FormControl , FormGroup , Validators } from '@angular/forms'
33import { MarketplaceService } from '../../services/marketplace.service'
44import { MatSnackBar } from '@angular/material/snack-bar'
55import * as _ from 'lodash'
66import { HttpErrorResponse } from '@angular/common/http'
77import { ActivatedRoute } from '@angular/router'
8- import { JsonEditorOptions } from 'ang-jsoneditor'
8+ import { JsonEditorComponent , JsonEditorOptions } from 'ang-jsoneditor'
99
1010@Component ( {
1111 selector : 'ws-app-via-api' ,
@@ -14,6 +14,7 @@ import { JsonEditorOptions } from 'ang-jsoneditor'
1414} )
1515export class ViaApiComponent implements OnInit , OnChanges {
1616 //#region (global varialbles)
17+ @ViewChild ( 'jsonEditor' ) jsonEditor : JsonEditorComponent | undefined
1718 //#region (view chaild, input and output)
1819 @Input ( ) providerDetails ?: any
1920 @Input ( ) viaApiTabIndex = 0
@@ -460,28 +461,34 @@ export class ViaApiComponent implements OnInit, OnChanges {
460461 this . providerDetails [ 'data' ] [ 'isActive' ] = true
461462 const hasTransformationAlready = this . providerDetails [ this . transformationType ] ? true : false
462463 this . transformationSpecForm . markAsTouched ( )
463- if ( this . transformationSpecForm . valid ) {
464- this . providerDetails [ this . transformationType ] = this . transformationSpecForm . value
465- this . marketPlaceSvc . updateProvider ( this . providerDetails ) . subscribe ( {
466- next : ( responce : any ) => {
467- if ( responce ) {
468- setTimeout ( ( ) => {
469- let successMsg = 'Saved Successfully'
470- successMsg = hasTransformationAlready ? 'Transform Content updated successfully.' : 'Transform Content saved successfully.'
471- this . showSnackBar ( successMsg )
472- this . transformationsUpdated = true
473- this . loadProviderDetails . emit ( true )
474- } , 1000 )
475- }
476- } ,
477- error : ( error : HttpErrorResponse ) => {
478- const errmsg = _ . get ( error , 'error.params.errMsg' , 'Something went worng, please try again later' )
479- this . showSnackBar ( errmsg )
480- } ,
481- } )
464+ try {
465+ this . jsonEditor ! . get ( )
466+ if ( this . transformationSpecForm . valid && JSON . stringify ( this . transformationSpecForm . value ) !== '{}' ) {
467+ this . providerDetails [ this . transformationType ] = this . transformationSpecForm . value
468+ this . marketPlaceSvc . updateProvider ( this . providerDetails ) . subscribe ( {
469+ next : ( responce : any ) => {
470+ if ( responce ) {
471+ setTimeout ( ( ) => {
472+ let successMsg = 'Saved Successfully'
473+ successMsg = hasTransformationAlready ? 'Transform Content updated successfully.' : 'Transform Content saved successfully.'
474+ this . showSnackBar ( successMsg )
475+ this . transformationsUpdated = true
476+ this . loadProviderDetails . emit ( true )
477+ } , 1000 )
478+ }
479+ } ,
480+ error : ( error : HttpErrorResponse ) => {
481+ const errmsg = _ . get ( error , 'error.params.errMsg' , 'Something went worng, please try again later' )
482+ this . showSnackBar ( errmsg )
483+ } ,
484+ } )
482485
483- } else {
484- const message = this . transforamtionType === 'viaForm' ? 'Please provide all mandatory fields' : 'Please provide spec json'
486+ } else {
487+ const message = this . transforamtionType === 'viaForm' ? 'Please provide all mandatory fields' : 'Please provide valid spec json'
488+ this . showSnackBar ( message )
489+ }
490+ } catch ( err ) {
491+ const message = 'Please provied valid spec json'
485492 this . showSnackBar ( message )
486493 }
487494 }
0 commit comments