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;
48 defaultValue : boolean;
51 showSpinner : boolean;
52 showDialog1 : boolean;
54 validateResponseString : string;
55 showVerifySpinner : 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();
80 this._formFieldsService.getListOfFormFields()
81 .subscribe((responseFormFields) => {
83 // for(let k=0; k<responseFormFields.length; k++)
85 // this.formFieldsListObj.push(responseFormFields[k]);
86 for(let m=0; m<responseFormFields.length; m++)
88 // if(responseFormFields[m]["orderSeq"] == k+1)
90 responseFormFields[m]["orderSeq"] = m+1;
91 this.formFieldsListObj.push(responseFormFields[m]);
96 this._formFieldsService.getFormFieldGroupsData(this.reportId1)
97 .subscribe((responseGroupsData) => {
98 this.Groups = JSON.parse(responseGroupsData["formFieldGroupsJSON"]);
108 if(n == this.formFieldsListObj.length-1)
131 moveUpward( n : number)
133 this.showSpinner = true;
135 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n]["id"])
136 .subscribe((responseGetFormFieldn) => {
137 this.postMoveUpwrdObj = responseGetFormFieldn;
139 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n-1]["id"])
140 .subscribe((responseGetFormFieldnmin1) => {
141 this.postDownwardObj = responseGetFormFieldnmin1;
143 this.orderSeqOfDown = this.postMoveUpwrdObj["orderSeq"];
144 this.orderSeqOfUp = this.postDownwardObj["orderSeq"];
146 this.postMoveUpwrdObj["orderSeq"] = this.orderSeqOfUp;
147 this.postDownwardObj["orderSeq"] = this.orderSeqOfDown;
149 this._formFieldsService.postFormFieldData(this.postDownwardObj, this.reportId1)
150 .subscribe((responsePostn) => {
151 if(responsePostn["message"])
153 this._formFieldsService.postFormFieldData(this.postMoveUpwrdObj, this.reportId1)
154 .subscribe((responsePostnmin1) => {
155 if(responsePostnmin1["message"])
158 this.formFieldsListObj = [];
159 this._formFieldsService.getListOfFormFields()
160 .subscribe((finalListResponse) => {
161 for(let k=0; k<finalListResponse.length; k++)
163 // this.formFieldsListObj.push(finalListResponse[k]);
164 for(let m=0; m<finalListResponse.length; m++)
166 if(finalListResponse[m]["orderSeq"] == k+1)
168 this.formFieldsListObj.push(finalListResponse[m]);
172 this.showSpinner = false;
187 moveDownward( n : number)
189 this.showSpinner = true;
191 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n]["id"])
192 .subscribe((responseGetFormFieldn) => {
193 this.postMoveUpwrdObj = responseGetFormFieldn;
195 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n+1]["id"])
196 .subscribe((responseGetFormFieldnmin1) => {
197 this.postDownwardObj = responseGetFormFieldnmin1;
199 this.orderSeqOfDown = this.postMoveUpwrdObj["orderSeq"];
200 this.orderSeqOfUp = this.postDownwardObj["orderSeq"];
202 this.postMoveUpwrdObj["orderSeq"] = this.orderSeqOfUp;
203 this.postDownwardObj["orderSeq"] = this.orderSeqOfDown;
205 this._formFieldsService.postFormFieldData(this.postDownwardObj, this.reportId1)
206 .subscribe((responsePostn) => {
207 if(responsePostn["message"])
209 this._formFieldsService.postFormFieldData(this.postMoveUpwrdObj, this.reportId1)
210 .subscribe((responsePostnmin1) => {
211 if(responsePostnmin1["message"])
214 this.formFieldsListObj = [];
215 this._formFieldsService.getListOfFormFields()
216 .subscribe((finalListResponse) => {
217 for(let k=0; k<finalListResponse.length; k++)
219 // this.formFieldsListObj.push(finalListResponse[k]);
220 for(let m=0; m<finalListResponse.length; m++)
222 if(finalListResponse[m]["orderSeq"] == k+1)
224 this.formFieldsListObj.push(finalListResponse[m]);
228 this.showSpinner = false;
243 if(this.sqlAsDefaultValue)
245 this.showDefaultSQLOption = true;
249 this.showDefaultSQLOption = false;
254 setDisplayMode(displayMode : string)
260 this._formFieldsService.getFormFieldData(id)
261 .subscribe((responseFormFieldData) => {
262 this.validationType = responseFormFieldData["validationType"];
264 if(responseFormFieldData["visible"] === true)
266 this.visible = "YES";
273 this.orderSeq = responseFormFieldData["orderSeq"];
274 this.message = responseFormFieldData["message"];
275 this.groupFormField = responseFormFieldData["groupFormField"];
276 this.fieldType = responseFormFieldData["fieldType"];
277 this.fieldSQL = responseFormFieldData["fieldSQL"];
278 this.fieldName = responseFormFieldData["fieldName"];
279 this.fieldId = responseFormFieldData["fieldId"];
280 this.fieldDefaultSQL = responseFormFieldData["fieldDefaultSQL"];
281 this.errorStackTrace = responseFormFieldData["errorStackTrace"];
282 this.errorMessage = responseFormFieldData["errorMessage"];
284 if(this.fieldDefaultSQL !== null)
286 this.defaultValue = true;
290 this.defaultValue = false;
293 if(responseFormFieldData["predefinedValueList"] == null)
295 this.predefinedValueList = [];
299 this.predefinedValueList = responseFormFieldData["predefinedValueList"];
302 this.showDialog = true;
303 this.closable = true;
311 this.showDialog = true;
312 this.closable = true;
313 this.validationType = "";
314 this.visible = "YES";
316 this.groupFormField = false;
321 this.fieldDefaultSQL = "";
322 this.errorStackTrace = "";
323 this.errorMessage = "";
324 this.defaultValue = false;
325 this.predefinedValueList = [];
327 this.showDialog = true;
328 this.closable = true;
335 this.showDialog = !this.showDialog;
336 this.closable = false;
342 this.showDialog1 = !this.showDialog1;
343 this.showVerifySpinner = false;
346 addToList( attrib : string)
348 this.predefinedValueList.push(
356 deleteFromList(attrib : string)
359 for(let k=0; k<this.predefinedValueList.length; k++)
361 if(this.predefinedValueList[k]["id"] == attrib)
363 this.predefinedValueList.splice(k, 1);
371 this.showSpinner = true;
372 this.showDialog = false;
373 this.finalPOSTObj["validationType"] = this.validationType;
375 if(this.visible == "YES")
377 this.finalPOSTObj["visible"] = true;
381 this.finalPOSTObj["visible"] = false;
384 this.finalPOSTObj["orderSeq"] = this.orderSeq;
385 this.finalPOSTObj["message"] = this.message;
386 this.finalPOSTObj["groupFormField"] = this.groupFormField;
387 this.finalPOSTObj["fieldType"] = this.fieldType;
388 this.finalPOSTObj["fieldSQL"] = this.fieldSQL;
389 this.finalPOSTObj["fieldName"] = this.fieldName;
390 this.finalPOSTObj["fieldId"] = this.fieldId;
392 this.finalPOSTObj["errorStackTrace"] = this.errorStackTrace;
393 this.finalPOSTObj["errorMessage"] = this.errorMessage;
394 this.finalPOSTObj["defaultValue"] = this.defaultValue;
396 if( this.defaultValue === false)
398 this.finalPOSTObj["fieldDefaultSQL"] = null;
402 this.finalPOSTObj["fieldDefaultSQL"] = this.fieldDefaultSQL;
405 this.finalPOSTObj["predefinedValueList"] = this.predefinedValueList;
407 if(this.mode == "Edit")
409 this._formFieldsService.postFormFieldData(this.finalPOSTObj, this.reportId1)
410 .subscribe((responsePost) => {
411 if(responsePost["message"])
413 this._formFieldsService.getListOfFormFields()
414 .subscribe((responseFormFields) => {
415 this.formFieldsListObj = [];
417 while(responseFormFields[m])
419 this.formFieldsListObj.push(responseFormFields[m]);
424 this.showSpinner = false;
433 this._formFieldsService.addFormFieldData(this.finalPOSTObj, this.reportId1)
434 .subscribe((responsePost) => {
435 if(responsePost["message"])
437 this._formFieldsService.getListOfFormFields()
438 .subscribe((responseFormFields) => {
439 this.formFieldsListObj = [];
441 while(responseFormFields[m])
443 this.formFieldsListObj.push(responseFormFields[m]);
447 this.showSpinner = false;
457 this.showSpinner = true;
458 this._formFieldsService.deleteFormField(id)
459 .subscribe((responseDeleted) => {
460 if(responseDeleted["message"] == "Formfield Deleted")
462 this._formFieldsService.getListOfFormFields()
463 .subscribe((responseFormFields) => {
464 this.formFieldsListObj = [];
466 while(responseFormFields[m])
468 this.formFieldsListObj.push(responseFormFields[m]);
472 this.showSpinner = false;
479 verify( SQLType : string)
481 this.showVerifySpinner = true;
482 this.showDialog1 = true;
483 if(SQLType == "Default")
486 query : this.fieldDefaultSQL
488 this._formFieldsService.verifySQL(this.queryObj)
489 .subscribe((responseDefaultSQL) => {
490 this.validateResponseString = responseDefaultSQL["data"]["elements"];
491 this.showVerifySpinner = false;
497 query : this.fieldSQL
499 this._formFieldsService.verifySQL(this.queryObj)
500 .subscribe((responseSQL) => {
501 this.validateResponseString = responseSQL["data"]["elements"];
502 this.showVerifySpinner = false;
508 deleteFromGroup(formFieldId : String)
510 for(let k=0; k<this.Groups.length; k++)
512 let element = this.Groups[k];
513 for(let l=0; l<element["formFieldList"].length; l++)
515 if(element["formFieldList"][l]["id"] == formFieldId)
517 this.Groups[k]["formFieldList"].splice(l, 1);
523 deleteGroup(groupName : string)
525 for(let k=0; k<this.Groups.length; k++)
527 if(this.Groups[k]["name"] == groupName)
529 this.Groups.splice(k, 1);
540 const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
543 data: this.formFieldsListObj
546 dialogRef.afterClosed().subscribe(result => {
548 let groupAlreadyExists = false;
549 if(this.Groups == null || this.Groups == undefined)
551 this.Groups = new Array();
553 for(let k=0; k<this.Groups.length; k++)
555 if(this.Groups[k]["name"] == result["name"])
557 groupAlreadyExists = true;
562 if(!groupAlreadyExists)
564 let UpdatedResult = result;
565 for(let i=0; i<result["formFieldList"].length; i++)
567 let formFieldId = result["formFieldList"][i];
569 while(this.formFieldsListObj[j])
571 if(this.formFieldsListObj[j]["id"] == formFieldId)
573 UpdatedResult["formFieldList"][i] = this.formFieldsListObj[j];
579 if(this.Groups !== null || this.Groups!== undefined)
581 this.Groups.push(UpdatedResult);
585 this.Groups = new Array();
586 this.Groups.push(UpdatedResult);
592 this.openSnackBar("Group Already Exists.","Try using another name!");
599 openSnackBar(message: string, action: string) {
600 this._snackBar.open(message, action, {
605 saveFormFieldGroups()
607 let formFieldGroupsPostObj =
609 reportId : this.reportId1,
610 formFieldGroupsJSON : JSON.stringify(this.Groups)
613 this._formFieldsService.postFormFieldGroupsData(formFieldGroupsPostObj)
614 .subscribe((responsePost) => {
615 this.openSnackBar("Successfully Saved!","");
622 selector: 'app-create-group',
623 templateUrl: './create-group.component.html',
625 export class DialogOverviewExampleDialog {
626 createGroupObj : any = {};
628 public dialogRef: MatDialogRef<DialogOverviewExampleDialog>,
629 @Inject(MAT_DIALOG_DATA) public data: DialogData) {
633 this.dialogRef.close();