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