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'
2
2
import { FormArray , FormBuilder , FormControl , FormGroup , Validators } from '@angular/forms'
3
3
import { MarketplaceService } from '../../services/marketplace.service'
4
4
import { MatSnackBar } from '@angular/material/snack-bar'
5
5
import * as _ from 'lodash'
6
6
import { HttpErrorResponse } from '@angular/common/http'
7
7
import { ActivatedRoute } from '@angular/router'
8
- import { JsonEditorOptions } from 'ang-jsoneditor'
8
+ import { JsonEditorComponent , JsonEditorOptions } from 'ang-jsoneditor'
9
9
10
10
@Component ( {
11
11
selector : 'ws-app-via-api' ,
@@ -14,6 +14,7 @@ import { JsonEditorOptions } from 'ang-jsoneditor'
14
14
} )
15
15
export class ViaApiComponent implements OnInit , OnChanges {
16
16
//#region (global varialbles)
17
+ @ViewChild ( 'jsonEditor' ) jsonEditor : JsonEditorComponent | undefined
17
18
//#region (view chaild, input and output)
18
19
@Input ( ) providerDetails ?: any
19
20
@Input ( ) viaApiTabIndex = 0
@@ -460,28 +461,34 @@ export class ViaApiComponent implements OnInit, OnChanges {
460
461
this . providerDetails [ 'data' ] [ 'isActive' ] = true
461
462
const hasTransformationAlready = this . providerDetails [ this . transformationType ] ? true : false
462
463
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
+ } )
482
485
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'
485
492
this . showSnackBar ( message )
486
493
}
487
494
}
0 commit comments