Skip to content

Commit 2d9775e

Browse files
Merge pull request #167 from mansurskTarento/cios-via-api
Cios via api
2 parents bab9123 + 191a650 commit 2d9775e

File tree

4 files changed

+49
-29
lines changed

4 files changed

+49
-29
lines changed

project/ws/app/src/lib/routes/home/routes/marketplace-provider/components/transformations/transformations.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@
9292
</form>
9393
</ng-container>
9494
<ng-template #specForm>
95-
<json-editor [options]="editorOptions" [formControl]="transformationSpecForm" class="transformationEditor"
95+
<json-editor #jsonEditor [options]="editorOptions" [formControl]="transformationSpecForm"
96+
class="transformationEditor"
9697
[ngClass]="{'has-error': transformationSpecForm.invalid && transformationSpecForm.touched}">
9798
</json-editor>
9899
</ng-template>

project/ws/app/src/lib/routes/home/routes/marketplace-provider/components/transformations/transformations.component.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ConformationPopupComponent } from '../../dialogs/conformation-popup/con
99
import { HttpErrorResponse } from '@angular/common/http'
1010
import * as XLSX from 'xlsx'
1111
import { environment } from '../../../../../../../../../../../src/environments/environment'
12-
import { JsonEditorOptions } from 'ang-jsoneditor'
12+
import { JsonEditorComponent, JsonEditorOptions } from 'ang-jsoneditor'
1313

1414
@Component({
1515
selector: 'ws-app-transformations',
@@ -21,6 +21,7 @@ export class TransformationsComponent implements OnInit, OnChanges {
2121
//#region (global varialbles)
2222
//#region (view chaild, input and output)
2323
@ViewChild('fileInput', { static: false }) fileInput!: ElementRef<HTMLInputElement>
24+
@ViewChild('jsonEditor') jsonEditor: JsonEditorComponent | undefined
2425

2526
@Input() providerDetails?: any
2627
@Input() transformationType = ''
@@ -203,8 +204,18 @@ export class TransformationsComponent implements OnInit, OnChanges {
203204
const hasTransformationAlready = this.providerDetalsBeforUpdate[this.transformationType] ? true : false
204205
this.transforamtionForm.markAllAsTouched()
205206
this.transformationSpecForm.markAsTouched()
207+
let isValidJson = false
208+
if (this.transforamtionType === 'viaSpec') {
209+
try {
210+
const enteredJson = this.jsonEditor!.get()
211+
isValidJson = JSON.stringify(enteredJson) !== '{}' ? true : false
212+
} catch (err) {
213+
isValidJson = false
214+
}
215+
}
206216
if ((this.transforamtionType === 'viaForm' && this.transforamtionForm.valid) ||
207-
(this.transforamtionType === 'viaSpec' && this.transformationSpecForm.valid && this.transformationSpecForm.value !== '{}')) {
217+
(this.transforamtionType === 'viaSpec' && this.transformationSpecForm.valid &&
218+
JSON.stringify(this.transformationSpecForm.value) !== '{}' && isValidJson)) {
208219
if (this.transformationType !== 'certificateTemplateUrl') {
209220
if (this.transforamtionType === 'viaForm') {
210221
const trasformContentSpec: any = {} // contains maped transform spec for db
@@ -249,7 +260,7 @@ export class TransformationsComponent implements OnInit, OnChanges {
249260
})
250261

251262
} else {
252-
const message = this.transforamtionType === 'viaForm' ? 'Please provide all mandatory fields' : 'Please provide spec json'
263+
const message = this.transforamtionType === 'viaForm' ? 'Please provide all mandatory fields' : 'Please provide valid spec json'
253264
this.showSnackBar(message)
254265
}
255266
}

project/ws/app/src/lib/routes/home/routes/marketplace-provider/components/via-api/via-api.component.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,9 @@
196196
</form>
197197
</ng-container>
198198
<ng-template #specForm>
199-
<json-editor [options]="editorOptions" [formControl]="transformationSpecForm" class="transformationEditor"
200-
[ngClass]="{'has-error': transformationSpecForm.invalid && transformationSpecForm.touched}">
199+
<json-editor #jsonEditor [options]="editorOptions" [formControl]="transformationSpecForm"
200+
class="transformationEditor"
201+
[ngClass]="{'has-error': transformationSpecForm?.invalid && transformationSpecForm?.touched}">
201202
</json-editor>
202203
</ng-template>
203204
<div class="flex w-full justify-end mt-4">

project/ws/app/src/lib/routes/home/routes/marketplace-provider/components/via-api/via-api.component.ts

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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'
22
import { FormArray, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'
33
import { MarketplaceService } from '../../services/marketplace.service'
44
import { MatSnackBar } from '@angular/material/snack-bar'
55
import * as _ from 'lodash'
66
import { HttpErrorResponse } from '@angular/common/http'
77
import { 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
})
1515
export 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

Comments
 (0)