1 import {ChangeDetectorRef, Component, HostListener, OnInit, Input, SimpleChange, SystemJsNgModuleLoader, OnDestroy} from '@angular/core';
2 import {RunService} from '../run.service';
3 import {ActivatedRoute, Router} from '@angular/router';
4 import * as cloneDeep from 'lodash/cloneDeep';
5 import {environment} from 'src/environments/environment';
6 import {HttpCacheService} from '../../../shared/services/cache.service';
9 selector: 'app-run-report-form-fields',
10 templateUrl: './run-report-form-fields.component.html',
11 styleUrls: ['./run-report-form-fields.component.css']
13 export class RunReportFormFieldsComponent implements OnInit, OnDestroy {
14 @Input('formFieldList') formFieldList: {}[];
15 @Input('reportId') reportId: string;
16 staticFormFieldList: {}[] = [];
17 formFieldListValueArr: any[];
18 saveFormFieldGroups: any[];
19 finalQueryParamsObj: {};
20 navigateToRun: boolean;
24 reportSubTitle: string;
27 runDashboardReport: boolean;
28 DashboardReportObj: {}[] = [];
29 triggerFormFieldArr = [];
31 formFieldGroupObjList: {}[] = [];
32 toggleFormFieldRenderArr: {}[] = [];
33 groupSelectValue = '';
34 oldGroupSelectValue = '';
42 iSDashboardReport = '';
44 directCallQueryParams: any = '';
45 calledWithFormFields = false;
46 showformFiledSpinner = false;
47 actualformFieldValues: any[];
49 runReportAgain: boolean;
52 saveFormFieldListValueArr: any[];
53 saveGroupSelectValue = '';
55 toolTipPosition = 'right';
56 isResetAllowed: boolean;
58 unCommonGropusList: any[];
59 commonFormFields: any[];
60 formFieldListValueMap: any;
61 saveFormFieldListValueMap: any;
63 showRunButton = false;
64 showBackButton = false;
65 downloadPrevReport = '';
66 timeStampArray: any[];
68 constructor(private _runService: RunService,
69 private _route: ActivatedRoute,
70 private _router: Router,
71 private changeDetectorRefs: ChangeDetectorRef,
72 private httpCacheService: HttpCacheService) {
73 this.formFieldListValueArr = [];
74 this.saveFormFieldListValueArr = [];
75 this.saveFormFieldGroups = [];
76 this.finalQueryParamsObj = {};
77 this.navigateToRun = false;
78 this.queryString = '';
79 this.showSpinner = false;
80 this.showLabel = false;
81 this.runDashboardReport = false;
82 this.showformFiledSpinner = false;
83 this.runReportAgain = false;
84 this.tempFieldValues = [];
85 this.isResetAllowed = false;
86 this.unCommonGropusList = [];
87 this.commonFormFields = [];
88 this.formFieldListValueMap = new Map<any, any>();
89 this.saveFormFieldListValueMap = new Map<any, any>();
91 this.showRunButton = false;
92 this.showBackButton = false;
93 this.downloadPrevReport = '';
94 this.timeStampArray = [];
99 @HostListener('click') onClick() {
100 this.changeDetectorRefs.detectChanges();
103 ngOnDestroy(): void {
104 this.createNewObject();
105 this.showSpinner = false;
109 this.staticFormFieldList = [];
110 this.formFieldListValueArr = [];
111 this.saveFormFieldGroups = [];
112 this.saveFormFieldListValueArr = [];
113 this.finalQueryParamsObj = {};
114 this.navigateToRun = false;
115 this.reportMode = '';
116 this.queryString = '';
117 this.reportName = '';
118 this.reportSubTitle = '';
119 this.showSpinner = true;
120 this.showLabel = false;
121 this.runDashboardReport = false;
122 this.DashboardReportObj = [];
123 this.triggerFormFieldArr = [];
124 this.initialObject = {};
125 this.formFieldGroupObjList = [];
126 this.toggleFormFieldRenderArr = [];
127 this.groupSelectValue = '';
128 this.oldGroupSelectValue = '';
129 this.unCommonCnt = 0;
130 this.totalCommonCount = 0;
131 this.commonCount = 0;
133 this.errorMessage = '';
134 this.stackTrace = '';
136 this.iSDashboardReport = '';
138 this.directCallQueryParams = '';
139 this.calledWithFormFields = false;
140 this.showformFiledSpinner = false;
141 this.allowEdit = false;
142 this.runReportAgain = false;
143 this.isResetAllowed = false;
144 this.unCommonGropusList = [];
145 this.commonFormFields = [];
146 this.formFieldListValueMap = new Map<any, any>();
147 this.saveFormFieldListValueMap = new Map<any, any>();
149 this.showRunButton = false;
150 this.downloadPrevReport = '';
155 this.showSpinner = true;
156 this.navigateToRun = false;
159 this._route.params.subscribe(params => {
160 this.createNewObject();
161 this.reportId = params['reportId'];
162 const checkOfCache = this.httpCacheService.getPreviousId(this.reportId) || null;
164 this.httpCacheService.clearCache();
166 const backButton = params['showBackButton'];
167 const downloadPrevReport = params['downloadPrevReport'];
168 if (downloadPrevReport && downloadPrevReport === 'true') {
169 this.downloadPrevReport = 'true';
171 if (backButton && backButton === 'true') {
172 this.showBackButton = true;
173 } else if (backButton && backButton === 'false') {
174 this.showBackButton = false;
176 this.showBackButton = false;
178 this.groupSelectValue = params['groupSelectValue'];
179 if (this.groupSelectValue === undefined) {
180 this.groupSelectValue = '';
182 if (params['queryParameters']) {
183 this.directCallQueryParams = params['queryParameters'];
184 this.calledWithFormFields = true;
185 this.populateQueryParams(params['queryParameters']);
192 populateQueryParams(queryParams: any) {
193 this.actualformFieldValues = this.directCallQueryParams.substring(1, this.directCallQueryParams.length).split('&');
194 for (const ff of this.actualformFieldValues) {
195 const formfiledArray = ff.split('=');
196 const formFieldId = formfiledArray[0];
197 const formFieldObj = formfiledArray[1];
198 this.finalQueryParamsObj[formFieldId] = formFieldObj;
200 this.queryString = this.directCallQueryParams;
204 this._runService.getDefinitionPageDetails(+this.reportId)
205 .subscribe((responseDefPage) => {
206 this.reportName = responseDefPage['reportName'];
207 this.reportSubTitle = responseDefPage['reportSubTitle'];
208 this.chartType = responseDefPage['chartType'];
209 if (responseDefPage['reportType'] !== 'Dashboard') {
210 if (this.calledWithFormFields == false) {
211 this._runService.getReportData(this.reportId)
212 .subscribe((response) => {
213 if (response['errormessage']) {
214 this.allowEdit = response['allowEdit'];
215 this.showError(response);
217 this.allowEdit = response['allowEdit'];
218 this.reportName = response['reportName'];
219 if (response['formFieldList'].length > 0) {
220 this.fetchAndPopulateFormFields(response, this.reportId);
221 this.showformFiledSpinner = true;
223 this.formFieldList = response['formFieldList'];
224 this.reportMode = 'Regular';
225 this.httpCacheService.setRouteCache(this.reportId, this.getQueryString());
226 this.httpCacheService.setRouteGroupCache(this.reportId, this.groupSelectValue);
227 this.navigateToRun = true;
228 this.showformFiledSpinner = false;
231 this.showSpinner = false;
234 } else if (this.calledWithFormFields == true) {
235 this._runService.getReportData(this.reportId)
236 .subscribe((response) => {
237 if (response['errormessage']) {
238 this.showError(response);
241 this.reportName = response['reportName'];
242 this.allowEdit = response['allowEdit'];
243 if (response['formFieldList'].length > 0) {
244 this.setDefaultFieldGroupValueForNonSelected(response['formFieldList']);
245 this.generateQueryString();
246 this.fetchAndPopulateFormFields(response, this.reportId);
247 this.formFieldListValueMap = new Map<any, any>();
248 for (const ff of response['formFieldList']) {
249 if (this.finalQueryParamsObj[ff.fieldId]) {
250 if (ff.validationType == 'DATE') {
251 const dateVal = this.finalQueryParamsObj[ff.fieldId];
252 this.formFieldListValueMap.set(ff.fieldId, new Date(dateVal.toString().replace(/%2F/g, '/')));
253 } else if (ff.fieldType == 'LIST_MULTI_SELECT') {
254 const multiSelectArray = [];
255 let multiVal = this.finalQueryParamsObj[ff.fieldId];
256 multiVal = multiVal.toString().replace(/%2F/g, '/');
257 multiVal = multiVal.toString().replace(/%20/g, ' ');
258 multiVal = multiVal.toString().replace(/%28/g, '(');
259 multiVal = multiVal.toString().replace(/%29/g, ')');
260 multiVal = multiVal.toString().replace('+', ' ');
261 if (multiVal.split('|').length > 1) {
262 let tempArray = multiVal.split('|');
263 for (let arr = 0; arr < tempArray.length; arr++) {
264 multiSelectArray.push(tempArray[arr]);
267 multiSelectArray.push(multiVal);
269 this.formFieldListValueMap.set(ff.fieldId, multiSelectArray);
271 let multiVal = this.finalQueryParamsObj[ff.fieldId];
272 multiVal = multiVal.toString().replace(/%2F/g, '/');
273 multiVal = multiVal.toString().replace(/%20/g, ' ');
274 multiVal = multiVal.toString().replace(/%28/g, '(');
275 multiVal = multiVal.toString().replace(/%29/g, ')');
276 multiVal = multiVal.toString().split('+').join(' ');
277 this.formFieldListValueMap.set(ff.fieldId, multiVal);
280 if (ff.fieldType == 'LIST_MULTI_SELECT') {
281 const multiSelectArray = [];
282 this.formFieldListValueMap.set(ff.fieldId, multiSelectArray);
284 this.formFieldListValueMap.set(ff.fieldId, '');
289 this.httpCacheService.setRouteCache(this.reportId, this.getQueryString());
290 this.httpCacheService.setRouteGroupCache(this.reportId, this.groupSelectValue);
291 this.navigateToRun = true;
292 this.showformFiledSpinner = true;
293 this.directCallQueryParams = '';
295 this.reportMode = 'Regular';
296 this.navigateToRun = true;
297 this.showformFiledSpinner = false;
300 this.showSpinner = false;
305 this.reportMode = 'FormField';
306 this.navigateToRun = true;
307 this.showSpinner = false;
308 this.showformFiledSpinner = true;
311 if (this.calledWithFormFields == false) {
312 this.iSDashboardReport = 'Dashboard';
313 this.reportName = responseDefPage['reportName'];
314 this.DashboardReportObj = JSON.parse(responseDefPage['dashboardLayoutJSON']);
316 let subReportId = '';
317 const tempDashboardArray = [];
318 for (let dash = 0; dash < this.DashboardReportObj.length; dash++) {
319 if (this.DashboardReportObj[dash]['hasContent']['hideDisplay'] !== true) {
320 tempDashboardArray.push(this.DashboardReportObj[dash]);
323 this.DashboardReportObj = [];
324 this.DashboardReportObj = tempDashboardArray;
325 while (this.DashboardReportObj[i]) {
326 subReportId = this.DashboardReportObj[i]['hasContent']['id'].split('#')[1];
330 this._runService.getReportData(subReportId)
331 .subscribe((response) => {
332 if (response['errormessage']) {
333 this.showError(response);
334 this.allowEdit = response['allowEdit'];
336 this.allowEdit = response['allowEdit'];
337 if (response['formFieldList'].length > 0) {
338 this.fetchAndPopulateFormFields(response, subReportId);
340 this.navigateToRun = true;
342 this.runDashboardReport = true;
343 this.showSpinner = false;
344 this.showformFiledSpinner = true;
347 this.showSpinner = false;
348 this.showformFiledSpinner = true;
349 } else if (this.calledWithFormFields == true) {
350 this.httpCacheService.setRouteCache(this.reportId, this.getQueryString());
351 this.httpCacheService.setRouteGroupCache(this.reportId, this.groupSelectValue);
352 this.iSDashboardReport = 'Dashboard';
353 this.reportName = responseDefPage['reportName'];
354 this.DashboardReportObj = JSON.parse(responseDefPage['dashboardLayoutJSON']);
355 const tempDashboardArray = [];
356 for (let dash = 0; dash < this.DashboardReportObj.length; dash++) {
357 if (this.DashboardReportObj[dash]['hasContent']['hideDisplay'] !== true) {
358 tempDashboardArray.push(this.DashboardReportObj[dash]);
361 this.DashboardReportObj = [];
362 this.DashboardReportObj = tempDashboardArray;
363 let subReportId1 = '';
365 while (this.DashboardReportObj[i]) {
366 subReportId1 = this.DashboardReportObj[i]['hasContent']['id'].split('#')[1];
370 this._runService.getReportData(subReportId1)
371 .subscribe((response) => {
372 if (response['errormessage']) {
373 this.showError(response);
374 this.allowEdit = response['allowEdit'];
376 this.allowEdit = response['allowEdit'];
377 if (response['formFieldList'].length > 0) {
378 this.fetchAndPopulateFormFields(response, subReportId1);
379 this.formFieldListValueMap = new Map<any, any>();
380 for (const ff of response['formFieldList']) {
381 if (this.finalQueryParamsObj[ff.fieldId]) {
382 if (ff.validationType == 'DATE') {
383 const dateVal = this.finalQueryParamsObj[ff.fieldId];
384 this.formFieldListValueMap.set(ff.fieldId, new Date(dateVal.toString().replace(/%2F/g, '/')));
385 } else if (ff.fieldType == 'LIST_MULTI_SELECT') {
386 const multiSelectArray = [];
387 let multiVal = this.finalQueryParamsObj[ff.fieldId];
388 multiVal = multiVal.toString().replace(/%2F/g, '/');
389 multiVal = multiVal.toString().replace(/%20/g, ' ');
390 multiVal = multiVal.toString().replace(/%28/g, '(');
391 multiVal = multiVal.toString().replace(/%29/g, ')');
392 multiVal = multiVal.toString().replace('+', ' ');
393 if (multiVal.split('|').length > 1) {
394 let tempArray = multiVal.split('|');
395 for (let arr = 0; arr < tempArray.length; arr++) {
396 multiSelectArray.push(tempArray[arr]);
399 multiSelectArray.push(multiVal);
401 this.formFieldListValueMap.set(ff.fieldId, multiSelectArray);
403 let multiVal = this.finalQueryParamsObj[ff.fieldId];
404 multiVal = multiVal.toString().replace(/%2F/g, '/');
405 multiVal = multiVal.toString().replace(/%20/g, ' ');
406 multiVal = multiVal.toString().replace(/%28/g, '(');
407 multiVal = multiVal.toString().replace(/%29/g, ')');
408 multiVal = multiVal.toString().split('+').join(' ');
409 if (multiVal == 'NULL') {
410 this.formFieldListValueMap.set(ff.fieldId, '');
412 this.formFieldListValueMap.set(ff.fieldId, multiVal);
416 if (ff.fieldType == 'LIST_MULTI_SELECT') {
417 const multiSelectArray = [];
418 this.formFieldListValueMap.set(ff.fieldId, multiSelectArray);
420 this.formFieldListValueMap.set(ff.fieldId, '');
425 this.navigateToRun = true;
427 let subReportId = '';
428 for (const dashboard of this.DashboardReportObj) {
430 temp = dashboard['hasContent']['id'].split('#')[1];
432 this.directCallQueryParams = '';
433 this.runDashboardReport = true;
434 this.navigateToRun = true;
435 this.showSpinner = false;
446 toggleChangeWhenCalledWithFromFields() {
447 this.calledWithFormFields = false;
452 if (this.formFieldList !== undefined) {
454 if (this.groupSelectValue !== this.oldGroupSelectValue) {
455 // this.formFieldListValueArr.splice(this.commonCount-1, this.formFieldListValueArr.length)
456 this.removePrevioustoggleGroupData();
457 this.oldGroupSelectValue = this.groupSelectValue;
458 this.formFieldGroupObjList = [];
459 this.saveFormFieldGroups = [];
460 this.formFieldGroupObjList = cloneDeep(this.save);
461 this.saveFormFieldGroups = cloneDeep(this.save);
462 for (const formFieldGroupObjItem of this.formFieldGroupObjList) {
463 if (formFieldGroupObjItem['name'] == this.groupSelectValue) {
464 this.toggleFormFieldRenderArr = formFieldGroupObjItem['formFieldList'];
468 if (this.toggleFormFieldRenderArr.length > 0) {
469 for (let i = 0; i < this.toggleFormFieldRenderArr.length; i++) {
470 const formFieldObj = this.toggleFormFieldRenderArr[i];
471 if (formFieldObj['triggerOtherFormFields'] === true) {
472 const formFieldId = formFieldObj['fieldId'];
473 this.triggerFormFieldArr.push(formFieldId);
474 this.initialObject[formFieldId] = '1';
475 this.finalQueryParamsObj[formFieldId] = '1';
480 if (this.calledWithFormFields != true) {
481 for (const formFieldGroupObjItem of this.saveFormFieldGroups) {
482 if (formFieldGroupObjItem['name'] == this.groupSelectValue) {
483 this.toggleFormFieldRenderArr = formFieldGroupObjItem['formFieldList'];
484 for (let ffGrpValue = 0; ffGrpValue < formFieldGroupObjItem['formFieldList'].length; ffGrpValue++) {
485 if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length > 0) {
486 for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) {
487 if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'LIST_BOX' && formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length > 0) {
489 for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) {
490 if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['defaultValue'] == true) {
491 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']);
496 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
498 } else if ((formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'LIST_MULTI_SELECT' || formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'TEXT') && formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length > 0) {
500 for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) {
502 if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['defaultValue'] == true) {
503 const multiSelectArray = [];
504 multiSelectArray.push(formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']);
505 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], multiSelectArray);
510 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
512 } else if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'Select Field Type' && formFieldGroupObjItem['formFieldList'][ffGrpValue]['validationType'] == 'NONE') {
514 for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) {
516 if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['defaultValue'] == true) {
517 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']);
522 this.formFieldListValueArr[this.totalCommonCount + ffGrpValue] = '';
525 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
529 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
535 if (this.formFieldGroupObjList.length > 0) {
536 for (let ffl = 0; ffl < this.formFieldList.length; ffl++) {
537 for (let ffgl = 0; ffgl < this.formFieldGroupObjList.length; ffgl++) {
538 const inList = this.formFieldGroupObjList[ffgl]['formFieldList'];
540 for (let inl = 0; inl < inList.length; inl++) {
542 if (inList[inl]['fieldId'] == this.formFieldList[ffl]['fieldId']) {
546 this.finalQueryParamsObj[inList[inl]['fieldId']] = '-1';
554 for (const tffr of this.toggleFormFieldRenderArr) {
555 if (this.formFieldListValueMap.get(tffr['fieldId']) || this.formFieldListValueMap.get(tffr['fieldId']) == '') {
556 if (tffr['validationType'] == 'DATE') {
557 this.finalQueryParamsObj[tffr['fieldId']] = this.convertDate(this.formFieldListValueMap.get(tffr['fieldId']));
558 } else if (this.formFieldListValueMap.get(tffr['fieldId']) == '') {
560 if (tffr['fieldType'] == 'LIST_MULTI_SELECT') {
561 let multiSelectValue = '';
562 if (multiSelectValue != '') {
563 multiSelectValue = multiSelectValue.substring(0, multiSelectValue.length - 1);
565 this.finalQueryParamsObj[tffr['fieldId']] = multiSelectValue;
568 this.finalQueryParamsObj[tffr['fieldId']] = '';
571 this.finalQueryParamsObj[tffr['fieldId']] = this.formFieldListValueMap.get(tffr['fieldId']);
572 if (this.initialObject[tffr['fieldId']] !== this.finalQueryParamsObj[tffr['fieldId']]) {
573 this.initialObject[tffr['fieldId']] = this.finalQueryParamsObj[tffr['fieldId']];
574 this.generateQueryString();
575 await this.delay(1000);
576 console.log('Afterp: ' + new Date().toString());
577 if ( tffr['triggerOtherFormFields'] == true) {
578 this._runService.refreshFormFields(this.reportId, this.queryString)
579 .subscribe((responseRefreshFF) => {
580 for (let rrff = 0; rrff < responseRefreshFF['formFieldList'].length; rrff++) {
581 for (let innerTFRR = 0; innerTFRR < this.toggleFormFieldRenderArr.length; innerTFRR++) {
582 if (responseRefreshFF['formFieldList'][rrff]['fieldId'] == this.toggleFormFieldRenderArr[innerTFRR]['fieldId']) {
583 this.toggleFormFieldRenderArr[innerTFRR] = responseRefreshFF['formFieldList'][rrff];
590 this.initialObject[tffr['fieldId']] = this.finalQueryParamsObj[tffr['fieldId']];
596 if (this.reportMode !== 'Regular' && this.reportMode !== 'Dashboard') {
597 for (const ffvalue of this.formFieldList) {
598 if (this.formFieldListValueMap.get(ffvalue['fieldId']) === '' || this.formFieldListValueMap.get(ffvalue['fieldId']) ) {
599 if (ffvalue['validationType'] == 'DATE' && this.formFieldListValueMap.get(ffvalue['fieldId']) !== '' ) {
600 this.finalQueryParamsObj[ffvalue['fieldId']] = this.convertDate(this.formFieldListValueMap.get(ffvalue['fieldId']));
601 }else if (ffvalue['validationType'] == 'TIMESTAMP_SEC' && this.formFieldListValueMap.get(ffvalue['fieldId']) !== ''){
602 if(this.formFieldListValueMap.get(ffvalue['fieldId'])[0] != ''){
603 this.finalQueryParamsObj[ffvalue['fieldId']] = this.convertDate(this.formFieldListValueMap.get(ffvalue['fieldId'])[0]);
605 this.finalQueryParamsObj[ffvalue['fieldId']] = this.formFieldListValueMap.get(ffvalue['fieldId'])[0];
607 this.finalQueryParamsObj[ffvalue['fieldId']+'_Hr'] = this.formFieldListValueMap.get(ffvalue['fieldId'])[1];
608 this.finalQueryParamsObj[ffvalue['fieldId']+'_Min'] = this.formFieldListValueMap.get(ffvalue['fieldId'])[2];
609 this.finalQueryParamsObj[ffvalue['fieldId']+'_Sec'] = this.formFieldListValueMap.get(ffvalue['fieldId'])[3];
610 }else if (ffvalue['validationType'] == 'TIMESTAMP_MIN' && this.formFieldListValueMap.get(ffvalue['fieldId']) !== ''){
611 if(this.formFieldListValueMap.get(ffvalue['fieldId'])[0] != ''){
612 this.finalQueryParamsObj[ffvalue['fieldId']] = this.convertDate(this.formFieldListValueMap.get(ffvalue['fieldId'])[0]);
614 this.finalQueryParamsObj[ffvalue['fieldId']] = this.formFieldListValueMap.get(ffvalue['fieldId'])[0];
616 this.finalQueryParamsObj[ffvalue['fieldId']+'_Hr'] = this.formFieldListValueMap.get(ffvalue['fieldId'])[1];
617 this.finalQueryParamsObj[ffvalue['fieldId']+'_Min'] = this.formFieldListValueMap.get(ffvalue['fieldId'])[2];
618 }else if (ffvalue['validationType'] == 'TIMESTAMP_HOUR' && this.formFieldListValueMap.get(ffvalue['fieldId']) !== ''){
619 if(this.formFieldListValueMap.get(ffvalue['fieldId'])[0] != ''){
620 this.finalQueryParamsObj[ffvalue['fieldId']] = this.convertDate(this.formFieldListValueMap.get(ffvalue['fieldId'])[0]);
622 this.finalQueryParamsObj[ffvalue['fieldId']] = this.formFieldListValueMap.get(ffvalue['fieldId'])[0];
624 this.finalQueryParamsObj[ffvalue['fieldId']+'_Hr'] = this.formFieldListValueMap.get(ffvalue['fieldId'])[1];
627 this.finalQueryParamsObj[ffvalue['fieldId']] = this.formFieldListValueMap.get(ffvalue['fieldId']);
629 for (const trigElement of this.triggerFormFieldArr) {
630 if (this.initialObject[trigElement] !== this.finalQueryParamsObj[trigElement]) {
631 this.initialObject[trigElement] = this.finalQueryParamsObj[trigElement];
632 this.generateQueryString();
633 await this.delay(1000);
634 console.log('Afterp: ' + new Date().toString());
635 if (ffvalue['triggerOtherFormFields'] == true) {
636 this._runService.refreshFormFields(this.reportId, this.queryString)
637 .subscribe((responseRefreshFF) => {
638 for (let rrff = 0; rrff < responseRefreshFF['formFieldList'].length; rrff++) {
639 for (let innerFFL = 0; innerFFL < this.formFieldList.length; innerFFL++) {
640 if (responseRefreshFF['formFieldList'][rrff]['fieldId'] == this.formFieldList[innerFFL]['fieldId']) {
641 this.formFieldList[innerFFL] = responseRefreshFF['formFieldList'][rrff];
657 this.saveGroupSelectValue = this.groupSelectValue;
658 this.saveFormFieldListValueMap = cloneDeep(this.formFieldListValueMap);
660 this.firstRun = false;
664 const date = new Date(str),
665 mnth = ('0' + (date.getMonth() + 1)).slice(-2),
666 day = ('0' + date.getDate()).slice(-2);
667 return [mnth, day, date.getFullYear()].join('/');
671 if (this.directCallQueryParams !== '') {
672 return this.directCallQueryParams;
674 return this.queryString;
678 fetchAndPopulateFormFields(respObj: any, ffReportId: string) {
679 this._runService.getFormFieldGroupsData(ffReportId)
680 .subscribe((responseFormFieldGroups) => {
681 this.firstRun = true;
682 this.showformFiledSpinner = false;
683 this.formFieldGroupObjList = JSON.parse(responseFormFieldGroups['formFieldGroupsJSON']);
684 this.saveFormFieldGroups = JSON.parse(responseFormFieldGroups['formFieldGroupsJSON']);
685 this.formFieldList = respObj['formFieldList'];
686 if (this.formFieldList.length === 1 && this.formFieldList[0]['visible'] === false) {
687 this.showRunButton = false;
688 } else if (this.formFieldList.length > 0) {
689 this.showRunButton = true;
691 this.staticFormFieldList = respObj['formFieldList'];
692 this.reportMode = 'FormField';
693 this.totalCount = this.formFieldList.length;
694 if (this.formFieldGroupObjList !== null) {
695 for (let ffgl = 0; ffgl < this.formFieldGroupObjList.length; ffgl++) {
696 for (let itemFFGL = 0; itemFFGL < this.formFieldGroupObjList[ffgl]['formFieldList'].length; itemFFGL++) {
697 const formFieldGroupItem = this.formFieldGroupObjList[ffgl]['formFieldList'][itemFFGL];
698 for (let fflg = 0; fflg < this.formFieldList.length; fflg++) {
699 if (formFieldGroupItem['id'] == this.formFieldList[fflg]['fieldId']) {
700 this.formFieldGroupObjList[ffgl]['formFieldList'][itemFFGL] = this.formFieldList[fflg];
701 this.saveFormFieldGroups[ffgl]['formFieldList'][itemFFGL] = this.formFieldList[fflg];
703 if (this.formFieldList[fflg]['triggerOtherFormFields'] === true) {
704 const formFieldId = this.formFieldList[fflg]['fieldId'];
705 this.triggerFormFieldArr.push(formFieldId);
706 this.initialObject[formFieldId] = [];
707 this.finalQueryParamsObj[formFieldId] = [];
709 this.formFieldList.splice(fflg, 1);
710 this.unCommonGropusList.push(formFieldGroupItem);
717 if (this.calledWithFormFields != true) {
718 for (let checkRadio = 0; checkRadio < this.formFieldList.length; checkRadio++) {
719 if (this.formFieldList[checkRadio]['fieldDisplayName'] == 'selectCriteria') {
720 for (let ffValue = 0; ffValue < this.formFieldList[checkRadio]['formFieldValues'].length; ffValue++) {
721 if (this.formFieldList[checkRadio]['formFieldValues'][ffValue]['defaultValue'] == true) {
722 this.groupSelectValue = this.formFieldList[checkRadio]['formFieldValues'][ffValue]['name'];
725 this.oldGroupSelectValue = this.groupSelectValue;
729 this.commonCount = this.totalCount - this.unCommonCnt;
730 this.totalCommonCount = this.commonCount;
731 console.log(this.unCommonGropusList);
732 console.log(this.formFieldList);
733 for (let i = 0; i < this.formFieldList.length; i++) {
734 const formFieldObj = this.formFieldList[i];
735 if (formFieldObj['formFieldValues'] != null && this.calledWithFormFields != true) {
736 if ((formFieldObj['validationType'] == 'DATE' && formFieldObj['formFieldValues'].length > 0) || formFieldObj['validationType'] == 'TIMESTAMP_SEC' || formFieldObj['validationType'] == 'TIMESTAMP_MIN' || formFieldObj['validationType'] == 'TIMESTAMP_HOUR') {
737 if (formFieldObj['validationType'] == 'TIMESTAMP_SEC') {
738 const multiSelectArray = [];
740 if (formFieldObj['formFieldValues'].length > 0) {
741 const date = formFieldObj['formFieldValues'][0]['id'];
742 let tempDate = new Date(date);
743 multiSelectArray.push(tempDate);
744 multiSelectArray.push(tempDate.getHours());
745 multiSelectArray.push(tempDate.getMinutes());
746 multiSelectArray.push(tempDate.getSeconds());
747 this.formFieldListValueMap.set(formFieldObj['fieldId'], multiSelectArray);
749 multiSelectArray.push('');
750 multiSelectArray.push('0');
751 multiSelectArray.push('0');
752 multiSelectArray.push('0');
753 this.formFieldListValueMap.set(formFieldObj['fieldId'], multiSelectArray);
756 else if (formFieldObj['validationType'] == 'TIMESTAMP_MIN') {
757 const multiSelectArray = [];
758 if (formFieldObj['formFieldValues'].length > 0) {
759 const date = formFieldObj['formFieldValues'][0]['id'];
760 let tempDate = new Date(date);
761 multiSelectArray.push(tempDate);
762 multiSelectArray.push(tempDate.getHours());
763 multiSelectArray.push(tempDate.getMinutes());
764 this.formFieldListValueMap.set(formFieldObj['fieldId'], multiSelectArray);
766 multiSelectArray.push('');
767 multiSelectArray.push('0');
768 multiSelectArray.push('0');
769 this.formFieldListValueMap.set(formFieldObj['fieldId'], multiSelectArray);
771 } else if (formFieldObj['validationType'] == 'TIMESTAMP_HOUR') {
772 const multiSelectArray = [];
774 if (formFieldObj['formFieldValues'].length > 0) {
775 const date = formFieldObj['formFieldValues'][0]['id'];
777 let tempDate = new Date(date);
778 multiSelectArray.push(tempDate);
779 multiSelectArray.push(tempDate.getHours());
780 this.formFieldListValueMap.set(formFieldObj['fieldId'], multiSelectArray);
782 multiSelectArray.push('');
783 multiSelectArray.push('0');
784 this.formFieldListValueMap.set(formFieldObj['fieldId'], multiSelectArray);
788 const date = formFieldObj['formFieldValues'][0]['id'];
789 this.formFieldListValueMap.set(formFieldObj['fieldId'], new Date(date));
791 } else if (formFieldObj['fieldType'] == 'LIST_BOX' && formFieldObj['formFieldValues'].length > 0) {
793 for (let ffValue = 0; ffValue < formFieldObj['formFieldValues'].length; ffValue++) {
794 if (formFieldObj['formFieldValues'][ffValue]['defaultValue'] == true) {
795 this.formFieldListValueMap.set(formFieldObj['fieldId'], formFieldObj['formFieldValues'][ffValue]['id']);
800 this.formFieldListValueMap.set(formFieldObj['fieldId'], '');
802 } else if ((formFieldObj['fieldType'] == 'LIST_MULTI_SELECT' || formFieldObj['fieldType'] == 'TEXT') && formFieldObj['formFieldValues'].length > 0) {
804 const multiSelectArray = [];
805 for (let ffValue = 0; ffValue < formFieldObj['formFieldValues'].length; ffValue++) {
806 if (formFieldObj['formFieldValues'][ffValue]['defaultValue'] == true) {
807 multiSelectArray.push(formFieldObj['formFieldValues'][ffValue]['id']);
808 this.formFieldListValueMap.set(formFieldObj['fieldId'], multiSelectArray);
813 this.formFieldListValueMap.set(formFieldObj['fieldId'], '');
815 } else if (formFieldObj['fieldDisplayName'] == 'DefaultRadio') {
816 this.formFieldListValueMap.set(formFieldObj['fieldId'], '');
819 this.formFieldListValueMap.set(formFieldObj['fieldId'], '');
823 if (formFieldObj['triggerOtherFormFields'] === true) {
824 const formFieldId = formFieldObj['fieldId'];
825 this.triggerFormFieldArr.push(formFieldId);
826 this.initialObject[formFieldId] = [];
827 this.finalQueryParamsObj[formFieldId] = [];
831 console.log(this.formFieldListValueMap);
833 if (this.calledWithFormFields != true) {
834 if (this.formFieldGroupObjList !== null) {
835 for (const formFieldGroupObjItem of this.formFieldGroupObjList) {
836 if (formFieldGroupObjItem['name'] == this.groupSelectValue) {
837 this.toggleFormFieldRenderArr = formFieldGroupObjItem['formFieldList'];
838 for (let ffGrpValue = 0; ffGrpValue < formFieldGroupObjItem['formFieldList'].length; ffGrpValue++) {
839 if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length > 0) {
840 for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) {
841 if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['defaultValue'] == true) {
842 if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'LIST_MULTI_SELECT') {
843 const multiSelectArray = [];
844 multiSelectArray.push(formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']);
845 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], multiSelectArray);
847 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']);
852 this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], '');
861 console.log('finalMap', this.formFieldListValueMap);
862 if (this.formFieldGroupObjList !== null) {
863 if (this.formFieldGroupObjList.length > 0) {
864 for (let ffl = 0; ffl < this.formFieldList.length; ffl++) {
865 for (let ffgl = 0; ffgl < this.formFieldGroupObjList.length; ffgl++) {
866 const inList = this.formFieldGroupObjList[ffgl]['formFieldList'];
868 for (let inl = 0; inl < inList.length; inl++) {
870 if (inList[inl]['fieldId'] == this.formFieldList[ffl]['fieldId']) {
874 this.finalQueryParamsObj[inList[inl]['fieldId']] = '-1';
882 this.save = cloneDeep(this.formFieldGroupObjList);
886 generateQueryString() {
888 this.queryString = '';
889 for (let k = 0; k < Object.keys(this.finalQueryParamsObj).length; k++) {
890 if (typeof (this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]]) == 'object') {
891 const key = Object.keys(this.finalQueryParamsObj)[k];
894 while (this.finalQueryParamsObj[key][l]) {
896 qstr = qstr + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]][l];
898 qstr = qstr + '|' + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]][l];
903 this.queryString = this.queryString + '&' + Object.keys(this.finalQueryParamsObj)[k] + '=' + qstr;
906 if (typeof (this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]]) == 'string') {
907 this.queryString = this.queryString + '&' + Object.keys(this.finalQueryParamsObj)[k] + '=' + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]];
909 this.queryString = this.queryString + '&' + Object.keys(this.finalQueryParamsObj)[k] + '=' + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]];
917 showError(Errresponse: any) {
918 this.errorMessage = Errresponse['errormessage'];
919 this.stackTrace = Errresponse['stacktrace'];
921 this.showSpinner = false;
926 this.showSpinner = true;
927 if (this.iSDashboardReport !== 'Dashboard') {
928 if (this.formFieldList.length > 0) {
929 this.reportMode = 'FormField';
930 this.generateQueryString();
932 this.reportMode = 'Regular';
934 this.showSpinner = false;
936 this.generateQueryString();
937 this.showSpinner = false;
939 this.httpCacheService.setRouteCache(this.reportId, this.getQueryString());
940 this.httpCacheService.setRouteGroupCache(this.reportId, this.groupSelectValue);
941 this.runReportAgain = !this.runReportAgain;
942 this.navigateToRun = true;
945 editReport(reportId: string) {
946 this._router.navigate(['v2/app/reports', 'Edit', reportId]);
950 this.showLabel = !this.showLabel;
953 setDefaultFieldGroupValueForNonSelected(formFieldsList: any) {
954 this.tempFieldValues = [];
955 const map = new Map<string, string>();
956 for (const value in this.finalQueryParamsObj) {
957 map.set(value, this.finalQueryParamsObj[value]);
959 for (const ffl of formFieldsList) {
960 if (!map.get(ffl['fieldId']) && ffl['formFieldValues'].length === 1) {
961 this.tempFieldValues = ffl['formFieldValues'];
962 if (ffl['fieldDisplayName'] == this.tempFieldValues[0]['name']) {
963 this.finalQueryParamsObj[ffl['fieldId']] = '-1';
969 resetFormFieldValues() {
970 this.httpCacheService.clearCache();
971 this._router.navigateByUrl('v2/app/refresh', {skipLocationChange: true}).then(() =>
972 this._router.navigate(['v2/run', this.reportId]));
976 const prevId = this.httpCacheService.getPreviousId(this.reportId) || null;
977 const prevIdParent = this.httpCacheService.getPreviousId(prevId) || null;
979 if (prevIdParent && prevIdParent === 'parent') {
980 this._router.navigate(['v2/run', prevId, this.httpCacheService.getRouteCache(prevId), this.httpCacheService.getRouteGroupCache(prevId), 'false', 'true']);
982 this._router.navigate(['v2/run', prevId, this.httpCacheService.getRouteCache(prevId), this.httpCacheService.getRouteGroupCache(prevId), 'true', 'true']);
987 private delay(ms: number) {
988 return new Promise(resolve => setTimeout(resolve, ms));
991 private removePrevioustoggleGroupData() {
992 for (const formFieldGroupObjItem of this.formFieldGroupObjList) {
993 if (formFieldGroupObjItem['name'] == this.oldGroupSelectValue) {
994 for (let ffGrpValue = 0; ffGrpValue < formFieldGroupObjItem['formFieldList'].length; ffGrpValue++) {
995 this.finalQueryParamsObj[formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId']] = '-1';
996 this.formFieldListValueMap.delete(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId']);
997 this.triggerFormFieldArr = [];
1005 for(let i=0; i<=59; i++){
1006 this.timeStampArray.push(i);
1011 for(let i=0; i<=23; i++){
1012 this.hoursArray.push(i);