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;
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>();
85 this.createNewObject();
86 this.showSpinner = false;
90 this.staticFormFieldList = [];
91 this.formFieldListValueArr = [];
92 this.saveFormFieldGroups = [];
93 this.saveFormFieldListValueArr = [];
94 this.finalQueryParamsObj = {};
95 this.navigateToRun = false;
97 this.queryString = '';
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;
114 this.errorMessage = '';
115 this.stackTrace = '';
117 this.iSDashboardReport = '';
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>();
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 = '';
142 if (params['queryParameters']) {
143 this.directCallQueryParams = params['queryParameters'];
144 this.calledWithFormFields = true;
145 this.populateQueryParams(params['queryParameters']);
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;
160 this.queryString = this.directCallQueryParams;
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);
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;
182 this.formFieldList = response['formFieldList'];
183 this.reportMode = 'Regular';
184 this.navigateToRun = true;
185 this.showformFiledSpinner = false;
188 this.showSpinner = false;
191 } else if (this.calledWithFormFields == true) {
192 this._runService.getReportData(this.reportId)
193 .subscribe((response) => {
194 if (response['errormessage']) {
195 this.showError(response);
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);
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);
224 if (ff.fieldType == 'LIST_MULTI_SELECT') {
225 const multiSelectArray = [];
226 this.formFieldListValueMap.set(ff.fieldId, multiSelectArray);
228 this.formFieldListValueMap.set(ff.fieldId, '');
233 this.navigateToRun = true;
234 this.showformFiledSpinner = true;
235 this.directCallQueryParams = '';
237 this.reportMode = 'Regular';
238 this.navigateToRun = true;
239 this.showformFiledSpinner = false;
242 this.showSpinner = false;
247 this.reportMode = 'FormField';
248 this.navigateToRun = true;
249 this.showSpinner = false;
250 this.showformFiledSpinner = true;
253 if (this.calledWithFormFields == false) {
254 this.iSDashboardReport = 'Dashboard';
255 this.reportName = responseDefPage['reportName'];
256 this.DashboardReportObj = JSON.parse(responseDefPage['dashboardLayoutJSON']);
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]);
265 this.DashboardReportObj = [];
266 this.DashboardReportObj = tempDashboardArray;
267 while (this.DashboardReportObj[i]) {
268 subReportId = this.DashboardReportObj[i]['hasContent']['id'].split('#')[1];
272 this._runService.getReportData(subReportId)
273 .subscribe((response) => {
274 if (response['errormessage']) {
275 this.showError(response);
276 this.allowEdit = response['allowEdit'];
278 this.allowEdit = response['allowEdit'];
279 if (response['formFieldList'].length > 0) {
280 this.fetchAndPopulateFormFields(response, subReportId);
282 this.navigateToRun = true;
284 this.runDashboardReport = true;
285 this.showSpinner = false;
286 this.showformFiledSpinner = true;
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]);
301 this.DashboardReportObj = [];
302 this.DashboardReportObj = tempDashboardArray;
303 let subReportId = '';
304 for (const dashboard of this.DashboardReportObj) {
306 temp = dashboard['hasContent']['id'].split('#')[1];
308 this.directCallQueryParams = '';
309 this.runDashboardReport = true;
310 this.navigateToRun = true;
311 this.showSpinner = false;
318 toggleChangeWhenCalledWithFromFields(){
319 this.calledWithFormFields = false;
324 if (this.formFieldList !== undefined) {
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'];
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';
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) {
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']);
368 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
370 } else if ((formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'LIST_MULTI_SELECT' || formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'TEXT') && formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length > 0) {
372 for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) {
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);
382 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
384 } else if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'Select Field Type' && formFieldGroupObjItem['formFieldList'][ffGrpValue]['validationType'] == 'NONE') {
386 for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) {
388 if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['defaultValue'] == true) {
389 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']);
394 this.formFieldListValueArr[this.totalCommonCount + ffGrpValue] = '';
397 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
401 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
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'];
412 for (let inl = 0; inl < inList.length; inl++) {
414 if (inList[inl]['fieldId'] == this.formFieldList[ffl]['fieldId']) {
418 this.finalQueryParamsObj[inList[inl]['fieldId']] = '-1';
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']) == "") {
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'] + '|';
437 if (multiSelectValue != '') {
438 multiSelectValue = multiSelectValue.substring(0, multiSelectValue.length - 1);
440 this.finalQueryParamsObj[tffr['fieldId']] = multiSelectValue;
443 this.finalQueryParamsObj[tffr['fieldId']] = '';
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];
463 this.initialObject[trigElement] = this.finalQueryParamsObj[trigElement];
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']));
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) => {
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];
505 this.saveGroupSelectValue = this.groupSelectValue;
506 this.saveFormFieldListValueMap = cloneDeep(this.formFieldListValueMap);
508 this.firstRun = false;
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('/');
519 if (this.directCallQueryParams !== '') {
520 return this.directCallQueryParams;
522 return this.queryString;
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];
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] = [];
552 this.formFieldList.splice(fflg, 1);
553 this.unCommonGropusList.push(formFieldGroupItem);
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'];
568 this.oldGroupSelectValue = this.groupSelectValue;
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) {
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']);
591 this.formFieldListValueMap.set(formFieldObj['fieldId'], '');
593 } else if ((formFieldObj['fieldType'] == 'LIST_MULTI_SELECT' || formFieldObj['fieldType'] == 'TEXT') && formFieldObj['formFieldValues'].length > 0) {
595 for (let ffValue = 0; ffValue < formFieldObj['formFieldValues'].length; ffValue++) {
597 if (formFieldObj['formFieldValues'][ffValue]['defaultValue'] == true) {
598 const multiSelectArray = [];
599 multiSelectArray.push(formFieldObj['formFieldValues'][ffValue]['id']);
600 this.formFieldListValueMap.set(formFieldObj['fieldId'], multiSelectArray);
605 this.formFieldListValueMap.set(formFieldObj['fieldId'], '');
607 } else if (formFieldObj['fieldDisplayName'] == 'DefaultRadio') {
608 this.formFieldListValueMap.set(formFieldObj['fieldId'], '');
611 this.formFieldListValueMap.set(formFieldObj['fieldId'], '');
615 if (formFieldObj['triggerOtherFormFields'] === true) {
616 const formFieldId = formFieldObj['fieldId'];
617 this.triggerFormFieldArr.push(formFieldId);
618 this.initialObject[formFieldId] = [];
619 this.finalQueryParamsObj[formFieldId] = [];
623 console.log(this.formFieldListValueMap);
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);
639 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']);
644 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
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'];
660 for (let inl = 0; inl < inList.length; inl++) {
662 if (inList[inl]['fieldId'] == this.formFieldList[ffl]['fieldId']) {
666 this.finalQueryParamsObj[inList[inl]['fieldId']] = '-1';
674 this.save = cloneDeep(this.formFieldGroupObjList);
678 generateQueryString() {
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];
686 while (this.finalQueryParamsObj[key][l]) {
688 qstr = qstr + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]][l];
690 qstr = qstr + '|' + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]][l];
695 this.queryString = this.queryString + '&' + Object.keys(this.finalQueryParamsObj)[k] + '=' + qstr;
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]];
701 this.queryString = this.queryString + '&' + Object.keys(this.finalQueryParamsObj)[k] + '=' + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]];
709 showError(Errresponse: any) {
710 this.errorMessage = Errresponse['errormessage'];
711 this.stackTrace = Errresponse['stacktrace'];
713 this.showSpinner = false;
718 this.showSpinner = true;
719 if (this.iSDashboardReport !== 'Dashboard') {
720 if (this.formFieldList.length > 0) {
721 this.reportMode = 'FormField';
722 this.generateQueryString();
724 this.reportMode = 'Regular';
726 this.showSpinner = false;
728 this.generateQueryString();
729 this.showSpinner = false;
731 this.runReportAgain = !this.runReportAgain;
732 this.navigateToRun = true;
735 editReport(reportId: string) {
736 this._router.navigate(['v2/reports', 'Edit', reportId]);
740 this.showLabel = !this.showLabel;
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]);
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';
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]));
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);
778 private delay(ms: number) {
779 return new Promise(resolve => setTimeout(resolve, ms));
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']);