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 {
13 selector: 'app-form-fields',
14 templateUrl: './form-fields.component.html',
15 styleUrls: ['./form-fields.component.css']
17 export class FormFieldsComponent implements OnInit {
19 @Input('reportId') reportId1: string;
21 formFieldsListObj: any[];
24 orderSeqOfDown: number;
28 sqlAsDefaultValue: Boolean;
29 showDefaultSQLOption: boolean;
30 verifyFieldValueAs: number;
31 predefinedValueList: any[];
32 predefinedValue: string;
35 validationType: string;
39 groupFormField: boolean;
44 fieldDefaultSQL: string;
53 validateResponseString: string;
54 showVerifySpinner: boolean;
56 isDefaultSql: boolean;
57 showConfirmButton: boolean;
60 constructor(private _formFieldsService: FormFieldsService, public dialog: MatDialog, private _snackBar: MatSnackBar) {
61 this.formFieldsListObj = [];
62 this.postMoveUpwrdObj = {};
63 this.postDownwardObj = {};
64 this.showDialog = false;
65 this.showDefaultSQLOption = false;
67 this.predefinedValueList = [];
68 this.finalPOSTObj = {};
69 this.showSpinner = false;
70 this.showDialog1 = false;
72 this.showVerifySpinner = false;
74 this.isDefaultSql = false;
78 this._formFieldsService.getListOfFormFields()
79 .subscribe((responseFormFields) => {
80 for (let m = 0; m < responseFormFields.length; m++) {
81 responseFormFields[m]['orderSeq'] = m + 1;
82 this.formFieldsListObj.push(responseFormFields[m]);
85 this._formFieldsService.getFormFieldGroupsData(this.reportId1)
86 .subscribe((responseGroupsData) => {
87 this.Groups = JSON.parse(responseGroupsData['formFieldGroupsJSON']);
94 if (n == this.formFieldsListObj.length - 1) {
110 moveUpward(n: number) {
111 this.showSpinner = true;
113 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n]['id'])
114 .subscribe((responseGetFormFieldn) => {
115 this.postMoveUpwrdObj = responseGetFormFieldn;
117 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n - 1]['id'])
118 .subscribe((responseGetFormFieldnmin1) => {
119 this.postDownwardObj = responseGetFormFieldnmin1;
121 this.orderSeqOfDown = this.postMoveUpwrdObj['orderSeq'];
122 this.orderSeqOfUp = this.postDownwardObj['orderSeq'];
124 this.postMoveUpwrdObj['orderSeq'] = this.orderSeqOfUp;
125 this.postDownwardObj['orderSeq'] = this.orderSeqOfDown;
127 console.log(this.postDownwardObj);
128 console.log(this.postMoveUpwrdObj);
129 this.postMoveUpwrdObj['lastUpdatedFieldId'] = this.postDownwardObj['fieldId'];
130 this.postDownwardObj['lastUpdatedFieldId'] = this.postMoveUpwrdObj['fieldId'];
132 this._formFieldsService.postFormFieldData(this.postDownwardObj, this.reportId1)
133 .subscribe((responsePostn) => {
134 if (responsePostn['message']) {
135 this._formFieldsService.postFormFieldData(this.postMoveUpwrdObj, this.reportId1)
136 .subscribe((responsePostnmin1) => {
137 if (responsePostnmin1['message']) {
139 this.formFieldsListObj = [];
140 this._formFieldsService.getListOfFormFields()
141 .subscribe((finalListResponse) => {
142 for (let k = 0; k < finalListResponse.length; k++) {
143 // this.formFieldsListObj.push(finalListResponse[k]);
144 for (let m = 0; m < finalListResponse.length; m++) {
145 if (finalListResponse[m]['orderSeq'] == k + 1) {
146 this.formFieldsListObj.push(finalListResponse[m]);
150 this.showSpinner = false;
163 moveDownward(n: number) {
164 this.showSpinner = true;
166 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n]['id'])
167 .subscribe((responseGetFormFieldn) => {
168 this.postMoveUpwrdObj = responseGetFormFieldn;
170 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n + 1]['id'])
171 .subscribe((responseGetFormFieldnmin1) => {
172 this.postDownwardObj = responseGetFormFieldnmin1;
174 this.orderSeqOfDown = this.postMoveUpwrdObj['orderSeq'];
175 this.orderSeqOfUp = this.postDownwardObj['orderSeq'];
177 this.postMoveUpwrdObj['orderSeq'] = this.orderSeqOfUp;
178 this.postDownwardObj['orderSeq'] = this.orderSeqOfDown;
180 console.log(this.postDownwardObj);
181 console.log(this.postMoveUpwrdObj);
183 this.postMoveUpwrdObj['lastUpdatedFieldId'] = this.postDownwardObj['fieldId'];
184 this.postDownwardObj['lastUpdatedFieldId'] = this.postMoveUpwrdObj['fieldId'];
186 this._formFieldsService.postFormFieldData(this.postDownwardObj, this.reportId1)
187 .subscribe((responsePostn) => {
188 if (responsePostn['message']) {
189 this._formFieldsService.postFormFieldData(this.postMoveUpwrdObj, this.reportId1)
190 .subscribe((responsePostnmin1) => {
191 if (responsePostnmin1['message']) {
193 this.formFieldsListObj = [];
194 this._formFieldsService.getListOfFormFields()
195 .subscribe((finalListResponse) => {
196 for (let k = 0; k < finalListResponse.length; k++) {
197 // this.formFieldsListObj.push(finalListResponse[k]);
198 for (let m = 0; m < finalListResponse.length; m++) {
199 if (finalListResponse[m]['orderSeq'] == k + 1) {
200 this.formFieldsListObj.push(finalListResponse[m]);
204 this.showSpinner = false;
218 if (this.sqlAsDefaultValue) {
219 this.showDefaultSQLOption = true;
221 this.showDefaultSQLOption = false;
226 setDisplayMode(displayMode: string) {
229 editGroup(group: any) {
230 this.openEditDialog(group);
234 this._formFieldsService.getFormFieldData(id)
235 .subscribe((responseFormFieldData) => {
236 this.validationType = responseFormFieldData['validationType'];
238 if (responseFormFieldData['visible'] === true) {
239 this.visible = 'YES';
244 this.orderSeq = responseFormFieldData['orderSeq'];
245 this.message = responseFormFieldData['message'];
246 this.groupFormField = responseFormFieldData['groupFormField'];
247 this.fieldType = responseFormFieldData['fieldType'];
248 this.fieldSQL = responseFormFieldData['fieldSQL'];
249 this.fieldName = responseFormFieldData['fieldName'];
250 this.fieldId = responseFormFieldData['fieldId'];
251 this.fieldDefaultSQL = responseFormFieldData['fieldDefaultSQL'];
252 this.errorStackTrace = responseFormFieldData['errorStackTrace'];
253 this.errorMessage = responseFormFieldData['errorMessage'];
254 this.defaultValue = responseFormFieldData['defaultValue'];
255 if (this.fieldDefaultSQL != null || this.fieldDefaultSQL != '') {
256 this.isDefaultSql = true;
258 this.isDefaultSql = false;
261 if (this.defaultValue == null || this.defaultValue == '') {
262 this.isDefaultSql = true;
264 this.isDefaultSql = false;
267 if ((this.fieldDefaultSQL == null || this.fieldDefaultSQL == '') && (this.defaultValue == null || this.defaultValue == '')) {
268 this.isDefaultSql = false;
271 if (responseFormFieldData['predefinedValueList'] == null) {
272 this.predefinedValueList = [];
274 this.predefinedValueList = responseFormFieldData['predefinedValueList'];
277 this.showDialog = true;
278 this.closable = true;
285 this.showDialog = true;
286 this.closable = true;
287 this.validationType = '';
288 this.visible = 'YES';
290 this.groupFormField = false;
295 this.fieldDefaultSQL = '';
296 this.errorStackTrace = '';
297 this.errorMessage = '';
298 this.isDefaultSql = false;
299 this.predefinedValueList = [];
300 this.defaultValue = '';
302 this.showDialog = true;
303 this.closable = true;
310 this.showDialog = !this.showDialog;
311 this.closable = false;
315 closeValidateModal() {
316 this.showDialog1 = !this.showDialog1;
317 this.showVerifySpinner = false;
320 addToList(attrib: string) {
321 this.predefinedValueList.push(
329 deleteFromList(attrib: string) {
331 for (let k = 0; k < this.predefinedValueList.length; k++) {
332 if (this.predefinedValueList[k]['id'] == attrib) {
333 this.predefinedValueList.splice(k, 1);
340 this.showSpinner = true;
341 this.showDialog = false;
342 this.finalPOSTObj['validationType'] = this.validationType;
344 if (this.visible == 'YES') {
345 this.finalPOSTObj['visible'] = true;
347 this.finalPOSTObj['visible'] = false;
350 this.finalPOSTObj['orderSeq'] = this.orderSeq;
351 this.finalPOSTObj['message'] = this.message;
352 this.finalPOSTObj['groupFormField'] = this.groupFormField;
353 this.finalPOSTObj['fieldType'] = this.fieldType;
354 this.finalPOSTObj['fieldSQL'] = this.fieldSQL;
355 this.finalPOSTObj['fieldName'] = this.fieldName;
356 this.finalPOSTObj['fieldId'] = this.fieldId;
358 this.finalPOSTObj['errorStackTrace'] = this.errorStackTrace;
359 this.finalPOSTObj['errorMessage'] = this.errorMessage;
360 this.finalPOSTObj['lastUpdatedFieldId'] = this.fieldId;
362 this.finalPOSTObj['fieldDefaultSQL'] = this.fieldDefaultSQL;
364 this.finalPOSTObj['defaultValue'] = this.defaultValue;
366 if (this.fieldDefaultSQL != '' && this.fieldDefaultSQL != null) {
367 this.finalPOSTObj['defaultValue'] = '';
370 this.finalPOSTObj['predefinedValueList'] = this.predefinedValueList;
372 if (this.mode == 'Edit') {
373 this._formFieldsService.postFormFieldData(this.finalPOSTObj, this.reportId1)
374 .subscribe((responsePost) => {
375 if (responsePost['message']) {
376 this._formFieldsService.getListOfFormFields()
377 .subscribe((responseFormFields) => {
378 this.formFieldsListObj = [];
380 while (responseFormFields[m]) {
381 this.formFieldsListObj.push(responseFormFields[m]);
386 this.showSpinner = false;
393 this._formFieldsService.addFormFieldData(this.finalPOSTObj, this.reportId1)
394 .subscribe((responsePost) => {
395 if (responsePost['message']) {
396 this._formFieldsService.getListOfFormFields()
397 .subscribe((responseFormFields) => {
398 this.formFieldsListObj = [];
400 while (responseFormFields[m]) {
401 this.formFieldsListObj.push(responseFormFields[m]);
405 this.showSpinner = false;
414 this.showSpinner = true;
415 this._formFieldsService.deleteFormField(id)
416 .subscribe((responseDeleted) => {
417 if (responseDeleted['message'] == 'Formfield Deleted') {
418 this._formFieldsService.getListOfFormFields()
419 .subscribe((responseFormFields) => {
420 this.formFieldsListObj = [];
422 while (responseFormFields[m]) {
423 this.formFieldsListObj.push(responseFormFields[m]);
427 this.showSpinner = false;
434 verify(SQLType: string) {
435 this.showVerifySpinner = true;
436 this.showDialog1 = true;
437 if (SQLType == 'Default') {
439 query: this.fieldDefaultSQL
441 this._formFieldsService.verifySQL(this.queryObj)
442 .subscribe((responseDefaultSQL) => {
443 this.validateResponseString = responseDefaultSQL['data']['elements'];
444 this.showVerifySpinner = false;
450 this._formFieldsService.verifySQL(this.queryObj)
451 .subscribe((responseSQL) => {
452 this.validateResponseString = responseSQL['data']['elements'];
453 this.showVerifySpinner = false;
459 deleteFromGroup(formFieldId: String) {
460 for (let k = 0; k < this.Groups.length; k++) {
461 let element = this.Groups[k];
462 for (let l = 0; l < element["formFieldList"].length; l++) {
463 if (element['formFieldList'][l]['id'] == formFieldId) {
464 this.Groups[k]['formFieldList'].splice(l, 1);
470 deleteGroup(groupName: string) {
471 for (let k = 0; k < this.Groups.length; k++) {
472 if (this.Groups[k]['name'] == groupName) {
473 this.Groups.splice(k, 1);
483 const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
486 data: this.formFieldsListObj,
489 dialogRef.afterClosed().subscribe(result => {
491 let groupAlreadyExists = false;
492 if (this.Groups == null || this.Groups == undefined) {
495 for (let k = 0; k < this.Groups.length; k++) {
496 if (this.Groups[k]['name'] == result['name']) {
497 groupAlreadyExists = true;
502 if (!groupAlreadyExists) {
503 let UpdatedResult = result;
504 for (let i = 0; i < result["formFieldList"].length; i++) {
505 let formFieldId = result['formFieldList'][i];
507 while (this.formFieldsListObj[j]) {
508 if (this.formFieldsListObj[j]['id'] == formFieldId) {
509 UpdatedResult['formFieldList'][i] = this.formFieldsListObj[j];
515 if (this.Groups !== null || this.Groups !== undefined) {
516 this.Groups.push(UpdatedResult);
519 this.Groups.push(UpdatedResult);
523 this.openSnackBar('Group Already Exists.', 'Try using another name!');
531 openEditDialog(groupInfo: any) {
532 const multiSelectArray = [];
533 for (let arr = 0; arr < groupInfo['formFieldList'].length; arr++) {
534 multiSelectArray.push(groupInfo['formFieldList'][arr]['id']);
536 let editGroupInfo = {};
537 editGroupInfo['formFieldList'] = multiSelectArray;
538 editGroupInfo['name'] = groupInfo['name'];
539 const dialogRef = this.dialog.open(EditGroupDialog, {
543 formFieldsListObj: this.formFieldsListObj,
544 editGroupInfo: editGroupInfo
548 dialogRef.afterClosed().subscribe(result => {
549 for (let k = 0; k < this.Groups.length; k++) {
550 if (this.Groups[k]['name'] == editGroupInfo['name']) {
551 let UpdatedResult = editGroupInfo;
552 for (let i = 0; i < editGroupInfo["formFieldList"].length; i++) {
553 let formFieldId = editGroupInfo['formFieldList'][i];
555 while (this.formFieldsListObj[j]) {
556 if (this.formFieldsListObj[j]['id'] == formFieldId) {
557 UpdatedResult['formFieldList'][i] = this.formFieldsListObj[j];
564 this.Groups[k]['formFieldList'] = UpdatedResult['formFieldList'];
571 openSnackBar(message: string, action: string) {
572 this._snackBar.open(message, action, {
577 saveFormFieldGroups() {
578 let formFieldGroupsPostObj =
580 reportId: this.reportId1,
581 formFieldGroupsJSON: JSON.stringify(this.Groups)
584 this._formFieldsService.postFormFieldGroupsData(formFieldGroupsPostObj)
585 .subscribe((responsePost) => {
586 this.openSnackBar('Successfully Saved!', '');
593 selector: 'app-create-group',
594 templateUrl: './create-group.component.html',
596 export class DialogOverviewExampleDialog {
597 createGroupObj: any = {};
600 public dialogRef: MatDialogRef<DialogOverviewExampleDialog>,
601 @Inject(MAT_DIALOG_DATA) public data: DialogData) {
605 this.dialogRef.close();
612 selector: 'app-edit-group',
613 templateUrl: './edit-group.component.html',
615 export class EditGroupDialog {
616 @Input('mode') mode: string;
617 editGroupInfo: any = {};
620 public dialogRef: MatDialogRef<EditGroupDialog>,
621 @Inject(MAT_DIALOG_DATA) public data: DialogData) {
625 this.dialogRef.close();