1 import { Component, OnInit, Input, Inject } from '@angular/core';
2 import { FormFieldsService } from './form-fields.service';
3 import { MatDialog, MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
4 import { Observable } from 'rxjs';
5 import { MatSnackBar } from '@angular/material/snack-bar';
8 export interface DialogData {
14 selector: 'app-form-fields',
15 templateUrl: './form-fields.component.html',
16 styleUrls: ['./form-fields.component.css']
18 export class FormFieldsComponent implements OnInit {
20 @Input("reportId") reportId1 : string;
22 formFieldsListObj : any[];
23 postMoveUpwrdObj : {};
25 orderSeqOfDown : number;
26 orderSeqOfUp : number;
29 sqlAsDefaultValue : Boolean;
30 showDefaultSQLOption : boolean;
31 verifyFieldValueAs : number;
32 predefinedValueList : any[];
33 predefinedValue : string;
36 validationType : string;
40 groupFormField : boolean;
45 fieldDefaultSQL : string;
46 errorStackTrace : any;
51 showSpinner : boolean;
52 showDialog1 : boolean;
54 validateResponseString : string;
55 showVerifySpinner : boolean;
57 isDefaultSql : boolean;
61 constructor(private _formFieldsService : FormFieldsService, public dialog: MatDialog, private _snackBar: MatSnackBar) {
62 this.formFieldsListObj = new Array();
63 this.postMoveUpwrdObj = new Object();
64 this.postDownwardObj = new Object();
65 this.showDialog = false;
66 this.showDefaultSQLOption = false;
68 this.predefinedValueList = new Array();
69 this.finalPOSTObj = new Object();
70 this.showSpinner = false;
71 this.showDialog1 = false;
73 this.showVerifySpinner = false;
74 this.Groups = new Array();
75 this.isDefaultSql = false;
79 this.showSpinner = true;
80 this._formFieldsService.getListOfFormFields()
81 .subscribe((responseFormFields) => {
82 this.showSpinner = true;
83 for (let m = 0; m < responseFormFields.length; m++) {
84 responseFormFields[m]["orderSeq"] = m + 1;
85 this.formFieldsListObj.push(responseFormFields[m]);
87 this.showSpinner = false;
88 this._formFieldsService.getFormFieldGroupsData(this.reportId1)
89 .subscribe((responseGroupsData) => {
90 this.showSpinner = true;
91 this.Groups = JSON.parse(responseGroupsData["formFieldGroupsJSON"]);
92 this.showSpinner = false;
100 if(n == this.formFieldsListObj.length-1)
123 moveUpward( n : number)
125 this.showSpinner = true;
127 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n]["id"])
128 .subscribe((responseGetFormFieldn) => {
129 this.postMoveUpwrdObj = responseGetFormFieldn;
131 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n-1]["id"])
132 .subscribe((responseGetFormFieldnmin1) => {
133 this.postDownwardObj = responseGetFormFieldnmin1;
135 this.orderSeqOfDown = this.postMoveUpwrdObj["orderSeq"];
136 this.orderSeqOfUp = this.postDownwardObj["orderSeq"];
138 this.postMoveUpwrdObj["orderSeq"] = this.orderSeqOfUp;
139 this.postDownwardObj["orderSeq"] = this.orderSeqOfDown;
141 console.log(this.postDownwardObj);
142 console.log(this.postMoveUpwrdObj);
143 this.postMoveUpwrdObj["lastUpdatedFieldId"] = this.postDownwardObj["fieldId"];
144 this.postDownwardObj["lastUpdatedFieldId"] = this.postMoveUpwrdObj["fieldId"];
146 this._formFieldsService.postFormFieldData(this.postDownwardObj, this.reportId1)
147 .subscribe((responsePostn) => {
148 if(responsePostn["message"])
150 this._formFieldsService.postFormFieldData(this.postMoveUpwrdObj, this.reportId1)
151 .subscribe((responsePostnmin1) => {
152 if(responsePostnmin1["message"])
155 this.formFieldsListObj = [];
156 this._formFieldsService.getListOfFormFields()
157 .subscribe((finalListResponse) => {
158 for(let k=0; k<finalListResponse.length; k++)
160 // this.formFieldsListObj.push(finalListResponse[k]);
161 for(let m=0; m<finalListResponse.length; m++)
163 if(finalListResponse[m]["orderSeq"] == k+1)
165 this.formFieldsListObj.push(finalListResponse[m]);
169 this.showSpinner = false;
184 moveDownward( n : number)
186 this.showSpinner = true;
188 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n]["id"])
189 .subscribe((responseGetFormFieldn) => {
190 this.postMoveUpwrdObj = responseGetFormFieldn;
192 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n+1]["id"])
193 .subscribe((responseGetFormFieldnmin1) => {
194 this.postDownwardObj = responseGetFormFieldnmin1;
196 this.orderSeqOfDown = this.postMoveUpwrdObj["orderSeq"];
197 this.orderSeqOfUp = this.postDownwardObj["orderSeq"];
199 this.postMoveUpwrdObj["orderSeq"] = this.orderSeqOfUp;
200 this.postDownwardObj["orderSeq"] = this.orderSeqOfDown;
202 console.log(this.postDownwardObj);
203 console.log(this.postMoveUpwrdObj);
205 this.postMoveUpwrdObj["lastUpdatedFieldId"] = this.postDownwardObj["fieldId"];
206 this.postDownwardObj["lastUpdatedFieldId"] = this.postMoveUpwrdObj["fieldId"];
208 this._formFieldsService.postFormFieldData(this.postDownwardObj, this.reportId1)
209 .subscribe((responsePostn) => {
210 if(responsePostn["message"])
212 this._formFieldsService.postFormFieldData(this.postMoveUpwrdObj, this.reportId1)
213 .subscribe((responsePostnmin1) => {
214 if(responsePostnmin1["message"])
217 this.formFieldsListObj = [];
218 this._formFieldsService.getListOfFormFields()
219 .subscribe((finalListResponse) => {
220 for(let k=0; k<finalListResponse.length; k++)
222 // this.formFieldsListObj.push(finalListResponse[k]);
223 for(let m=0; m<finalListResponse.length; m++)
225 if(finalListResponse[m]["orderSeq"] == k+1)
227 this.formFieldsListObj.push(finalListResponse[m]);
231 this.showSpinner = false;
246 if(this.sqlAsDefaultValue)
248 this.showDefaultSQLOption = true;
252 this.showDefaultSQLOption = false;
257 setDisplayMode(displayMode : string)
263 this._formFieldsService.getFormFieldData(id)
264 .subscribe((responseFormFieldData) => {
265 this.validationType = responseFormFieldData["validationType"];
267 if(responseFormFieldData["visible"] === true)
269 this.visible = "YES";
276 this.orderSeq = responseFormFieldData["orderSeq"];
277 this.message = responseFormFieldData["message"];
278 this.groupFormField = responseFormFieldData["groupFormField"];
279 this.fieldType = responseFormFieldData["fieldType"];
280 this.fieldSQL = responseFormFieldData["fieldSQL"];
281 this.fieldName = responseFormFieldData["fieldName"];
282 this.fieldId = responseFormFieldData["fieldId"];
283 this.fieldDefaultSQL = responseFormFieldData["fieldDefaultSQL"];
284 this.errorStackTrace = responseFormFieldData["errorStackTrace"];
285 this.errorMessage = responseFormFieldData["errorMessage"];
286 this.defaultValue = responseFormFieldData["defaultValue"] ;
287 if(this.fieldDefaultSQL != null || this.fieldDefaultSQL != "")
288 this.isDefaultSql = true;
290 this.isDefaultSql = false;
292 if(this.defaultValue == null || this.defaultValue == "")
293 this.isDefaultSql = true;
295 this.isDefaultSql = false;
297 if ((this.fieldDefaultSQL == null || this.fieldDefaultSQL == "") && (this.defaultValue == null || this.defaultValue == ""))
298 this.isDefaultSql = false;
300 if(responseFormFieldData["predefinedValueList"] == null)
302 this.predefinedValueList = [];
306 this.predefinedValueList = responseFormFieldData["predefinedValueList"];
309 this.showDialog = true;
310 this.closable = true;
318 this.showDialog = true;
319 this.closable = true;
320 this.validationType = "";
321 this.visible = "YES";
323 this.groupFormField = false;
328 this.fieldDefaultSQL = "";
329 this.errorStackTrace = "";
330 this.errorMessage = "";
331 this.isDefaultSql = false;
332 this.predefinedValueList = [];
333 this.defaultValue="";
335 this.showDialog = true;
336 this.closable = true;
343 this.showDialog = !this.showDialog;
344 this.closable = false;
350 this.showDialog1 = !this.showDialog1;
351 this.showVerifySpinner = false;
354 addToList( attrib : string)
356 this.predefinedValueList.push(
364 deleteFromList(attrib : string)
367 for(let k=0; k<this.predefinedValueList.length; k++)
369 if(this.predefinedValueList[k]["id"] == attrib)
371 this.predefinedValueList.splice(k, 1);
379 this.showSpinner = true;
380 this.showDialog = false;
381 this.finalPOSTObj["validationType"] = this.validationType;
383 if(this.visible == "YES")
385 this.finalPOSTObj["visible"] = true;
389 this.finalPOSTObj["visible"] = false;
392 this.finalPOSTObj["orderSeq"] = this.orderSeq;
393 this.finalPOSTObj["message"] = this.message;
394 this.finalPOSTObj["groupFormField"] = this.groupFormField;
395 this.finalPOSTObj["fieldType"] = this.fieldType;
396 this.finalPOSTObj["fieldSQL"] = this.fieldSQL;
397 this.finalPOSTObj["fieldName"] = this.fieldName;
398 this.finalPOSTObj["fieldId"] = this.fieldId;
400 this.finalPOSTObj["errorStackTrace"] = this.errorStackTrace;
401 this.finalPOSTObj["errorMessage"] = this.errorMessage;
402 this.finalPOSTObj["lastUpdatedFieldId"] = this.fieldId;
404 this.finalPOSTObj["fieldDefaultSQL"] = this.fieldDefaultSQL;
406 this.finalPOSTObj["defaultValue"] = this.defaultValue;
408 if(this.fieldDefaultSQL != "" && this.fieldDefaultSQL != null)
410 this.finalPOSTObj["defaultValue"] = "";
413 this.finalPOSTObj["predefinedValueList"] = this.predefinedValueList;
415 if(this.mode == "Edit")
417 this._formFieldsService.postFormFieldData(this.finalPOSTObj, this.reportId1)
418 .subscribe((responsePost) => {
419 if(responsePost["message"])
421 this._formFieldsService.getListOfFormFields()
422 .subscribe((responseFormFields) => {
423 this.formFieldsListObj = [];
425 while(responseFormFields[m])
427 this.formFieldsListObj.push(responseFormFields[m]);
432 this.showSpinner = false;
441 this._formFieldsService.addFormFieldData(this.finalPOSTObj, this.reportId1)
442 .subscribe((responsePost) => {
443 if(responsePost["message"])
445 this._formFieldsService.getListOfFormFields()
446 .subscribe((responseFormFields) => {
447 this.formFieldsListObj = [];
449 while(responseFormFields[m])
451 this.formFieldsListObj.push(responseFormFields[m]);
455 this.showSpinner = false;
465 this.showSpinner = true;
466 this._formFieldsService.deleteFormField(id)
467 .subscribe((responseDeleted) => {
468 if(responseDeleted["message"] == "Formfield Deleted")
470 this._formFieldsService.getListOfFormFields()
471 .subscribe((responseFormFields) => {
472 this.formFieldsListObj = [];
474 while(responseFormFields[m])
476 this.formFieldsListObj.push(responseFormFields[m]);
480 this.showSpinner = false;
487 verify( SQLType : string)
489 this.showVerifySpinner = true;
490 this.showDialog1 = true;
491 if(SQLType == "Default")
494 query : this.fieldDefaultSQL
496 this._formFieldsService.verifySQL(this.queryObj)
497 .subscribe((responseDefaultSQL) => {
498 this.validateResponseString = responseDefaultSQL["data"]["elements"];
499 this.showVerifySpinner = false;
505 query : this.fieldSQL
507 this._formFieldsService.verifySQL(this.queryObj)
508 .subscribe((responseSQL) => {
509 this.validateResponseString = responseSQL["data"]["elements"];
510 this.showVerifySpinner = false;
516 deleteFromGroup(formFieldId : String)
518 for(let k=0; k<this.Groups.length; k++)
520 let element = this.Groups[k];
521 for(let l=0; l<element["formFieldList"].length; l++)
523 if(element["formFieldList"][l]["id"] == formFieldId)
525 this.Groups[k]["formFieldList"].splice(l, 1);
531 deleteGroup(groupName : string)
533 for(let k=0; k<this.Groups.length; k++)
535 if(this.Groups[k]["name"] == groupName)
537 this.Groups.splice(k, 1);
548 const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
551 data: this.formFieldsListObj
554 dialogRef.afterClosed().subscribe(result => {
556 let groupAlreadyExists = false;
557 if(this.Groups == null || this.Groups == undefined)
559 this.Groups = new Array();
561 for(let k=0; k<this.Groups.length; k++)
563 if(this.Groups[k]["name"] == result["name"])
565 groupAlreadyExists = true;
570 if(!groupAlreadyExists)
572 let UpdatedResult = result;
573 for(let i=0; i<result["formFieldList"].length; i++)
575 let formFieldId = result["formFieldList"][i];
577 while(this.formFieldsListObj[j])
579 if(this.formFieldsListObj[j]["id"] == formFieldId)
581 UpdatedResult["formFieldList"][i] = this.formFieldsListObj[j];
587 if(this.Groups !== null || this.Groups!== undefined)
589 this.Groups.push(UpdatedResult);
593 this.Groups = new Array();
594 this.Groups.push(UpdatedResult);
600 this.openSnackBar("Group Already Exists.","Try using another name!");
607 openSnackBar(message: string, action: string) {
608 this._snackBar.open(message, action, {
613 saveFormFieldGroups()
615 let formFieldGroupsPostObj =
617 reportId : this.reportId1,
618 formFieldGroupsJSON : JSON.stringify(this.Groups)
621 this._formFieldsService.postFormFieldGroupsData(formFieldGroupsPostObj)
622 .subscribe((responsePost) => {
623 this.openSnackBar("Successfully Saved!","");
630 selector: 'app-create-group',
631 templateUrl: './create-group.component.html',
633 export class DialogOverviewExampleDialog {
634 createGroupObj : any = {};
636 public dialogRef: MatDialogRef<DialogOverviewExampleDialog>,
637 @Inject(MAT_DIALOG_DATA) public data: DialogData) {
641 this.dialogRef.close();