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';
10 selector: 'app-run-report-form-fields',
11 templateUrl: './run-report-form-fields.component.html',
12 styleUrls: ['./run-report-form-fields.component.css']
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;
25 reportSubTitle: string;
28 runDashboardReport: boolean;
29 DashboardReportObj: {}[] = [];
30 triggerFormFieldArr = [];
32 formFieldGroupObjList: {}[] = [];
33 toggleFormFieldRenderArr: {}[] = [];
34 groupSelectValue = '';
35 oldGroupSelectValue = '';
43 iSDashboardReport = '';
45 directCallQueryParams: any = '';
46 calledWithFormFields = false;
47 showformFiledSpinner = false;
48 actualformFieldValues: any[];
50 runReportAgain: boolean;
53 saveFormFieldListValueArr: any[];
54 saveGroupSelectValue = '';
56 toolTipPosition = 'right';
57 isResetAllowed: boolean;
59 unCommonGropusList: any[];
60 commonFormFields: any[];
61 formFieldListValueMap: any;
62 saveFormFieldListValueMap: any;
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>();
87 this.createNewObject();
88 this.showSpinner = false;
92 this.staticFormFieldList = [];
93 this.formFieldListValueArr = [];
94 this.saveFormFieldGroups = [];
95 this.saveFormFieldListValueArr = [];
96 this.finalQueryParamsObj = {};
97 this.navigateToRun = false;
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;
116 this.errorMessage = '';
117 this.stackTrace = '';
119 this.iSDashboardReport = '';
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>();
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 = '';
145 if (params['queryParameters']) {
146 this.directCallQueryParams = params['queryParameters'];
147 this.calledWithFormFields = true;
148 this.populateQueryParams(params['queryParameters']);
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;
163 this.queryString = this.directCallQueryParams;
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);
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;
186 this.formFieldList = response['formFieldList'];
187 this.reportMode = 'Regular';
188 this.navigateToRun = true;
189 this.showformFiledSpinner = false;
192 this.showSpinner = false;
195 } else if (this.calledWithFormFields == true) {
196 this._runService.getReportData(this.reportId)
197 .subscribe((response) => {
198 if (response['errormessage']) {
199 this.showError(response);
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);
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);
228 if (ff.fieldType == 'LIST_MULTI_SELECT') {
229 const multiSelectArray = [];
230 this.formFieldListValueMap.set(ff.fieldId, multiSelectArray);
232 this.formFieldListValueMap.set(ff.fieldId, '');
237 this.navigateToRun = true;
238 this.showformFiledSpinner = true;
239 this.directCallQueryParams = '';
241 this.reportMode = 'Regular';
242 this.navigateToRun = true;
243 this.showformFiledSpinner = false;
246 this.showSpinner = false;
251 this.reportMode = 'FormField';
252 this.navigateToRun = true;
253 this.showSpinner = false;
254 this.showformFiledSpinner = true;
257 if (this.calledWithFormFields == false) {
258 this.iSDashboardReport = 'Dashboard';
259 this.reportName = responseDefPage['reportName'];
260 this.DashboardReportObj = JSON.parse(responseDefPage['dashboardLayoutJSON']);
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]);
269 this.DashboardReportObj = [];
270 this.DashboardReportObj = tempDashboardArray;
271 while (this.DashboardReportObj[i]) {
272 subReportId = this.DashboardReportObj[i]['hasContent']['id'].split('#')[1];
276 this._runService.getReportData(subReportId)
277 .subscribe((response) => {
278 if (response['errormessage']) {
279 this.showError(response);
280 this.allowEdit = response['allowEdit'];
282 this.allowEdit = response['allowEdit'];
283 if (response['formFieldList'].length > 0) {
284 this.fetchAndPopulateFormFields(response, subReportId);
286 this.navigateToRun = true;
288 this.runDashboardReport = true;
289 this.showSpinner = false;
290 this.showformFiledSpinner = true;
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]);
305 this.DashboardReportObj = [];
306 this.DashboardReportObj = tempDashboardArray;
307 let subReportId = '';
308 for (const dashboard of this.DashboardReportObj) {
310 temp = dashboard['hasContent']['id'].split('#')[1];
312 this.directCallQueryParams = '';
313 this.runDashboardReport = true;
314 this.navigateToRun = true;
315 this.showSpinner = false;
322 toggleChangeWhenCalledWithFromFields(){
323 this.calledWithFormFields = false;
328 if (this.formFieldList !== undefined) {
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'];
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';
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) {
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']);
372 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
374 } else if ((formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'LIST_MULTI_SELECT' || formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'TEXT') && formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length > 0) {
376 for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) {
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);
386 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
388 } else if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'Select Field Type' && formFieldGroupObjItem['formFieldList'][ffGrpValue]['validationType'] == 'NONE') {
390 for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) {
392 if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['defaultValue'] == true) {
393 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']);
398 this.formFieldListValueArr[this.totalCommonCount + ffGrpValue] = '';
401 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
405 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
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'];
416 for (let inl = 0; inl < inList.length; inl++) {
418 if (inList[inl]['fieldId'] == this.formFieldList[ffl]['fieldId']) {
422 this.finalQueryParamsObj[inList[inl]['fieldId']] = '-1';
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']) == "") {
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'] + '|';
441 if (multiSelectValue != '') {
442 multiSelectValue = multiSelectValue.substring(0, multiSelectValue.length - 1);
444 this.finalQueryParamsObj[tffr['fieldId']] = multiSelectValue;
447 this.finalQueryParamsObj[tffr['fieldId']] = '';
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];
467 this.initialObject[trigElement] = this.finalQueryParamsObj[trigElement];
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']));
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) => {
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];
509 this.saveGroupSelectValue = this.groupSelectValue;
510 this.saveFormFieldListValueMap = cloneDeep(this.formFieldListValueMap);
512 this.firstRun = false;
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('/');
523 if (this.directCallQueryParams !== '') {
524 return this.directCallQueryParams;
526 return this.queryString;
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];
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] = [];
556 this.formFieldList.splice(fflg, 1);
557 this.unCommonGropusList.push(formFieldGroupItem);
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'];
572 this.oldGroupSelectValue = this.groupSelectValue;
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) {
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']);
595 this.formFieldListValueMap.set(formFieldObj['fieldId'], '');
597 } else if ((formFieldObj['fieldType'] == 'LIST_MULTI_SELECT' || formFieldObj['fieldType'] == 'TEXT') && formFieldObj['formFieldValues'].length > 0) {
599 for (let ffValue = 0; ffValue < formFieldObj['formFieldValues'].length; ffValue++) {
601 if (formFieldObj['formFieldValues'][ffValue]['defaultValue'] == true) {
602 const multiSelectArray = [];
603 multiSelectArray.push(formFieldObj['formFieldValues'][ffValue]['id']);
604 this.formFieldListValueMap.set(formFieldObj['fieldId'], multiSelectArray);
609 this.formFieldListValueMap.set(formFieldObj['fieldId'], '');
611 } else if (formFieldObj['fieldDisplayName'] == 'DefaultRadio') {
612 this.formFieldListValueMap.set(formFieldObj['fieldId'], '');
615 this.formFieldListValueMap.set(formFieldObj['fieldId'], '');
619 if (formFieldObj['triggerOtherFormFields'] === true) {
620 const formFieldId = formFieldObj['fieldId'];
621 this.triggerFormFieldArr.push(formFieldId);
622 this.initialObject[formFieldId] = [];
623 this.finalQueryParamsObj[formFieldId] = [];
627 console.log(this.formFieldListValueMap);
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);
643 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']);
648 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
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'];
664 for (let inl = 0; inl < inList.length; inl++) {
666 if (inList[inl]['fieldId'] == this.formFieldList[ffl]['fieldId']) {
670 this.finalQueryParamsObj[inList[inl]['fieldId']] = '-1';
678 this.save = cloneDeep(this.formFieldGroupObjList);
682 generateQueryString() {
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];
690 while (this.finalQueryParamsObj[key][l]) {
692 qstr = qstr + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]][l];
694 qstr = qstr + '|' + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]][l];
699 this.queryString = this.queryString + '&' + Object.keys(this.finalQueryParamsObj)[k] + '=' + qstr;
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]];
705 this.queryString = this.queryString + '&' + Object.keys(this.finalQueryParamsObj)[k] + '=' + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]];
713 showError(Errresponse: any) {
714 this.errorMessage = Errresponse['errormessage'];
715 this.stackTrace = Errresponse['stacktrace'];
717 this.showSpinner = false;
722 this.showSpinner = true;
723 if (this.iSDashboardReport !== 'Dashboard') {
724 if (this.formFieldList.length > 0) {
725 this.reportMode = 'FormField';
726 this.generateQueryString();
728 this.reportMode = 'Regular';
730 this.showSpinner = false;
732 this.generateQueryString();
733 this.showSpinner = false;
735 this.runReportAgain = !this.runReportAgain;
736 this.navigateToRun = true;
739 editReport(reportId: string) {
740 this._router.navigate(['v2/app/reports', 'Edit', reportId]);
744 this.showLabel = !this.showLabel;
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]);
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';
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]));
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);
782 private delay(ms: number) {
783 return new Promise(resolve => setTimeout(resolve, ms));
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= [];