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._formFieldsService.getListOfFormFields()
80 .subscribe((responseFormFields) => {
81 for (let m = 0; m < responseFormFields.length; m++) {
82 responseFormFields[m]["orderSeq"] = m + 1;
83 this.formFieldsListObj.push(responseFormFields[m]);
86 this._formFieldsService.getFormFieldGroupsData(this.reportId1)
87 .subscribe((responseGroupsData) => {
88 this.Groups = JSON.parse(responseGroupsData["formFieldGroupsJSON"]);
96 if(n == this.formFieldsListObj.length-1)
119 moveUpward( n : number)
121 this.showSpinner = true;
123 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n]["id"])
124 .subscribe((responseGetFormFieldn) => {
125 this.postMoveUpwrdObj = responseGetFormFieldn;
127 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n-1]["id"])
128 .subscribe((responseGetFormFieldnmin1) => {
129 this.postDownwardObj = responseGetFormFieldnmin1;
131 this.orderSeqOfDown = this.postMoveUpwrdObj["orderSeq"];
132 this.orderSeqOfUp = this.postDownwardObj["orderSeq"];
134 this.postMoveUpwrdObj["orderSeq"] = this.orderSeqOfUp;
135 this.postDownwardObj["orderSeq"] = this.orderSeqOfDown;
137 console.log(this.postDownwardObj);
138 console.log(this.postMoveUpwrdObj);
139 this.postMoveUpwrdObj["lastUpdatedFieldId"] = this.postDownwardObj["fieldId"];
140 this.postDownwardObj["lastUpdatedFieldId"] = this.postMoveUpwrdObj["fieldId"];
142 this._formFieldsService.postFormFieldData(this.postDownwardObj, this.reportId1)
143 .subscribe((responsePostn) => {
144 if(responsePostn["message"])
146 this._formFieldsService.postFormFieldData(this.postMoveUpwrdObj, this.reportId1)
147 .subscribe((responsePostnmin1) => {
148 if(responsePostnmin1["message"])
151 this.formFieldsListObj = [];
152 this._formFieldsService.getListOfFormFields()
153 .subscribe((finalListResponse) => {
154 for(let k=0; k<finalListResponse.length; k++)
156 // this.formFieldsListObj.push(finalListResponse[k]);
157 for(let m=0; m<finalListResponse.length; m++)
159 if(finalListResponse[m]["orderSeq"] == k+1)
161 this.formFieldsListObj.push(finalListResponse[m]);
165 this.showSpinner = false;
180 moveDownward( n : number)
182 this.showSpinner = true;
184 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n]["id"])
185 .subscribe((responseGetFormFieldn) => {
186 this.postMoveUpwrdObj = responseGetFormFieldn;
188 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n+1]["id"])
189 .subscribe((responseGetFormFieldnmin1) => {
190 this.postDownwardObj = responseGetFormFieldnmin1;
192 this.orderSeqOfDown = this.postMoveUpwrdObj["orderSeq"];
193 this.orderSeqOfUp = this.postDownwardObj["orderSeq"];
195 this.postMoveUpwrdObj["orderSeq"] = this.orderSeqOfUp;
196 this.postDownwardObj["orderSeq"] = this.orderSeqOfDown;
198 console.log(this.postDownwardObj);
199 console.log(this.postMoveUpwrdObj);
201 this.postMoveUpwrdObj["lastUpdatedFieldId"] = this.postDownwardObj["fieldId"];
202 this.postDownwardObj["lastUpdatedFieldId"] = this.postMoveUpwrdObj["fieldId"];
204 this._formFieldsService.postFormFieldData(this.postDownwardObj, this.reportId1)
205 .subscribe((responsePostn) => {
206 if(responsePostn["message"])
208 this._formFieldsService.postFormFieldData(this.postMoveUpwrdObj, this.reportId1)
209 .subscribe((responsePostnmin1) => {
210 if(responsePostnmin1["message"])
213 this.formFieldsListObj = [];
214 this._formFieldsService.getListOfFormFields()
215 .subscribe((finalListResponse) => {
216 for(let k=0; k<finalListResponse.length; k++)
218 // this.formFieldsListObj.push(finalListResponse[k]);
219 for(let m=0; m<finalListResponse.length; m++)
221 if(finalListResponse[m]["orderSeq"] == k+1)
223 this.formFieldsListObj.push(finalListResponse[m]);
227 this.showSpinner = false;
242 if(this.sqlAsDefaultValue)
244 this.showDefaultSQLOption = true;
248 this.showDefaultSQLOption = false;
253 setDisplayMode(displayMode : string)
259 this._formFieldsService.getFormFieldData(id)
260 .subscribe((responseFormFieldData) => {
261 this.validationType = responseFormFieldData["validationType"];
263 if(responseFormFieldData["visible"] === true)
265 this.visible = "YES";
272 this.orderSeq = responseFormFieldData["orderSeq"];
273 this.message = responseFormFieldData["message"];
274 this.groupFormField = responseFormFieldData["groupFormField"];
275 this.fieldType = responseFormFieldData["fieldType"];
276 this.fieldSQL = responseFormFieldData["fieldSQL"];
277 this.fieldName = responseFormFieldData["fieldName"];
278 this.fieldId = responseFormFieldData["fieldId"];
279 this.fieldDefaultSQL = responseFormFieldData["fieldDefaultSQL"];
280 this.errorStackTrace = responseFormFieldData["errorStackTrace"];
281 this.errorMessage = responseFormFieldData["errorMessage"];
282 this.defaultValue = responseFormFieldData["defaultValue"] ;
283 if(this.fieldDefaultSQL != null || this.fieldDefaultSQL != "")
284 this.isDefaultSql = true;
286 this.isDefaultSql = false;
288 if(this.defaultValue == null || this.defaultValue == "")
289 this.isDefaultSql = true;
291 this.isDefaultSql = false;
293 if ((this.fieldDefaultSQL == null || this.fieldDefaultSQL == "") && (this.defaultValue == null || this.defaultValue == ""))
294 this.isDefaultSql = false;
296 if(responseFormFieldData["predefinedValueList"] == null)
298 this.predefinedValueList = [];
302 this.predefinedValueList = responseFormFieldData["predefinedValueList"];
305 this.showDialog = true;
306 this.closable = true;
314 this.showDialog = true;
315 this.closable = true;
316 this.validationType = "";
317 this.visible = "YES";
319 this.groupFormField = false;
324 this.fieldDefaultSQL = "";
325 this.errorStackTrace = "";
326 this.errorMessage = "";
327 this.isDefaultSql = false;
328 this.predefinedValueList = [];
329 this.defaultValue="";
331 this.showDialog = true;
332 this.closable = true;
339 this.showDialog = !this.showDialog;
340 this.closable = false;
346 this.showDialog1 = !this.showDialog1;
347 this.showVerifySpinner = false;
350 addToList( attrib : string)
352 this.predefinedValueList.push(
360 deleteFromList(attrib : string)
363 for(let k=0; k<this.predefinedValueList.length; k++)
365 if(this.predefinedValueList[k]["id"] == attrib)
367 this.predefinedValueList.splice(k, 1);
375 this.showSpinner = true;
376 this.showDialog = false;
377 this.finalPOSTObj["validationType"] = this.validationType;
379 if(this.visible == "YES")
381 this.finalPOSTObj["visible"] = true;
385 this.finalPOSTObj["visible"] = false;
388 this.finalPOSTObj["orderSeq"] = this.orderSeq;
389 this.finalPOSTObj["message"] = this.message;
390 this.finalPOSTObj["groupFormField"] = this.groupFormField;
391 this.finalPOSTObj["fieldType"] = this.fieldType;
392 this.finalPOSTObj["fieldSQL"] = this.fieldSQL;
393 this.finalPOSTObj["fieldName"] = this.fieldName;
394 this.finalPOSTObj["fieldId"] = this.fieldId;
396 this.finalPOSTObj["errorStackTrace"] = this.errorStackTrace;
397 this.finalPOSTObj["errorMessage"] = this.errorMessage;
398 this.finalPOSTObj["lastUpdatedFieldId"] = this.fieldId;
400 this.finalPOSTObj["fieldDefaultSQL"] = this.fieldDefaultSQL;
402 this.finalPOSTObj["defaultValue"] = this.defaultValue;
404 if(this.fieldDefaultSQL != "" && this.fieldDefaultSQL != null)
406 this.finalPOSTObj["defaultValue"] = "";
409 this.finalPOSTObj["predefinedValueList"] = this.predefinedValueList;
411 if(this.mode == "Edit")
413 this._formFieldsService.postFormFieldData(this.finalPOSTObj, this.reportId1)
414 .subscribe((responsePost) => {
415 if(responsePost["message"])
417 this._formFieldsService.getListOfFormFields()
418 .subscribe((responseFormFields) => {
419 this.formFieldsListObj = [];
421 while(responseFormFields[m])
423 this.formFieldsListObj.push(responseFormFields[m]);
428 this.showSpinner = false;
437 this._formFieldsService.addFormFieldData(this.finalPOSTObj, this.reportId1)
438 .subscribe((responsePost) => {
439 if(responsePost["message"])
441 this._formFieldsService.getListOfFormFields()
442 .subscribe((responseFormFields) => {
443 this.formFieldsListObj = [];
445 while(responseFormFields[m])
447 this.formFieldsListObj.push(responseFormFields[m]);
451 this.showSpinner = false;
461 this.showSpinner = true;
462 this._formFieldsService.deleteFormField(id)
463 .subscribe((responseDeleted) => {
464 if(responseDeleted["message"] == "Formfield Deleted")
466 this._formFieldsService.getListOfFormFields()
467 .subscribe((responseFormFields) => {
468 this.formFieldsListObj = [];
470 while(responseFormFields[m])
472 this.formFieldsListObj.push(responseFormFields[m]);
476 this.showSpinner = false;
483 verify( SQLType : string)
485 this.showVerifySpinner = true;
486 this.showDialog1 = true;
487 if(SQLType == "Default")
490 query : this.fieldDefaultSQL
492 this._formFieldsService.verifySQL(this.queryObj)
493 .subscribe((responseDefaultSQL) => {
494 this.validateResponseString = responseDefaultSQL["data"]["elements"];
495 this.showVerifySpinner = false;
501 query : this.fieldSQL
503 this._formFieldsService.verifySQL(this.queryObj)
504 .subscribe((responseSQL) => {
505 this.validateResponseString = responseSQL["data"]["elements"];
506 this.showVerifySpinner = false;
512 deleteFromGroup(formFieldId : String)
514 for(let k=0; k<this.Groups.length; k++)
516 let element = this.Groups[k];
517 for(let l=0; l<element["formFieldList"].length; l++)
519 if(element["formFieldList"][l]["id"] == formFieldId)
521 this.Groups[k]["formFieldList"].splice(l, 1);
527 deleteGroup(groupName : string)
529 for(let k=0; k<this.Groups.length; k++)
531 if(this.Groups[k]["name"] == groupName)
533 this.Groups.splice(k, 1);
544 const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
547 data: this.formFieldsListObj
550 dialogRef.afterClosed().subscribe(result => {
552 let groupAlreadyExists = false;
553 if(this.Groups == null || this.Groups == undefined)
555 this.Groups = new Array();
557 for(let k=0; k<this.Groups.length; k++)
559 if(this.Groups[k]["name"] == result["name"])
561 groupAlreadyExists = true;
566 if(!groupAlreadyExists)
568 let UpdatedResult = result;
569 for(let i=0; i<result["formFieldList"].length; i++)
571 let formFieldId = result["formFieldList"][i];
573 while(this.formFieldsListObj[j])
575 if(this.formFieldsListObj[j]["id"] == formFieldId)
577 UpdatedResult["formFieldList"][i] = this.formFieldsListObj[j];
583 if(this.Groups !== null || this.Groups!== undefined)
585 this.Groups.push(UpdatedResult);
589 this.Groups = new Array();
590 this.Groups.push(UpdatedResult);
596 this.openSnackBar("Group Already Exists.","Try using another name!");
603 openSnackBar(message: string, action: string) {
604 this._snackBar.open(message, action, {
609 saveFormFieldGroups()
611 let formFieldGroupsPostObj =
613 reportId : this.reportId1,
614 formFieldGroupsJSON : JSON.stringify(this.Groups)
617 this._formFieldsService.postFormFieldGroupsData(formFieldGroupsPostObj)
618 .subscribe((responsePost) => {
619 this.openSnackBar("Successfully Saved!","");
626 selector: 'app-create-group',
627 templateUrl: './create-group.component.html',
629 export class DialogOverviewExampleDialog {
630 createGroupObj : any = {};
632 public dialogRef: MatDialogRef<DialogOverviewExampleDialog>,
633 @Inject(MAT_DIALOG_DATA) public data: DialogData) {
637 this.dialogRef.close();