c0856b44e3aab1b836fd634637c538dc26853f46
[portal/sdk.git] /
1 import {Component, OnInit, Input, SimpleChange, SystemJsNgModuleLoader, OnDestroy} from '@angular/core';
2 import {RunService} from '../run.service';
3 import {ActivatedRoute, Router} from '@angular/router';
4 import {inlineInterpolate} from '@angular/core/src/view';
5 import {copyStyles} from '@angular/animations/browser/src/util';
6 import {split} from 'ts-node';
7 import * as cloneDeep from 'lodash/cloneDeep';
8
9 @Component({
10     selector: 'app-run-report-form-fields',
11     templateUrl: './run-report-form-fields.component.html',
12     styleUrls: ['./run-report-form-fields.component.css']
13 })
14 export class RunReportFormFieldsComponent implements OnInit, OnDestroy {
15     @Input('formFieldList') formFieldList: {}[];
16     @Input('reportId') reportId: string;
17     staticFormFieldList: {}[] = [];
18     formFieldListValueArr: any[];
19     saveFormFieldGroups: any[];
20     finalQueryParamsObj: {};
21     navigateToRun: boolean;
22     reportMode: string;
23     queryString: string;
24     reportName: string;
25     reportSubTitle: string;
26     showSpinner: boolean;
27     showLabel: boolean;
28     runDashboardReport: boolean;
29     DashboardReportObj: {}[] = [];
30     triggerFormFieldArr = [];
31     initialObject = {};
32     formFieldGroupObjList: {}[] = [];
33     toggleFormFieldRenderArr: {}[] = [];
34     groupSelectValue = '';
35     oldGroupSelectValue = '';
36     unCommonCnt = 0;
37     commonCount = 0;
38     totalCommonCount = 0;
39     totalCount = 0;
40     errorMessage = '';
41     stackTrace = '';
42     error = false;
43     iSDashboardReport = '';
44     hitCnt = 0;
45     directCallQueryParams: any = '';
46     calledWithFormFields = false;
47     showformFiledSpinner = false;
48     actualformFieldValues: any[];
49     allowEdit: boolean;
50     runReportAgain: boolean;
51     tempFieldValues = [];
52     firstRun = false;
53     saveFormFieldListValueArr: any[];
54     saveGroupSelectValue = '';
55     avoidDoCheck = false;
56     toolTipPosition = 'right';
57     isResetAllowed: boolean;
58     save: {}[];
59     unCommonGropusList: any[];
60     commonFormFields: any[];
61     formFieldListValueMap: any;
62     saveFormFieldListValueMap: any;
63     chartType = '';
64
65     constructor(private _runService: RunService, private _route: ActivatedRoute, private _router: Router) {
66         this.formFieldListValueArr = [];
67         this.saveFormFieldListValueArr = [];
68         this.saveFormFieldGroups = [];
69         this.finalQueryParamsObj = {};
70         this.navigateToRun = false;
71         this.queryString = '';
72         this.showSpinner = false;
73         this.showLabel = false;
74         this.runDashboardReport = false;
75         this.showformFiledSpinner = false;
76         this.runReportAgain = false;
77         this.tempFieldValues = [];
78         this.isResetAllowed = false;
79         this.unCommonGropusList = [];
80         this.commonFormFields = [];
81         this.formFieldListValueMap = new Map<any, any>();
82         this.saveFormFieldListValueMap = new Map<any, any>();
83         this.chartType = '';
84     }
85
86     ngOnDestroy(): void {
87         this.createNewObject();
88         this.showSpinner = false;
89     }
90
91     createNewObject() {
92         this.staticFormFieldList = [];
93         this.formFieldListValueArr = [];
94         this.saveFormFieldGroups = [];
95         this.saveFormFieldListValueArr = [];
96         this.finalQueryParamsObj = {};
97         this.navigateToRun = false;
98         this.reportMode = '';
99         this.queryString = '';
100         this.reportName = '';
101         this.reportSubTitle='';
102         this.showSpinner = true;
103         this.showLabel = false;
104         this.runDashboardReport = false;
105         this.DashboardReportObj = [];
106         this.triggerFormFieldArr = [];
107         this.initialObject = {};
108         this.formFieldGroupObjList = [];
109         this.toggleFormFieldRenderArr = [];
110         this.groupSelectValue = '';
111         this.oldGroupSelectValue = '';
112         this.unCommonCnt = 0;
113         this.totalCommonCount = 0;
114         this.commonCount = 0;
115         this.totalCount = 0;
116         this.errorMessage = '';
117         this.stackTrace = '';
118         this.error = false;
119         this.iSDashboardReport = '';
120         this.hitCnt = 0;
121         this.directCallQueryParams = '';
122         this.calledWithFormFields = false;
123         this.showformFiledSpinner = false;
124         this.allowEdit = false;
125         this.runReportAgain = false;
126         this.isResetAllowed = false;
127         this.unCommonGropusList = [];
128         this.commonFormFields = [];
129         this.formFieldListValueMap = new Map<any, any>();
130         this.saveFormFieldListValueMap = new Map<any, any>();
131         this.chartType = '';
132     }
133
134     ngOnInit() {
135
136         this.showSpinner = true;
137         this.navigateToRun = false;
138         this._route.params.subscribe(params => {
139             this.reportId = params['reportId'];
140             this.createNewObject();
141             this.groupSelectValue = params['groupSelectValue'];
142             if (this.groupSelectValue === undefined) {
143                 this.groupSelectValue = '';
144             }
145             if (params['queryParameters']) {
146                 this.directCallQueryParams = params['queryParameters'];
147                 this.calledWithFormFields = true;
148                 this.populateQueryParams(params['queryParameters']);
149             }
150             this.loadPage();
151         });
152
153     }
154
155     populateQueryParams(queryParams: any) {
156         this.actualformFieldValues = this.directCallQueryParams.substring(1, this.directCallQueryParams.length).split('&');
157         for (const ff of this.actualformFieldValues) {
158             const formfiledArray = ff.split('=');
159             const formFieldId = formfiledArray[0];
160             const formFieldObj = formfiledArray[1];
161             this.finalQueryParamsObj[formFieldId] = formFieldObj;
162         }
163         this.queryString = this.directCallQueryParams;
164     }
165
166     loadPage() {
167         this._runService.getDefinitionPageDetails(+this.reportId)
168             .subscribe((responseDefPage) => {
169                 this.reportName = responseDefPage['reportName'];
170                 this.reportSubTitle = responseDefPage['reportSubTitle'];
171                 this.chartType = responseDefPage['chartType'];
172                 if (responseDefPage['reportType'] !== 'Dashboard') {
173                     if (this.calledWithFormFields == false) {
174                         this._runService.getReportData(this.reportId)
175                             .subscribe((response) => {
176                                 if (response['errormessage']) {
177                                     this.allowEdit = response['allowEdit'];
178                                     this.showError(response);
179                                 } else {
180                                     this.allowEdit = response['allowEdit'];
181                                     this.reportName = response['reportName'];
182                                     if (response['formFieldList'].length > 0) {
183                                         this.fetchAndPopulateFormFields(response, this.reportId);
184                                         this.showformFiledSpinner = true;
185                                     } else {
186                                         this.formFieldList = response['formFieldList'];
187                                         this.reportMode = 'Regular';
188                                         this.navigateToRun = true;
189                                         this.showformFiledSpinner = false;
190
191                                     }
192                                     this.showSpinner = false;
193                                 }
194                             });
195                     } else if (this.calledWithFormFields == true) {
196                         this._runService.getReportData(this.reportId)
197                             .subscribe((response) => {
198                                 if (response['errormessage']) {
199                                     this.showError(response);
200                                 } else {
201                                     this.error = false;
202                                     this.reportName = response['reportName'];
203                                     this.allowEdit = response['allowEdit'];
204                                     if (response['formFieldList'].length > 0) {
205                                         this.setDefaultFieldGroupValueForNonSelected(response['formFieldList']);
206                                         this.generateQueryString();
207                                         this.fetchAndPopulateFormFields(response, this.reportId);
208                                         this.formFieldListValueMap = new Map<any, any>();
209                                         for (const ff of response['formFieldList']) {
210                                             if (this.finalQueryParamsObj[ff.fieldId]) {
211                                                 if (ff.validationType == 'DATE') {
212                                                     const dateVal = this.finalQueryParamsObj[ff.fieldId];
213                                                     this.formFieldListValueMap.set(ff.fieldId, new Date(dateVal.toString().replace(/%2F/g, '/')));
214                                                 } else if (ff.fieldType == 'LIST_MULTI_SELECT') {
215                                                     const multiSelectArray = [];
216                                                     let multiVal = this.finalQueryParamsObj[ff.fieldId];
217                                                     multiVal = multiVal.toString().replace(/%2F/g, '/');
218                                                     multiVal = multiVal.toString().replace('+', ' ');
219                                                     multiSelectArray.push(multiVal);
220                                                     this.formFieldListValueMap.set(ff.fieldId, multiSelectArray);
221                                                 } else {
222                                                     let multiVal = this.finalQueryParamsObj[ff.fieldId];
223                                                     multiVal = multiVal.toString().replace(/%2F/g, '/');
224                                                     multiVal = multiVal.toString().split('+').join(' ');
225                                                     this.formFieldListValueMap.set(ff.fieldId, multiVal);
226                                                 }
227                                             } else {
228                                                 if (ff.fieldType == 'LIST_MULTI_SELECT') {
229                                                     const multiSelectArray = [];
230                                                     this.formFieldListValueMap.set(ff.fieldId, multiSelectArray);
231                                                 } else {
232                                                     this.formFieldListValueMap.set(ff.fieldId, '');
233                                                 }
234                                             }
235                                         }
236                                         this.error = false;
237                                         this.navigateToRun = true;
238                                         this.showformFiledSpinner = true;
239                                         this.directCallQueryParams = '';
240                                     } else {
241                                         this.reportMode = 'Regular';
242                                         this.navigateToRun = true;
243                                         this.showformFiledSpinner = false;
244
245                                     }
246                                     this.showSpinner = false;
247
248                                 }
249                             });
250                     } else {
251                         this.reportMode = 'FormField';
252                         this.navigateToRun = true;
253                         this.showSpinner = false;
254                         this.showformFiledSpinner = true;
255                     }
256                 } else {
257                     if (this.calledWithFormFields == false) {
258                         this.iSDashboardReport = 'Dashboard';
259                         this.reportName = responseDefPage['reportName'];
260                         this.DashboardReportObj = JSON.parse(responseDefPage['dashboardLayoutJSON']);
261                         let i = 0;
262                         let subReportId = '';
263                         const tempDashboardArray = [];
264                         for (let dash = 0; dash < this.DashboardReportObj.length ; dash++) {
265                             if (this.DashboardReportObj[dash]['hasContent']['hideDisplay'] !== true) {
266                                 tempDashboardArray.push(this.DashboardReportObj[dash]);
267                             }
268                         }
269                         this.DashboardReportObj = [];
270                         this.DashboardReportObj = tempDashboardArray;
271                         while (this.DashboardReportObj[i]) {
272                             subReportId = this.DashboardReportObj[i]['hasContent']['id'].split('#')[1];
273                             i++;
274                             break;
275                         }
276                         this._runService.getReportData(subReportId)
277                             .subscribe((response) => {
278                                 if (response['errormessage']) {
279                                     this.showError(response);
280                                     this.allowEdit = response['allowEdit'];
281                                 } else {
282                                     this.allowEdit = response['allowEdit'];
283                                     if (response['formFieldList'].length > 0) {
284                                         this.fetchAndPopulateFormFields(response, subReportId);
285                                     } else {
286                                         this.navigateToRun = true;
287                                     }
288                                     this.runDashboardReport = true;
289                                     this.showSpinner = false;
290                                     this.showformFiledSpinner = true;
291                                 }
292                             });
293                         this.showSpinner = false;
294                         this.showformFiledSpinner = true;
295                     } else if (this.calledWithFormFields == true) {
296                         this.iSDashboardReport = 'Dashboard';
297                         this.reportName = responseDefPage['reportName'];
298                         this.DashboardReportObj = JSON.parse(responseDefPage['dashboardLayoutJSON']);
299                         const tempDashboardArray = [];
300                         for (let dash = 0; dash < this.DashboardReportObj.length ; dash++) {
301                             if (this.DashboardReportObj[dash]['hasContent']['hideDisplay'] !== true) {
302                                 tempDashboardArray.push(this.DashboardReportObj[dash]);
303                             }
304                         }
305                         this.DashboardReportObj = [];
306                         this.DashboardReportObj = tempDashboardArray;
307                         let subReportId = '';
308                         for (const dashboard of this.DashboardReportObj) {
309                             let temp = '';
310                             temp = dashboard['hasContent']['id'].split('#')[1];
311                             subReportId = temp;
312                             this.directCallQueryParams = '';
313                             this.runDashboardReport = true;
314                             this.navigateToRun = true;
315                             this.showSpinner = false;
316                         }
317                     }
318                 }
319             });
320     }
321
322     toggleChangeWhenCalledWithFromFields(){
323         this.calledWithFormFields = false;
324     }
325
326     async ngDoCheck() {
327
328         if (this.formFieldList !== undefined) {
329
330             if (this.groupSelectValue !== this.oldGroupSelectValue) {
331                 //  this.formFieldListValueArr.splice(this.commonCount-1, this.formFieldListValueArr.length)
332                 this.removePrevioustoggleGroupData();
333                 this.oldGroupSelectValue = this.groupSelectValue;
334                 this.formFieldGroupObjList = [];
335                 this.saveFormFieldGroups = [];
336                 this.formFieldGroupObjList = cloneDeep(this.save);
337                 this.saveFormFieldGroups = cloneDeep(this.save);
338                 for (const formFieldGroupObjItem of this.formFieldGroupObjList) {
339                     if (formFieldGroupObjItem['name'] == this.groupSelectValue) {
340                         this.toggleFormFieldRenderArr = formFieldGroupObjItem['formFieldList'];
341                     }
342
343                 }
344                 if (this.toggleFormFieldRenderArr.length > 0) {
345                     for (let i = 0; i < this.toggleFormFieldRenderArr.length; i++) {
346                         const formFieldObj = this.toggleFormFieldRenderArr[i];
347                         if (formFieldObj['triggerOtherFormFields'] === true) {
348                             const formFieldId = formFieldObj['fieldId'];
349                             this.triggerFormFieldArr.push(formFieldId);
350                             this.initialObject[formFieldId] = '1';
351                             this.finalQueryParamsObj[formFieldId] = '1';
352                         }
353                     }
354                 }
355
356                 if(this.calledWithFormFields != true){
357                     for (const formFieldGroupObjItem of this.saveFormFieldGroups) {
358                         if (formFieldGroupObjItem['name'] == this.groupSelectValue) {
359                             this.toggleFormFieldRenderArr = formFieldGroupObjItem['formFieldList'];
360                             for (let ffGrpValue = 0; ffGrpValue < formFieldGroupObjItem['formFieldList'].length; ffGrpValue++) {
361                                 if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length > 0) {
362                                     for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) {
363                                         if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'LIST_BOX' && formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length > 0) {
364                                             let isAdded = false;
365                                             for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) {
366                                                 if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['defaultValue'] == true) {
367                                                     this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']);
368                                                     isAdded = true;
369                                                 }
370                                             }
371                                             if (!isAdded) {
372                                                 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
373                                             }
374                                         } else if ((formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'LIST_MULTI_SELECT' || formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'TEXT') && formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length > 0) {
375                                             let isAdded = false;
376                                             for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) {
377
378                                                 if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['defaultValue'] == true) {
379                                                     const multiSelectArray = [];
380                                                     multiSelectArray.push(formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']);
381                                                     this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], multiSelectArray);
382                                                     isAdded = true;
383                                                 }
384                                             }
385                                             if (!isAdded) {
386                                                 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
387                                             }
388                                         } else if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'Select Field Type' && formFieldGroupObjItem['formFieldList'][ffGrpValue]['validationType'] == 'NONE') {
389                                             let isAdded = false;
390                                             for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) {
391
392                                                 if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['defaultValue'] == true) {
393                                                     this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']);
394                                                     isAdded = true;
395                                                 }
396                                             }
397                                             if (!isAdded) {
398                                                 this.formFieldListValueArr[this.totalCommonCount + ffGrpValue] = '';
399                                             }
400                                         } else {
401                                             this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
402                                         }
403                                     }
404                                 } else {
405                                     this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
406                                 }
407                             }
408                         }
409                     }
410                 }
411                 if (this.formFieldGroupObjList.length > 0) {
412                     for (let ffl = 0; ffl < this.formFieldList.length; ffl++) {
413                         for (let ffgl = 0; ffgl < this.formFieldGroupObjList.length; ffgl++) {
414                             const inList = this.formFieldGroupObjList[ffgl]['formFieldList'];
415
416                             for (let inl = 0; inl < inList.length; inl++) {
417                                 let cntr = 0;
418                                 if (inList[inl]['fieldId'] == this.formFieldList[ffl]['fieldId']) {
419                                     cntr++;
420                                 }
421                                 if (cntr == 0) {
422                                     this.finalQueryParamsObj[inList[inl]['fieldId']] = '-1';
423                                 }
424                             }
425
426                         }
427                     }
428                 }
429             }
430             for (const tffr of this.toggleFormFieldRenderArr) {
431                 if (this.formFieldListValueMap.get(tffr['fieldId']) || this.formFieldListValueMap.get(tffr['fieldId']) == "") {
432                     if (tffr['validationType'] == 'DATE') {
433                         this.finalQueryParamsObj[tffr['fieldId']] = this.convertDate(this.formFieldListValueMap.get(tffr['fieldId']));
434                     } else if (this.formFieldListValueMap.get(tffr['fieldId']) == "") {
435
436                         if (tffr['fieldType'] == 'LIST_MULTI_SELECT') {
437                             let multiSelectValue = '';
438                             for (let ffValue = 0; ffValue < tffr['formFieldValues'].length; ffValue++) {
439                                 multiSelectValue = multiSelectValue + tffr['formFieldValues'][ffValue]['id'] + '|';
440                             }
441                             if (multiSelectValue != '') {
442                                 multiSelectValue = multiSelectValue.substring(0, multiSelectValue.length - 1);
443                             }
444                             this.finalQueryParamsObj[tffr['fieldId']] = multiSelectValue;
445
446                         } else {
447                             this.finalQueryParamsObj[tffr['fieldId']] = '';
448                         }
449                     } else {
450                         this.finalQueryParamsObj[tffr['fieldId']] = this.formFieldListValueMap.get(tffr['fieldId']);
451                         for (const trigElement of this.triggerFormFieldArr) {
452                             if (this.initialObject[trigElement] !== this.finalQueryParamsObj[trigElement]) {
453                                 this.initialObject[trigElement] = this.finalQueryParamsObj[trigElement];
454                                 this.generateQueryString();
455                                 await this.delay(1000);
456                                 console.log('Afterp:  ' + new Date().toString());
457                                 this._runService.refreshFormFields(this.reportId, this.queryString)
458                                     .subscribe((responseRefreshFF) => {
459                                         for (let rrff = 0; rrff < responseRefreshFF['formFieldList'].length; rrff++) {
460                                             for (let innerTFRR = 0; innerTFRR < this.toggleFormFieldRenderArr.length; innerTFRR++) {
461                                                 if (responseRefreshFF['formFieldList'][rrff]['fieldId'] == this.toggleFormFieldRenderArr[innerTFRR]['fieldId']) {
462                                                     this.toggleFormFieldRenderArr[innerTFRR] = responseRefreshFF['formFieldList'][rrff];
463                                                 }
464                                             }
465                                         }
466                                     });
467                                 this.initialObject[trigElement] = this.finalQueryParamsObj[trigElement];
468                             }
469                         }
470
471                     }
472                 }
473             }
474
475             if (this.reportMode !== 'Regular' && this.reportMode !== 'Dashboard') {
476                 for (const ffvalue of this.formFieldList) {
477                     if (this.formFieldListValueMap.get(ffvalue['fieldId'])) {
478                         if (ffvalue['validationType'] == 'DATE') {
479                             this.finalQueryParamsObj[ffvalue['fieldId']] = this.convertDate(this.formFieldListValueMap.get(ffvalue['fieldId']));
480                         } else {
481                             this.finalQueryParamsObj[ffvalue['fieldId']] = this.formFieldListValueMap.get(ffvalue['fieldId']);
482                             for (const trigElement of this.triggerFormFieldArr) {
483                                 if (this.initialObject[trigElement] !== this.finalQueryParamsObj[trigElement]) {
484                                     this.initialObject[trigElement] = this.finalQueryParamsObj[trigElement];
485                                     this.generateQueryString();
486                                     await this.delay(1000);
487                                     console.log('Afterp:  ' + new Date().toString());
488                                     this._runService.refreshFormFields(this.reportId, this.queryString)
489                                         .subscribe((responseRefreshFF) => {
490
491                                             for (let rrff = 0; rrff < responseRefreshFF['formFieldList'].length; rrff++) {
492                                                 for (let innerFFL = 0; innerFFL < this.formFieldList.length; innerFFL++) {
493                                                     if (responseRefreshFF['formFieldList'][rrff]['fieldId'] == this.formFieldList[innerFFL]['fieldId']) {
494                                                         this.formFieldList[innerFFL] = responseRefreshFF['formFieldList'][rrff];
495                                                     }
496                                                 }
497                                             }
498                                         });
499                                 }
500                             }
501
502                         }
503                     }
504                 }
505
506             }
507         }
508         if (this.firstRun) {
509             this.saveGroupSelectValue = this.groupSelectValue;
510             this.saveFormFieldListValueMap = cloneDeep(this.formFieldListValueMap);
511         }
512         this.firstRun = false;
513     }
514
515     convertDate(str) {
516         const date = new Date(str),
517             mnth = ('0' + (date.getMonth() + 1)).slice(-2),
518             day = ('0' + date.getDate()).slice(-2);
519         return [mnth, day, date.getFullYear()].join('/');
520     }
521
522     getQueryString() {
523         if (this.directCallQueryParams !== '') {
524             return this.directCallQueryParams;
525         } else {
526             return this.queryString;
527         }
528     }
529
530     fetchAndPopulateFormFields(respObj: any, ffReportId: string) {
531         this._runService.getFormFieldGroupsData(ffReportId)
532             .subscribe((responseFormFieldGroups) => {
533                 this.firstRun = true;
534                 this.showformFiledSpinner = false;
535                 this.formFieldGroupObjList = JSON.parse(responseFormFieldGroups['formFieldGroupsJSON']);
536                 this.saveFormFieldGroups = JSON.parse(responseFormFieldGroups['formFieldGroupsJSON']);
537                 this.formFieldList = respObj['formFieldList'];
538                 this.staticFormFieldList = respObj['formFieldList'];
539                 this.reportMode = 'FormField';
540                 this.totalCount = this.formFieldList.length;
541                 if (this.formFieldGroupObjList !== null) {
542                     for (let ffgl = 0; ffgl < this.formFieldGroupObjList.length; ffgl++) {
543                         for (let itemFFGL = 0; itemFFGL < this.formFieldGroupObjList[ffgl]['formFieldList'].length; itemFFGL++) {
544                             const formFieldGroupItem = this.formFieldGroupObjList[ffgl]['formFieldList'][itemFFGL];
545                             for (let fflg = 0; fflg < this.formFieldList.length; fflg++) {
546                                 if (formFieldGroupItem['id'] == this.formFieldList[fflg]['fieldId']) {
547                                     this.formFieldGroupObjList[ffgl]['formFieldList'][itemFFGL] = this.formFieldList[fflg];
548                                     this.saveFormFieldGroups[ffgl]['formFieldList'][itemFFGL] = this.formFieldList[fflg];
549
550                                     if (this.formFieldList[fflg]['triggerOtherFormFields'] === true) {
551                                         const formFieldId = this.formFieldList[fflg]['fieldId'];
552                                         this.triggerFormFieldArr.push(formFieldId);
553                                         this.initialObject[formFieldId] = [];
554                                         this.finalQueryParamsObj[formFieldId] = [];
555                                     }
556                                     this.formFieldList.splice(fflg, 1);
557                                     this.unCommonGropusList.push(formFieldGroupItem);
558                                     this.unCommonCnt++;
559                                 }
560                             }
561                         }
562                     }
563                 }
564                 if(this.calledWithFormFields != true){
565                     for (let checkRadio = 0; checkRadio < this.formFieldList.length; checkRadio++) {
566                         if (this.formFieldList[checkRadio]['fieldDisplayName'] == 'selectCriteria') {
567                             for (let ffValue = 0; ffValue < this.formFieldList[checkRadio]['formFieldValues'].length; ffValue++) {
568                                 if (this.formFieldList[checkRadio]['formFieldValues'][ffValue]['defaultValue'] == true) {
569                                     this.groupSelectValue = this.formFieldList[checkRadio]['formFieldValues'][ffValue]['name'];
570                                 }
571                             }
572                             this.oldGroupSelectValue = this.groupSelectValue;
573                         }
574                     }
575                 }
576                 this.commonCount = this.totalCount - this.unCommonCnt;
577                 this.totalCommonCount = this.commonCount;
578                 console.log(this.unCommonGropusList);
579                 console.log(this.formFieldList);
580                 for (let i = 0; i < this.formFieldList.length; i++) {
581                     const formFieldObj = this.formFieldList[i];
582                     if (formFieldObj['formFieldValues'] != null && this.calledWithFormFields != true) {
583                         if (formFieldObj['validationType'] == 'DATE' && formFieldObj['formFieldValues'].length > 0) {
584                             const date = formFieldObj['formFieldValues'][0]['id'];
585                             this.formFieldListValueMap.set(formFieldObj['fieldId'], new Date(date));
586                         } else if (formFieldObj['fieldType'] == 'LIST_BOX' && formFieldObj['formFieldValues'].length > 0) {
587                             let isAdded = false;
588                             for (let ffValue = 0; ffValue < formFieldObj['formFieldValues'].length; ffValue++) {
589                                 if (formFieldObj['formFieldValues'][ffValue]['defaultValue'] == true) {
590                                     this.formFieldListValueMap.set(formFieldObj['fieldId'], formFieldObj['formFieldValues'][ffValue]['id']);
591                                     isAdded = true;
592                                 }
593                             }
594                             if (!isAdded) {
595                                 this.formFieldListValueMap.set(formFieldObj['fieldId'], '');
596                             }
597                         } else if ((formFieldObj['fieldType'] == 'LIST_MULTI_SELECT' || formFieldObj['fieldType'] == 'TEXT') && formFieldObj['formFieldValues'].length > 0) {
598                             let isAdded = false;
599                             for (let ffValue = 0; ffValue < formFieldObj['formFieldValues'].length; ffValue++) {
600
601                                 if (formFieldObj['formFieldValues'][ffValue]['defaultValue'] == true) {
602                                     const multiSelectArray = [];
603                                     multiSelectArray.push(formFieldObj['formFieldValues'][ffValue]['id']);
604                                     this.formFieldListValueMap.set(formFieldObj['fieldId'], multiSelectArray);
605                                     isAdded = true;
606                                 }
607                             }
608                             if (!isAdded) {
609                                 this.formFieldListValueMap.set(formFieldObj['fieldId'], '');
610                             }
611                         } else if (formFieldObj['fieldDisplayName'] == 'DefaultRadio') {
612                             this.formFieldListValueMap.set(formFieldObj['fieldId'], '');
613
614                         } else {
615                             this.formFieldListValueMap.set(formFieldObj['fieldId'], '');
616                         }
617                     }
618
619                     if (formFieldObj['triggerOtherFormFields'] === true) {
620                         const formFieldId = formFieldObj['fieldId'];
621                         this.triggerFormFieldArr.push(formFieldId);
622                         this.initialObject[formFieldId] = [];
623                         this.finalQueryParamsObj[formFieldId] = [];
624                     }
625                 }
626
627                 console.log(this.formFieldListValueMap);
628
629                 if(this.calledWithFormFields != true){
630                     if (this.formFieldGroupObjList !== null) {
631                         for (const formFieldGroupObjItem of this.formFieldGroupObjList) {
632                             if (formFieldGroupObjItem['name'] == this.groupSelectValue) {
633                                 this.toggleFormFieldRenderArr = formFieldGroupObjItem['formFieldList'];
634                                 for (let ffGrpValue = 0; ffGrpValue < formFieldGroupObjItem['formFieldList'].length; ffGrpValue++) {
635                                     if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length > 0) {
636                                         for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) {
637                                             if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['defaultValue'] == true) {
638                                                 if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'LIST_MULTI_SELECT') {
639                                                     const multiSelectArray = [];
640                                                     multiSelectArray.push(formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']);
641                                                     this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], multiSelectArray);
642                                                 } else {
643                                                     this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']);
644                                                 }
645                                             }
646                                         }
647                                     } else {
648                                         this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
649
650                                     }
651                                 }
652                             }
653
654                         }
655                     }
656                 }
657                 console.log('finalMap', this.formFieldListValueMap);
658                 if (this.formFieldGroupObjList !== null) {
659                     if (this.formFieldGroupObjList.length > 0) {
660                         for (let ffl = 0; ffl < this.formFieldList.length; ffl++) {
661                             for (let ffgl = 0; ffgl < this.formFieldGroupObjList.length; ffgl++) {
662                                 const inList = this.formFieldGroupObjList[ffgl]['formFieldList'];
663
664                                 for (let inl = 0; inl < inList.length; inl++) {
665                                     let cntr = 0;
666                                     if (inList[inl]['fieldId'] == this.formFieldList[ffl]['fieldId']) {
667                                         cntr++;
668                                     }
669                                     if (cntr == 0) {
670                                         this.finalQueryParamsObj[inList[inl]['fieldId']] = '-1';
671                                     }
672                                 }
673
674                             }
675                         }
676                     }
677                 }
678                 this.save = cloneDeep(this.formFieldGroupObjList);
679             });
680     }
681
682     generateQueryString() {
683
684         this.queryString = '';
685         for (let k = 0; k < Object.keys(this.finalQueryParamsObj).length; k++) {
686             if (typeof (this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]]) == 'object') {
687                 const key = Object.keys(this.finalQueryParamsObj)[k];
688                 let qstr = '';
689                 let l = 0;
690                 while (this.finalQueryParamsObj[key][l]) {
691                     if (l === 0) {
692                         qstr = qstr + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]][l];
693                     } else {
694                         qstr = qstr + '|' + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]][l];
695                     }
696                     l++;
697                 }
698                 if (qstr !== '') {
699                     this.queryString = this.queryString + '&' + Object.keys(this.finalQueryParamsObj)[k] + '=' + qstr;
700                 }
701             } else {
702                 if (typeof (this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]]) == 'string') {
703                         this.queryString = this.queryString + '&' + Object.keys(this.finalQueryParamsObj)[k] + '=' + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]];
704                 } else {
705                     this.queryString = this.queryString + '&' + Object.keys(this.finalQueryParamsObj)[k] + '=' + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]];
706                 }
707             }
708
709         }
710
711     }
712
713     showError(Errresponse: any) {
714         this.errorMessage = Errresponse['errormessage'];
715         this.stackTrace = Errresponse['stacktrace'];
716         this.error = true;
717         this.showSpinner = false;
718     }
719
720     runReport() {
721         this.hitCnt++;
722         this.showSpinner = true;
723         if (this.iSDashboardReport !== 'Dashboard') {
724             if (this.formFieldList.length > 0) {
725                 this.reportMode = 'FormField';
726                 this.generateQueryString();
727             } else {
728                 this.reportMode = 'Regular';
729             }
730             this.showSpinner = false;
731         } else {
732             this.generateQueryString();
733             this.showSpinner = false;
734         }
735         this.runReportAgain = !this.runReportAgain;
736         this.navigateToRun = true;
737     }
738
739     editReport(reportId: string) {
740         this._router.navigate(['v2/app/reports', 'Edit', reportId]);
741     }
742
743     showLabelFn() {
744         this.showLabel = !this.showLabel;
745     }
746
747     setDefaultFieldGroupValueForNonSelected(formFieldsList: any) {
748         this.tempFieldValues = [];
749         const map = new Map<string, string>();
750         for (const value in this.finalQueryParamsObj) {
751             map.set(value, this.finalQueryParamsObj[value]);
752         }
753         for (const ffl of formFieldsList) {
754             if (!map.get(ffl['fieldId']) && ffl['formFieldValues'].length === 1) {
755                 this.tempFieldValues = ffl['formFieldValues'];
756                 if (ffl['fieldDisplayName'] == this.tempFieldValues[0]['name']) {
757                     this.finalQueryParamsObj[ffl['fieldId']] = '-1';
758                 }
759             }
760         }
761     }
762
763     resetFormFieldValues() {
764         sessionStorage.clear();
765         const myItem = localStorage.getItem('id');
766         localStorage.clear();
767         localStorage.setItem('id', myItem);
768         if (this.formFieldGroupObjList != null) {
769             this._router.navigateByUrl('v2/app/refresh', {skipLocationChange: true}).then(() =>
770                 this._router.navigate(['v2/app/run', this.reportId]));
771         } else {
772             this.avoidDoCheck = true;
773             this.formFieldListValueMap = new Map<any, any>();
774             this.finalQueryParamsObj = [];
775             if (this.calledWithFormFields == false) {
776                 this.formFieldListValueMap = cloneDeep(this.saveFormFieldListValueMap);
777             }
778
779         }
780     }
781
782     private delay(ms: number) {
783         return new Promise(resolve => setTimeout(resolve, ms));
784     }
785
786     private removePrevioustoggleGroupData() {
787         for (const formFieldGroupObjItem of this.formFieldGroupObjList) {
788             if (formFieldGroupObjItem['name'] == this.oldGroupSelectValue) {
789                 for (let ffGrpValue = 0; ffGrpValue < formFieldGroupObjItem['formFieldList'].length; ffGrpValue++) {
790                     this.finalQueryParamsObj[formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId']] = '-1';
791                     this.formFieldListValueMap.delete(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId']);
792                     this.triggerFormFieldArr= [];
793                 }
794
795             }
796         }
797     }
798 }
799
800