import { Component, OnInit, Input, Inject } from '@angular/core'; import { FormFieldsService } from './form-fields.service'; import { MatDialog, MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { Observable } from 'rxjs'; import { MatSnackBar } from '@angular/material/snack-bar'; export interface DialogData { animal: string; name: string; } @Component({ selector: 'app-form-fields', templateUrl: './form-fields.component.html', styleUrls: ['./form-fields.component.css'] }) export class FormFieldsComponent implements OnInit { @Input("reportId") reportId1 : string; formFieldsListObj : any[]; postMoveUpwrdObj : {}; postDownwardObj : {}; orderSeqOfDown : number; orderSeqOfUp : number; showDialog : boolean; closable : boolean; sqlAsDefaultValue : Boolean; showDefaultSQLOption : boolean; verifyFieldValueAs : number; predefinedValueList : any[]; predefinedValue : string; tabId : string; tabName : string; validationType : string; visible : string; orderSeq : number; message : any; groupFormField : boolean; fieldType : string; fieldSQL : string; fieldName : string; fieldId : string; fieldDefaultSQL : string; errorStackTrace : any; errorMessage : any; defaultValue : any; finalPOSTObj : any; mode : string; showSpinner : boolean; showDialog1 : boolean; queryObj : {}; validateResponseString : string; showVerifySpinner : boolean; Groups : {}[] = []; isDefaultSql : boolean; constructor(private _formFieldsService : FormFieldsService, public dialog: MatDialog, private _snackBar: MatSnackBar) { this.formFieldsListObj = new Array(); this.postMoveUpwrdObj = new Object(); this.postDownwardObj = new Object(); this.showDialog = false; this.showDefaultSQLOption = false; this.closable = true; this.predefinedValueList = new Array(); this.finalPOSTObj = new Object(); this.showSpinner = false; this.showDialog1 = false; this.queryObj = {}; this.showVerifySpinner = false; this.Groups = new Array(); this.isDefaultSql = false; } ngOnInit() { this.showSpinner = true; this._formFieldsService.getListOfFormFields() .subscribe((responseFormFields) => { this.showSpinner = true; for (let m = 0; m < responseFormFields.length; m++) { responseFormFields[m]["orderSeq"] = m + 1; this.formFieldsListObj.push(responseFormFields[m]); } this.showSpinner = false; this._formFieldsService.getFormFieldGroupsData(this.reportId1) .subscribe((responseGroupsData) => { this.showSpinner = true; this.Groups = JSON.parse(responseGroupsData["formFieldGroupsJSON"]); this.showSpinner = false; }); }); } isLast( n : number) { if(n == this.formFieldsListObj.length-1) { return true; } else { return false; } } isFirst( n : number) { if(n == 0) { return true; } else { return false; } } moveUpward( n : number) { this.showSpinner = true; this._formFieldsService.getFormFieldData(this.formFieldsListObj[n]["id"]) .subscribe((responseGetFormFieldn) => { this.postMoveUpwrdObj = responseGetFormFieldn; this._formFieldsService.getFormFieldData(this.formFieldsListObj[n-1]["id"]) .subscribe((responseGetFormFieldnmin1) => { this.postDownwardObj = responseGetFormFieldnmin1; this.orderSeqOfDown = this.postMoveUpwrdObj["orderSeq"]; this.orderSeqOfUp = this.postDownwardObj["orderSeq"]; this.postMoveUpwrdObj["orderSeq"] = this.orderSeqOfUp; this.postDownwardObj["orderSeq"] = this.orderSeqOfDown; console.log(this.postDownwardObj); console.log(this.postMoveUpwrdObj); this.postMoveUpwrdObj["lastUpdatedFieldId"] = this.postDownwardObj["fieldId"]; this.postDownwardObj["lastUpdatedFieldId"] = this.postMoveUpwrdObj["fieldId"]; this._formFieldsService.postFormFieldData(this.postDownwardObj, this.reportId1) .subscribe((responsePostn) => { if(responsePostn["message"]) { this._formFieldsService.postFormFieldData(this.postMoveUpwrdObj, this.reportId1) .subscribe((responsePostnmin1) => { if(responsePostnmin1["message"]) { this.formFieldsListObj = []; this._formFieldsService.getListOfFormFields() .subscribe((finalListResponse) => { for(let k=0; k { this.postMoveUpwrdObj = responseGetFormFieldn; this._formFieldsService.getFormFieldData(this.formFieldsListObj[n+1]["id"]) .subscribe((responseGetFormFieldnmin1) => { this.postDownwardObj = responseGetFormFieldnmin1; this.orderSeqOfDown = this.postMoveUpwrdObj["orderSeq"]; this.orderSeqOfUp = this.postDownwardObj["orderSeq"]; this.postMoveUpwrdObj["orderSeq"] = this.orderSeqOfUp; this.postDownwardObj["orderSeq"] = this.orderSeqOfDown; console.log(this.postDownwardObj); console.log(this.postMoveUpwrdObj); this.postMoveUpwrdObj["lastUpdatedFieldId"] = this.postDownwardObj["fieldId"]; this.postDownwardObj["lastUpdatedFieldId"] = this.postMoveUpwrdObj["fieldId"]; this._formFieldsService.postFormFieldData(this.postDownwardObj, this.reportId1) .subscribe((responsePostn) => { if(responsePostn["message"]) { this._formFieldsService.postFormFieldData(this.postMoveUpwrdObj, this.reportId1) .subscribe((responsePostnmin1) => { if(responsePostnmin1["message"]) { this.formFieldsListObj = []; this._formFieldsService.getListOfFormFields() .subscribe((finalListResponse) => { for(let k=0; k { this.validationType = responseFormFieldData["validationType"]; if(responseFormFieldData["visible"] === true) { this.visible = "YES"; } else { this.visible = "NO"; } this.orderSeq = responseFormFieldData["orderSeq"]; this.message = responseFormFieldData["message"]; this.groupFormField = responseFormFieldData["groupFormField"]; this.fieldType = responseFormFieldData["fieldType"]; this.fieldSQL = responseFormFieldData["fieldSQL"]; this.fieldName = responseFormFieldData["fieldName"]; this.fieldId = responseFormFieldData["fieldId"]; this.fieldDefaultSQL = responseFormFieldData["fieldDefaultSQL"]; this.errorStackTrace = responseFormFieldData["errorStackTrace"]; this.errorMessage = responseFormFieldData["errorMessage"]; this.defaultValue = responseFormFieldData["defaultValue"] ; if(this.fieldDefaultSQL != null || this.fieldDefaultSQL != "") this.isDefaultSql = true; else this.isDefaultSql = false; if(this.defaultValue == null || this.defaultValue == "") this.isDefaultSql = true; else this.isDefaultSql = false; if ((this.fieldDefaultSQL == null || this.fieldDefaultSQL == "") && (this.defaultValue == null || this.defaultValue == "")) this.isDefaultSql = false; if(responseFormFieldData["predefinedValueList"] == null) { this.predefinedValueList = []; } else { this.predefinedValueList = responseFormFieldData["predefinedValueList"]; } this.showDialog = true; this.closable = true; this.mode = "Edit"; }); } add() { this.showDialog = true; this.closable = true; this.validationType = ""; this.visible = "YES"; this.message = ""; this.groupFormField = false; this.fieldType = ""; this.fieldSQL = ""; this.fieldName = ""; this.fieldId = ""; this.fieldDefaultSQL = ""; this.errorStackTrace = ""; this.errorMessage = ""; this.isDefaultSql = false; this.predefinedValueList = []; this.defaultValue=""; this.showDialog = true; this.closable = true; this.mode = "Add"; } close() { this.showDialog = !this.showDialog; this.closable = false; } closeValidateModal() { this.showDialog1 = !this.showDialog1; this.showVerifySpinner = false; } addToList( attrib : string) { this.predefinedValueList.push( { "id" : attrib, "name" : attrib, "selected" : false }); } deleteFromList(attrib : string) { for(let k=0; k { if(responsePost["message"]) { this._formFieldsService.getListOfFormFields() .subscribe((responseFormFields) => { this.formFieldsListObj = []; let m=0; while(responseFormFields[m]) { this.formFieldsListObj.push(responseFormFields[m]); m++; } this.showSpinner = false; }); } }); } else { this._formFieldsService.addFormFieldData(this.finalPOSTObj, this.reportId1) .subscribe((responsePost) => { if(responsePost["message"]) { this._formFieldsService.getListOfFormFields() .subscribe((responseFormFields) => { this.formFieldsListObj = []; let m=0; while(responseFormFields[m]) { this.formFieldsListObj.push(responseFormFields[m]); m++; } this.showSpinner = false; }); } }); } } delete( id : string) { this.showSpinner = true; this._formFieldsService.deleteFormField(id) .subscribe((responseDeleted) => { if(responseDeleted["message"] == "Formfield Deleted") { this._formFieldsService.getListOfFormFields() .subscribe((responseFormFields) => { this.formFieldsListObj = []; let m=0; while(responseFormFields[m]) { this.formFieldsListObj.push(responseFormFields[m]); m++; } this.showSpinner = false; }); } }) } verify( SQLType : string) { this.showVerifySpinner = true; this.showDialog1 = true; if(SQLType == "Default") { this.queryObj = { query : this.fieldDefaultSQL }; this._formFieldsService.verifySQL(this.queryObj) .subscribe((responseDefaultSQL) => { this.validateResponseString = responseDefaultSQL["data"]["elements"]; this.showVerifySpinner = false; }); } else { this.queryObj = { query : this.fieldSQL }; this._formFieldsService.verifySQL(this.queryObj) .subscribe((responseSQL) => { this.validateResponseString = responseSQL["data"]["elements"]; this.showVerifySpinner = false; }); } } deleteFromGroup(formFieldId : String) { for(let k=0; k { let groupAlreadyExists = false; if(this.Groups == null || this.Groups == undefined) { this.Groups = new Array(); } for(let k=0; k { this.openSnackBar("Successfully Saved!",""); }); } } @Component({ selector: 'app-create-group', templateUrl: './create-group.component.html', }) export class DialogOverviewExampleDialog { createGroupObj : any = {}; constructor( public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: DialogData) { } onNoClick() : void { this.dialogRef.close(); } }