Skip to content

Commit

Permalink
Merge pull request #167 from mansurskTarento/cios-via-api
Browse files Browse the repository at this point in the history
Cios via api
  • Loading branch information
vishnubansaltarento authored Jan 20, 2025
2 parents bab9123 + 191a650 commit 2d9775e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
</form>
</ng-container>
<ng-template #specForm>
<json-editor [options]="editorOptions" [formControl]="transformationSpecForm" class="transformationEditor"
<json-editor #jsonEditor [options]="editorOptions" [formControl]="transformationSpecForm"
class="transformationEditor"
[ngClass]="{'has-error': transformationSpecForm.invalid && transformationSpecForm.touched}">
</json-editor>
</ng-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ConformationPopupComponent } from '../../dialogs/conformation-popup/con
import { HttpErrorResponse } from '@angular/common/http'
import * as XLSX from 'xlsx'
import { environment } from '../../../../../../../../../../../src/environments/environment'
import { JsonEditorOptions } from 'ang-jsoneditor'
import { JsonEditorComponent, JsonEditorOptions } from 'ang-jsoneditor'

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

@Input() providerDetails?: any
@Input() transformationType = ''
Expand Down Expand Up @@ -203,8 +204,18 @@ export class TransformationsComponent implements OnInit, OnChanges {
const hasTransformationAlready = this.providerDetalsBeforUpdate[this.transformationType] ? true : false
this.transforamtionForm.markAllAsTouched()
this.transformationSpecForm.markAsTouched()
let isValidJson = false
if (this.transforamtionType === 'viaSpec') {
try {
const enteredJson = this.jsonEditor!.get()
isValidJson = JSON.stringify(enteredJson) !== '{}' ? true : false
} catch (err) {
isValidJson = false
}
}
if ((this.transforamtionType === 'viaForm' && this.transforamtionForm.valid) ||
(this.transforamtionType === 'viaSpec' && this.transformationSpecForm.valid && this.transformationSpecForm.value !== '{}')) {
(this.transforamtionType === 'viaSpec' && this.transformationSpecForm.valid &&
JSON.stringify(this.transformationSpecForm.value) !== '{}' && isValidJson)) {
if (this.transformationType !== 'certificateTemplateUrl') {
if (this.transforamtionType === 'viaForm') {
const trasformContentSpec: any = {} // contains maped transform spec for db
Expand Down Expand Up @@ -249,7 +260,7 @@ export class TransformationsComponent implements OnInit, OnChanges {
})

} else {
const message = this.transforamtionType === 'viaForm' ? 'Please provide all mandatory fields' : 'Please provide spec json'
const message = this.transforamtionType === 'viaForm' ? 'Please provide all mandatory fields' : 'Please provide valid spec json'
this.showSnackBar(message)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,9 @@
</form>
</ng-container>
<ng-template #specForm>
<json-editor [options]="editorOptions" [formControl]="transformationSpecForm" class="transformationEditor"
[ngClass]="{'has-error': transformationSpecForm.invalid && transformationSpecForm.touched}">
<json-editor #jsonEditor [options]="editorOptions" [formControl]="transformationSpecForm"
class="transformationEditor"
[ngClass]="{'has-error': transformationSpecForm?.invalid && transformationSpecForm?.touched}">
</json-editor>
</ng-template>
<div class="flex w-full justify-end mt-4">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core'
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core'
import { FormArray, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'
import { MarketplaceService } from '../../services/marketplace.service'
import { MatSnackBar } from '@angular/material/snack-bar'
import * as _ from 'lodash'
import { HttpErrorResponse } from '@angular/common/http'
import { ActivatedRoute } from '@angular/router'
import { JsonEditorOptions } from 'ang-jsoneditor'
import { JsonEditorComponent, JsonEditorOptions } from 'ang-jsoneditor'

@Component({
selector: 'ws-app-via-api',
Expand All @@ -14,6 +14,7 @@ import { JsonEditorOptions } from 'ang-jsoneditor'
})
export class ViaApiComponent implements OnInit, OnChanges {
//#region (global varialbles)
@ViewChild('jsonEditor') jsonEditor: JsonEditorComponent | undefined
//#region (view chaild, input and output)
@Input() providerDetails?: any
@Input() viaApiTabIndex = 0
Expand Down Expand Up @@ -460,28 +461,34 @@ export class ViaApiComponent implements OnInit, OnChanges {
this.providerDetails['data']['isActive'] = true
const hasTransformationAlready = this.providerDetails[this.transformationType] ? true : false
this.transformationSpecForm.markAsTouched()
if (this.transformationSpecForm.valid) {
this.providerDetails[this.transformationType] = this.transformationSpecForm.value
this.marketPlaceSvc.updateProvider(this.providerDetails).subscribe({
next: (responce: any) => {
if (responce) {
setTimeout(() => {
let successMsg = 'Saved Successfully'
successMsg = hasTransformationAlready ? 'Transform Content updated successfully.' : 'Transform Content saved successfully.'
this.showSnackBar(successMsg)
this.transformationsUpdated = true
this.loadProviderDetails.emit(true)
}, 1000)
}
},
error: (error: HttpErrorResponse) => {
const errmsg = _.get(error, 'error.params.errMsg', 'Something went worng, please try again later')
this.showSnackBar(errmsg)
},
})
try {
this.jsonEditor!.get()
if (this.transformationSpecForm.valid && JSON.stringify(this.transformationSpecForm.value) !== '{}') {
this.providerDetails[this.transformationType] = this.transformationSpecForm.value
this.marketPlaceSvc.updateProvider(this.providerDetails).subscribe({
next: (responce: any) => {
if (responce) {
setTimeout(() => {
let successMsg = 'Saved Successfully'
successMsg = hasTransformationAlready ? 'Transform Content updated successfully.' : 'Transform Content saved successfully.'
this.showSnackBar(successMsg)
this.transformationsUpdated = true
this.loadProviderDetails.emit(true)
}, 1000)
}
},
error: (error: HttpErrorResponse) => {
const errmsg = _.get(error, 'error.params.errMsg', 'Something went worng, please try again later')
this.showSnackBar(errmsg)
},
})

} else {
const message = this.transforamtionType === 'viaForm' ? 'Please provide all mandatory fields' : 'Please provide spec json'
} else {
const message = this.transforamtionType === 'viaForm' ? 'Please provide all mandatory fields' : 'Please provide valid spec json'
this.showSnackBar(message)
}
} catch (err) {
const message = 'Please provied valid spec json'
this.showSnackBar(message)
}
}
Expand Down

0 comments on commit 2d9775e

Please sign in to comment.