diff options
Diffstat (limited to 'ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/report-run/run/run-report-form-fields/run-report-form-fields.component.ts')
-rw-r--r-- | ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/report-run/run/run-report-form-fields/run-report-form-fields.component.ts | 1015 |
1 files changed, 1015 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/report-run/run/run-report-form-fields/run-report-form-fields.component.ts b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/report-run/run/run-report-form-fields/run-report-form-fields.component.ts new file mode 100644 index 00000000..ced812d2 --- /dev/null +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/report-run/run/run-report-form-fields/run-report-form-fields.component.ts @@ -0,0 +1,1015 @@ +import {ChangeDetectorRef, Component, HostListener, OnInit, Input, SimpleChange, SystemJsNgModuleLoader, OnDestroy} from '@angular/core'; +import {RunService} from '../run.service'; +import {ActivatedRoute, Router} from '@angular/router'; +import * as cloneDeep from 'lodash/cloneDeep'; +import {environment} from 'src/environments/environment'; +import {HttpCacheService} from '../../../shared/services/cache.service'; + +@Component({ + selector: 'app-run-report-form-fields', + templateUrl: './run-report-form-fields.component.html', + styleUrls: ['./run-report-form-fields.component.css'] +}) +export class RunReportFormFieldsComponent implements OnInit, OnDestroy { + @Input('formFieldList') formFieldList: {}[]; + @Input('reportId') reportId: string; + staticFormFieldList: {}[] = []; + formFieldListValueArr: any[]; + saveFormFieldGroups: any[]; + finalQueryParamsObj: {}; + navigateToRun: boolean; + reportMode: string; + queryString: string; + reportName: string; + reportSubTitle: string; + showSpinner: boolean; + showLabel: boolean; + runDashboardReport: boolean; + DashboardReportObj: {}[] = []; + triggerFormFieldArr = []; + initialObject = {}; + formFieldGroupObjList: {}[] = []; + toggleFormFieldRenderArr: {}[] = []; + groupSelectValue = ''; + oldGroupSelectValue = ''; + unCommonCnt = 0; + commonCount = 0; + totalCommonCount = 0; + totalCount = 0; + errorMessage = ''; + stackTrace = ''; + error = false; + iSDashboardReport = ''; + hitCnt = 0; + directCallQueryParams: any = ''; + calledWithFormFields = false; + showformFiledSpinner = false; + actualformFieldValues: any[]; + allowEdit: boolean; + runReportAgain: boolean; + tempFieldValues = []; + firstRun = false; + saveFormFieldListValueArr: any[]; + saveGroupSelectValue = ''; + avoidDoCheck = false; + toolTipPosition = 'right'; + isResetAllowed: boolean; + save: {}[]; + unCommonGropusList: any[]; + commonFormFields: any[]; + formFieldListValueMap: any; + saveFormFieldListValueMap: any; + chartType = ''; + showRunButton = false; + showBackButton = false; + downloadPrevReport = ''; + timeStampArray: any[]; + hoursArray : any[]; + constructor(private _runService: RunService, + private _route: ActivatedRoute, + private _router: Router, + private changeDetectorRefs: ChangeDetectorRef, + private httpCacheService: HttpCacheService) { + this.formFieldListValueArr = []; + this.saveFormFieldListValueArr = []; + this.saveFormFieldGroups = []; + this.finalQueryParamsObj = {}; + this.navigateToRun = false; + this.queryString = ''; + this.showSpinner = false; + this.showLabel = false; + this.runDashboardReport = false; + this.showformFiledSpinner = false; + this.runReportAgain = false; + this.tempFieldValues = []; + this.isResetAllowed = false; + this.unCommonGropusList = []; + this.commonFormFields = []; + this.formFieldListValueMap = new Map<any, any>(); + this.saveFormFieldListValueMap = new Map<any, any>(); + this.chartType = ''; + this.showRunButton = false; + this.showBackButton = false; + this.downloadPrevReport = ''; + this.timeStampArray = []; + this.hoursArray = []; + + } + + @HostListener('click') onClick() { + this.changeDetectorRefs.detectChanges(); + } + + ngOnDestroy(): void { + this.createNewObject(); + this.showSpinner = false; + } + + createNewObject() { + this.staticFormFieldList = []; + this.formFieldListValueArr = []; + this.saveFormFieldGroups = []; + this.saveFormFieldListValueArr = []; + this.finalQueryParamsObj = {}; + this.navigateToRun = false; + this.reportMode = ''; + this.queryString = ''; + this.reportName = ''; + this.reportSubTitle = ''; + this.showSpinner = true; + this.showLabel = false; + this.runDashboardReport = false; + this.DashboardReportObj = []; + this.triggerFormFieldArr = []; + this.initialObject = {}; + this.formFieldGroupObjList = []; + this.toggleFormFieldRenderArr = []; + this.groupSelectValue = ''; + this.oldGroupSelectValue = ''; + this.unCommonCnt = 0; + this.totalCommonCount = 0; + this.commonCount = 0; + this.totalCount = 0; + this.errorMessage = ''; + this.stackTrace = ''; + this.error = false; + this.iSDashboardReport = ''; + this.hitCnt = 0; + this.directCallQueryParams = ''; + this.calledWithFormFields = false; + this.showformFiledSpinner = false; + this.allowEdit = false; + this.runReportAgain = false; + this.isResetAllowed = false; + this.unCommonGropusList = []; + this.commonFormFields = []; + this.formFieldListValueMap = new Map<any, any>(); + this.saveFormFieldListValueMap = new Map<any, any>(); + this.chartType = ''; + this.showRunButton = false; + this.downloadPrevReport = ''; + } + + ngOnInit() { + + this.showSpinner = true; + this.navigateToRun = false; + this.getTime(); + this.getHours(); + this._route.params.subscribe(params => { + this.createNewObject(); + this.reportId = params['reportId']; + const checkOfCache = this.httpCacheService.getPreviousId(this.reportId) || null; + if (!checkOfCache) { + this.httpCacheService.clearCache(); + } + const backButton = params['showBackButton']; + const downloadPrevReport = params['downloadPrevReport']; + if (downloadPrevReport && downloadPrevReport === 'true') { + this.downloadPrevReport = 'true'; + } + if (backButton && backButton === 'true') { + this.showBackButton = true; + } else if (backButton && backButton === 'false') { + this.showBackButton = false; + } else { + this.showBackButton = false; + } + this.groupSelectValue = params['groupSelectValue']; + if (this.groupSelectValue === undefined) { + this.groupSelectValue = ''; + } + if (params['queryParameters']) { + this.directCallQueryParams = params['queryParameters']; + this.calledWithFormFields = true; + this.populateQueryParams(params['queryParameters']); + } + this.loadPage(); + }); + + } + + populateQueryParams(queryParams: any) { + this.actualformFieldValues = this.directCallQueryParams.substring(1, this.directCallQueryParams.length).split('&'); + for (const ff of this.actualformFieldValues) { + const formfiledArray = ff.split('='); + const formFieldId = formfiledArray[0]; + const formFieldObj = formfiledArray[1]; + this.finalQueryParamsObj[formFieldId] = formFieldObj; + } + this.queryString = this.directCallQueryParams; + } + + loadPage() { + this._runService.getDefinitionPageDetails(+this.reportId) + .subscribe((responseDefPage) => { + this.reportName = responseDefPage['reportName']; + this.reportSubTitle = responseDefPage['reportSubTitle']; + this.chartType = responseDefPage['chartType']; + if (responseDefPage['reportType'] !== 'Dashboard') { + if (this.calledWithFormFields == false) { + this._runService.getReportData(this.reportId) + .subscribe((response) => { + if (response['errormessage']) { + this.allowEdit = response['allowEdit']; + this.showError(response); + } else { + this.allowEdit = response['allowEdit']; + this.reportName = response['reportName']; + if (response['formFieldList'].length > 0) { + this.fetchAndPopulateFormFields(response, this.reportId); + this.showformFiledSpinner = true; + } else { + this.formFieldList = response['formFieldList']; + this.reportMode = 'Regular'; + this.httpCacheService.setRouteCache(this.reportId, this.getQueryString()); + this.httpCacheService.setRouteGroupCache(this.reportId, this.groupSelectValue); + this.navigateToRun = true; + this.showformFiledSpinner = false; + + } + this.showSpinner = false; + } + }); + } else if (this.calledWithFormFields == true) { + this._runService.getReportData(this.reportId) + .subscribe((response) => { + if (response['errormessage']) { + this.showError(response); + } else { + this.error = false; + this.reportName = response['reportName']; + this.allowEdit = response['allowEdit']; + if (response['formFieldList'].length > 0) { + this.setDefaultFieldGroupValueForNonSelected(response['formFieldList']); + this.generateQueryString(); + this.fetchAndPopulateFormFields(response, this.reportId); + this.formFieldListValueMap = new Map<any, any>(); + for (const ff of response['formFieldList']) { + if (this.finalQueryParamsObj[ff.fieldId]) { + if (ff.validationType == 'DATE') { + const dateVal = this.finalQueryParamsObj[ff.fieldId]; + this.formFieldListValueMap.set(ff.fieldId, new Date(dateVal.toString().replace(/%2F/g, '/'))); + } else if (ff.fieldType == 'LIST_MULTI_SELECT') { + const multiSelectArray = []; + let multiVal = this.finalQueryParamsObj[ff.fieldId]; + multiVal = multiVal.toString().replace(/%2F/g, '/'); + multiVal = multiVal.toString().replace(/%20/g, ' '); + multiVal = multiVal.toString().replace(/%28/g, '('); + multiVal = multiVal.toString().replace(/%29/g, ')'); + multiVal = multiVal.toString().replace('+', ' '); + if (multiVal.split('|').length > 1) { + let tempArray = multiVal.split('|'); + for (let arr = 0; arr < tempArray.length; arr++) { + multiSelectArray.push(tempArray[arr]); + } + } else { + multiSelectArray.push(multiVal); + } + this.formFieldListValueMap.set(ff.fieldId, multiSelectArray); + } else { + let multiVal = this.finalQueryParamsObj[ff.fieldId]; + multiVal = multiVal.toString().replace(/%2F/g, '/'); + multiVal = multiVal.toString().replace(/%20/g, ' '); + multiVal = multiVal.toString().replace(/%28/g, '('); + multiVal = multiVal.toString().replace(/%29/g, ')'); + multiVal = multiVal.toString().split('+').join(' '); + this.formFieldListValueMap.set(ff.fieldId, multiVal); + } + } else { + if (ff.fieldType == 'LIST_MULTI_SELECT') { + const multiSelectArray = []; + this.formFieldListValueMap.set(ff.fieldId, multiSelectArray); + } else { + this.formFieldListValueMap.set(ff.fieldId, ''); + } + } + } + this.error = false; + this.httpCacheService.setRouteCache(this.reportId, this.getQueryString()); + this.httpCacheService.setRouteGroupCache(this.reportId, this.groupSelectValue); + this.navigateToRun = true; + this.showformFiledSpinner = true; + this.directCallQueryParams = ''; + } else { + this.reportMode = 'Regular'; + this.navigateToRun = true; + this.showformFiledSpinner = false; + + } + this.showSpinner = false; + + } + }); + } else { + this.reportMode = 'FormField'; + this.navigateToRun = true; + this.showSpinner = false; + this.showformFiledSpinner = true; + } + } else { + if (this.calledWithFormFields == false) { + this.iSDashboardReport = 'Dashboard'; + this.reportName = responseDefPage['reportName']; + this.DashboardReportObj = JSON.parse(responseDefPage['dashboardLayoutJSON']); + let i = 0; + let subReportId = ''; + const tempDashboardArray = []; + for (let dash = 0; dash < this.DashboardReportObj.length; dash++) { + if (this.DashboardReportObj[dash]['hasContent']['hideDisplay'] !== true) { + tempDashboardArray.push(this.DashboardReportObj[dash]); + } + } + this.DashboardReportObj = []; + this.DashboardReportObj = tempDashboardArray; + while (this.DashboardReportObj[i]) { + subReportId = this.DashboardReportObj[i]['hasContent']['id'].split('#')[1]; + i++; + break; + } + this._runService.getReportData(subReportId) + .subscribe((response) => { + if (response['errormessage']) { + this.showError(response); + this.allowEdit = response['allowEdit']; + } else { + this.allowEdit = response['allowEdit']; + if (response['formFieldList'].length > 0) { + this.fetchAndPopulateFormFields(response, subReportId); + } else { + this.navigateToRun = true; + } + this.runDashboardReport = true; + this.showSpinner = false; + this.showformFiledSpinner = true; + } + }); + this.showSpinner = false; + this.showformFiledSpinner = true; + } else if (this.calledWithFormFields == true) { + this.httpCacheService.setRouteCache(this.reportId, this.getQueryString()); + this.httpCacheService.setRouteGroupCache(this.reportId, this.groupSelectValue); + this.iSDashboardReport = 'Dashboard'; + this.reportName = responseDefPage['reportName']; + this.DashboardReportObj = JSON.parse(responseDefPage['dashboardLayoutJSON']); + const tempDashboardArray = []; + for (let dash = 0; dash < this.DashboardReportObj.length; dash++) { + if (this.DashboardReportObj[dash]['hasContent']['hideDisplay'] !== true) { + tempDashboardArray.push(this.DashboardReportObj[dash]); + } + } + this.DashboardReportObj = []; + this.DashboardReportObj = tempDashboardArray; + let subReportId1 = ''; + let i = 0; + while (this.DashboardReportObj[i]) { + subReportId1 = this.DashboardReportObj[i]['hasContent']['id'].split('#')[1]; + i++; + break; + } + this._runService.getReportData(subReportId1) + .subscribe((response) => { + if (response['errormessage']) { + this.showError(response); + this.allowEdit = response['allowEdit']; + } else { + this.allowEdit = response['allowEdit']; + if (response['formFieldList'].length > 0) { + this.fetchAndPopulateFormFields(response, subReportId1); + this.formFieldListValueMap = new Map<any, any>(); + for (const ff of response['formFieldList']) { + if (this.finalQueryParamsObj[ff.fieldId]) { + if (ff.validationType == 'DATE') { + const dateVal = this.finalQueryParamsObj[ff.fieldId]; + this.formFieldListValueMap.set(ff.fieldId, new Date(dateVal.toString().replace(/%2F/g, '/'))); + } else if (ff.fieldType == 'LIST_MULTI_SELECT') { + const multiSelectArray = []; + let multiVal = this.finalQueryParamsObj[ff.fieldId]; + multiVal = multiVal.toString().replace(/%2F/g, '/'); + multiVal = multiVal.toString().replace(/%20/g, ' '); + multiVal = multiVal.toString().replace(/%28/g, '('); + multiVal = multiVal.toString().replace(/%29/g, ')'); + multiVal = multiVal.toString().replace('+', ' '); + if (multiVal.split('|').length > 1) { + let tempArray = multiVal.split('|'); + for (let arr = 0; arr < tempArray.length; arr++) { + multiSelectArray.push(tempArray[arr]); + } + } else { + multiSelectArray.push(multiVal); + } + this.formFieldListValueMap.set(ff.fieldId, multiSelectArray); + } else { + let multiVal = this.finalQueryParamsObj[ff.fieldId]; + multiVal = multiVal.toString().replace(/%2F/g, '/'); + multiVal = multiVal.toString().replace(/%20/g, ' '); + multiVal = multiVal.toString().replace(/%28/g, '('); + multiVal = multiVal.toString().replace(/%29/g, ')'); + multiVal = multiVal.toString().split('+').join(' '); + if (multiVal == 'NULL') { + this.formFieldListValueMap.set(ff.fieldId, ''); + } else { + this.formFieldListValueMap.set(ff.fieldId, multiVal); + } + } + } else { + if (ff.fieldType == 'LIST_MULTI_SELECT') { + const multiSelectArray = []; + this.formFieldListValueMap.set(ff.fieldId, multiSelectArray); + } else { + this.formFieldListValueMap.set(ff.fieldId, ''); + } + } + } + } else { + this.navigateToRun = true; + } + let subReportId = ''; + for (const dashboard of this.DashboardReportObj) { + let temp = ''; + temp = dashboard['hasContent']['id'].split('#')[1]; + subReportId = temp; + this.directCallQueryParams = ''; + this.runDashboardReport = true; + this.navigateToRun = true; + this.showSpinner = false; + } + } + }); + + } + + } + }); + } + + toggleChangeWhenCalledWithFromFields() { + this.calledWithFormFields = false; + } + + async ngDoCheck() { + + if (this.formFieldList !== undefined) { + + if (this.groupSelectValue !== this.oldGroupSelectValue) { + // this.formFieldListValueArr.splice(this.commonCount-1, this.formFieldListValueArr.length) + this.removePrevioustoggleGroupData(); + this.oldGroupSelectValue = this.groupSelectValue; + this.formFieldGroupObjList = []; + this.saveFormFieldGroups = []; + this.formFieldGroupObjList = cloneDeep(this.save); + this.saveFormFieldGroups = cloneDeep(this.save); + for (const formFieldGroupObjItem of this.formFieldGroupObjList) { + if (formFieldGroupObjItem['name'] == this.groupSelectValue) { + this.toggleFormFieldRenderArr = formFieldGroupObjItem['formFieldList']; + } + + } + if (this.toggleFormFieldRenderArr.length > 0) { + for (let i = 0; i < this.toggleFormFieldRenderArr.length; i++) { + const formFieldObj = this.toggleFormFieldRenderArr[i]; + if (formFieldObj['triggerOtherFormFields'] === true) { + const formFieldId = formFieldObj['fieldId']; + this.triggerFormFieldArr.push(formFieldId); + this.initialObject[formFieldId] = '1'; + this.finalQueryParamsObj[formFieldId] = '1'; + } + } + } + + if (this.calledWithFormFields != true) { + for (const formFieldGroupObjItem of this.saveFormFieldGroups) { + if (formFieldGroupObjItem['name'] == this.groupSelectValue) { + this.toggleFormFieldRenderArr = formFieldGroupObjItem['formFieldList']; + for (let ffGrpValue = 0; ffGrpValue < formFieldGroupObjItem['formFieldList'].length; ffGrpValue++) { + if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length > 0) { + for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) { + if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'LIST_BOX' && formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length > 0) { + let isAdded = false; + for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) { + if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['defaultValue'] == true) { + this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']); + isAdded = true; + } + } + if (!isAdded) { + this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], ''); + } + } else if ((formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'LIST_MULTI_SELECT' || formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'TEXT') && formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length > 0) { + let isAdded = false; + for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) { + + if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['defaultValue'] == true) { + const multiSelectArray = []; + multiSelectArray.push(formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']); + this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], multiSelectArray); + isAdded = true; + } + } + if (!isAdded) { + this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], ''); + } + } else if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'Select Field Type' && formFieldGroupObjItem['formFieldList'][ffGrpValue]['validationType'] == 'NONE') { + let isAdded = false; + for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) { + + if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['defaultValue'] == true) { + this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']); + isAdded = true; + } + } + if (!isAdded) { + this.formFieldListValueArr[this.totalCommonCount + ffGrpValue] = ''; + } + } else { + this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], ''); + } + } + } else { + this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], ''); + } + } + } + } + } + if (this.formFieldGroupObjList.length > 0) { + for (let ffl = 0; ffl < this.formFieldList.length; ffl++) { + for (let ffgl = 0; ffgl < this.formFieldGroupObjList.length; ffgl++) { + const inList = this.formFieldGroupObjList[ffgl]['formFieldList']; + + for (let inl = 0; inl < inList.length; inl++) { + let cntr = 0; + if (inList[inl]['fieldId'] == this.formFieldList[ffl]['fieldId']) { + cntr++; + } + if (cntr == 0) { + this.finalQueryParamsObj[inList[inl]['fieldId']] = '-1'; + } + } + + } + } + } + } + for (const tffr of this.toggleFormFieldRenderArr) { + if (this.formFieldListValueMap.get(tffr['fieldId']) || this.formFieldListValueMap.get(tffr['fieldId']) == '') { + if (tffr['validationType'] == 'DATE') { + this.finalQueryParamsObj[tffr['fieldId']] = this.convertDate(this.formFieldListValueMap.get(tffr['fieldId'])); + } else if (this.formFieldListValueMap.get(tffr['fieldId']) == '') { + + if (tffr['fieldType'] == 'LIST_MULTI_SELECT') { + let multiSelectValue = ''; + if (multiSelectValue != '') { + multiSelectValue = multiSelectValue.substring(0, multiSelectValue.length - 1); + } + this.finalQueryParamsObj[tffr['fieldId']] = multiSelectValue; + + } else { + this.finalQueryParamsObj[tffr['fieldId']] = ''; + } + } else { + this.finalQueryParamsObj[tffr['fieldId']] = this.formFieldListValueMap.get(tffr['fieldId']); + if (this.initialObject[tffr['fieldId']] !== this.finalQueryParamsObj[tffr['fieldId']]) { + this.initialObject[tffr['fieldId']] = this.finalQueryParamsObj[tffr['fieldId']]; + this.generateQueryString(); + await this.delay(1000); + console.log('Afterp: ' + new Date().toString()); + if ( tffr['triggerOtherFormFields'] == true) { + this._runService.refreshFormFields(this.reportId, this.queryString) + .subscribe((responseRefreshFF) => { + for (let rrff = 0; rrff < responseRefreshFF['formFieldList'].length; rrff++) { + for (let innerTFRR = 0; innerTFRR < this.toggleFormFieldRenderArr.length; innerTFRR++) { + if (responseRefreshFF['formFieldList'][rrff]['fieldId'] == this.toggleFormFieldRenderArr[innerTFRR]['fieldId']) { + this.toggleFormFieldRenderArr[innerTFRR] = responseRefreshFF['formFieldList'][rrff]; + } + } + } + }); + + } + this.initialObject[tffr['fieldId']] = this.finalQueryParamsObj[tffr['fieldId']]; + } + } + } + } + + if (this.reportMode !== 'Regular' && this.reportMode !== 'Dashboard') { + for (const ffvalue of this.formFieldList) { + if (this.formFieldListValueMap.get(ffvalue['fieldId']) === '' || this.formFieldListValueMap.get(ffvalue['fieldId']) ) { + if (ffvalue['validationType'] == 'DATE' && this.formFieldListValueMap.get(ffvalue['fieldId']) !== '' ) { + this.finalQueryParamsObj[ffvalue['fieldId']] = this.convertDate(this.formFieldListValueMap.get(ffvalue['fieldId'])); + }else if (ffvalue['validationType'] == 'TIMESTAMP_SEC' && this.formFieldListValueMap.get(ffvalue['fieldId']) !== ''){ + if(this.formFieldListValueMap.get(ffvalue['fieldId'])[0] != ''){ + this.finalQueryParamsObj[ffvalue['fieldId']] = this.convertDate(this.formFieldListValueMap.get(ffvalue['fieldId'])[0]); + } else { + this.finalQueryParamsObj[ffvalue['fieldId']] = this.formFieldListValueMap.get(ffvalue['fieldId'])[0]; + } + this.finalQueryParamsObj[ffvalue['fieldId']+'_Hr'] = this.formFieldListValueMap.get(ffvalue['fieldId'])[1]; + this.finalQueryParamsObj[ffvalue['fieldId']+'_Min'] = this.formFieldListValueMap.get(ffvalue['fieldId'])[2]; + this.finalQueryParamsObj[ffvalue['fieldId']+'_Sec'] = this.formFieldListValueMap.get(ffvalue['fieldId'])[3]; + }else if (ffvalue['validationType'] == 'TIMESTAMP_MIN' && this.formFieldListValueMap.get(ffvalue['fieldId']) !== ''){ + if(this.formFieldListValueMap.get(ffvalue['fieldId'])[0] != ''){ + this.finalQueryParamsObj[ffvalue['fieldId']] = this.convertDate(this.formFieldListValueMap.get(ffvalue['fieldId'])[0]); + }else{ + this.finalQueryParamsObj[ffvalue['fieldId']] = this.formFieldListValueMap.get(ffvalue['fieldId'])[0]; + } + this.finalQueryParamsObj[ffvalue['fieldId']+'_Hr'] = this.formFieldListValueMap.get(ffvalue['fieldId'])[1]; + this.finalQueryParamsObj[ffvalue['fieldId']+'_Min'] = this.formFieldListValueMap.get(ffvalue['fieldId'])[2]; + }else if (ffvalue['validationType'] == 'TIMESTAMP_HOUR' && this.formFieldListValueMap.get(ffvalue['fieldId']) !== ''){ + if(this.formFieldListValueMap.get(ffvalue['fieldId'])[0] != ''){ + this.finalQueryParamsObj[ffvalue['fieldId']] = this.convertDate(this.formFieldListValueMap.get(ffvalue['fieldId'])[0]); + }else{ + this.finalQueryParamsObj[ffvalue['fieldId']] = this.formFieldListValueMap.get(ffvalue['fieldId'])[0]; + } + this.finalQueryParamsObj[ffvalue['fieldId']+'_Hr'] = this.formFieldListValueMap.get(ffvalue['fieldId'])[1]; + } + else { + this.finalQueryParamsObj[ffvalue['fieldId']] = this.formFieldListValueMap.get(ffvalue['fieldId']); + } + for (const trigElement of this.triggerFormFieldArr) { + if (this.initialObject[trigElement] !== this.finalQueryParamsObj[trigElement]) { + this.initialObject[trigElement] = this.finalQueryParamsObj[trigElement]; + this.generateQueryString(); + await this.delay(1000); + console.log('Afterp: ' + new Date().toString()); + if (ffvalue['triggerOtherFormFields'] == true) { + this._runService.refreshFormFields(this.reportId, this.queryString) + .subscribe((responseRefreshFF) => { + for (let rrff = 0; rrff < responseRefreshFF['formFieldList'].length; rrff++) { + for (let innerFFL = 0; innerFFL < this.formFieldList.length; innerFFL++) { + if (responseRefreshFF['formFieldList'][rrff]['fieldId'] == this.formFieldList[innerFFL]['fieldId']) { + this.formFieldList[innerFFL] = responseRefreshFF['formFieldList'][rrff]; + } + } + } + }); + } + + } + + } + } + } + + } + } + if (this.firstRun) { + this.saveGroupSelectValue = this.groupSelectValue; + this.saveFormFieldListValueMap = cloneDeep(this.formFieldListValueMap); + } + this.firstRun = false; + } + + convertDate(str) { + const date = new Date(str), + mnth = ('0' + (date.getMonth() + 1)).slice(-2), + day = ('0' + date.getDate()).slice(-2); + return [mnth, day, date.getFullYear()].join('/'); + } + + getQueryString() { + if (this.directCallQueryParams !== '') { + return this.directCallQueryParams; + } else { + return this.queryString; + } + } + + fetchAndPopulateFormFields(respObj: any, ffReportId: string) { + this._runService.getFormFieldGroupsData(ffReportId) + .subscribe((responseFormFieldGroups) => { + this.firstRun = true; + this.showformFiledSpinner = false; + this.formFieldGroupObjList = JSON.parse(responseFormFieldGroups['formFieldGroupsJSON']); + this.saveFormFieldGroups = JSON.parse(responseFormFieldGroups['formFieldGroupsJSON']); + this.formFieldList = respObj['formFieldList']; + if (this.formFieldList.length === 1 && this.formFieldList[0]['visible'] === false) { + this.showRunButton = false; + } else if (this.formFieldList.length > 0) { + this.showRunButton = true; + } + this.staticFormFieldList = respObj['formFieldList']; + this.reportMode = 'FormField'; + this.totalCount = this.formFieldList.length; + if (this.formFieldGroupObjList !== null) { + for (let ffgl = 0; ffgl < this.formFieldGroupObjList.length; ffgl++) { + for (let itemFFGL = 0; itemFFGL < this.formFieldGroupObjList[ffgl]['formFieldList'].length; itemFFGL++) { + const formFieldGroupItem = this.formFieldGroupObjList[ffgl]['formFieldList'][itemFFGL]; + for (let fflg = 0; fflg < this.formFieldList.length; fflg++) { + if (formFieldGroupItem['id'] == this.formFieldList[fflg]['fieldId']) { + this.formFieldGroupObjList[ffgl]['formFieldList'][itemFFGL] = this.formFieldList[fflg]; + this.saveFormFieldGroups[ffgl]['formFieldList'][itemFFGL] = this.formFieldList[fflg]; + + if (this.formFieldList[fflg]['triggerOtherFormFields'] === true) { + const formFieldId = this.formFieldList[fflg]['fieldId']; + this.triggerFormFieldArr.push(formFieldId); + this.initialObject[formFieldId] = []; + this.finalQueryParamsObj[formFieldId] = []; + } + this.formFieldList.splice(fflg, 1); + this.unCommonGropusList.push(formFieldGroupItem); + this.unCommonCnt++; + } + } + } + } + } + if (this.calledWithFormFields != true) { + for (let checkRadio = 0; checkRadio < this.formFieldList.length; checkRadio++) { + if (this.formFieldList[checkRadio]['fieldDisplayName'] == 'selectCriteria') { + for (let ffValue = 0; ffValue < this.formFieldList[checkRadio]['formFieldValues'].length; ffValue++) { + if (this.formFieldList[checkRadio]['formFieldValues'][ffValue]['defaultValue'] == true) { + this.groupSelectValue = this.formFieldList[checkRadio]['formFieldValues'][ffValue]['name']; + } + } + this.oldGroupSelectValue = this.groupSelectValue; + } + } + } + this.commonCount = this.totalCount - this.unCommonCnt; + this.totalCommonCount = this.commonCount; + console.log(this.unCommonGropusList); + console.log(this.formFieldList); + for (let i = 0; i < this.formFieldList.length; i++) { + const formFieldObj = this.formFieldList[i]; + if (formFieldObj['formFieldValues'] != null && this.calledWithFormFields != true) { + if ((formFieldObj['validationType'] == 'DATE' && formFieldObj['formFieldValues'].length > 0) || formFieldObj['validationType'] == 'TIMESTAMP_SEC' || formFieldObj['validationType'] == 'TIMESTAMP_MIN' || formFieldObj['validationType'] == 'TIMESTAMP_HOUR') { + if (formFieldObj['validationType'] == 'TIMESTAMP_SEC') { + const multiSelectArray = []; + + if (formFieldObj['formFieldValues'].length > 0) { + const date = formFieldObj['formFieldValues'][0]['id']; + let tempDate = new Date(date); + multiSelectArray.push(tempDate); + multiSelectArray.push(tempDate.getHours()); + multiSelectArray.push(tempDate.getMinutes()); + multiSelectArray.push(tempDate.getSeconds()); + this.formFieldListValueMap.set(formFieldObj['fieldId'], multiSelectArray); + } else { + multiSelectArray.push(''); + multiSelectArray.push('0'); + multiSelectArray.push('0'); + multiSelectArray.push('0'); + this.formFieldListValueMap.set(formFieldObj['fieldId'], multiSelectArray); + } + } + else if (formFieldObj['validationType'] == 'TIMESTAMP_MIN') { + const multiSelectArray = []; + if (formFieldObj['formFieldValues'].length > 0) { + const date = formFieldObj['formFieldValues'][0]['id']; + let tempDate = new Date(date); + multiSelectArray.push(tempDate); + multiSelectArray.push(tempDate.getHours()); + multiSelectArray.push(tempDate.getMinutes()); + this.formFieldListValueMap.set(formFieldObj['fieldId'], multiSelectArray); + } else { + multiSelectArray.push(''); + multiSelectArray.push('0'); + multiSelectArray.push('0'); + this.formFieldListValueMap.set(formFieldObj['fieldId'], multiSelectArray); + } + } else if (formFieldObj['validationType'] == 'TIMESTAMP_HOUR') { + const multiSelectArray = []; + + if (formFieldObj['formFieldValues'].length > 0) { + const date = formFieldObj['formFieldValues'][0]['id']; + + let tempDate = new Date(date); + multiSelectArray.push(tempDate); + multiSelectArray.push(tempDate.getHours()); + this.formFieldListValueMap.set(formFieldObj['fieldId'], multiSelectArray); + } else { + multiSelectArray.push(''); + multiSelectArray.push('0'); + this.formFieldListValueMap.set(formFieldObj['fieldId'], multiSelectArray); + } + } + else{ + const date = formFieldObj['formFieldValues'][0]['id']; + this.formFieldListValueMap.set(formFieldObj['fieldId'], new Date(date)); + } + } else if (formFieldObj['fieldType'] == 'LIST_BOX' && formFieldObj['formFieldValues'].length > 0) { + let isAdded = false; + for (let ffValue = 0; ffValue < formFieldObj['formFieldValues'].length; ffValue++) { + if (formFieldObj['formFieldValues'][ffValue]['defaultValue'] == true) { + this.formFieldListValueMap.set(formFieldObj['fieldId'], formFieldObj['formFieldValues'][ffValue]['id']); + isAdded = true; + } + } + if (!isAdded) { + this.formFieldListValueMap.set(formFieldObj['fieldId'], ''); + } + } else if ((formFieldObj['fieldType'] == 'LIST_MULTI_SELECT' || formFieldObj['fieldType'] == 'TEXT') && formFieldObj['formFieldValues'].length > 0) { + let isAdded = false; + const multiSelectArray = []; + for (let ffValue = 0; ffValue < formFieldObj['formFieldValues'].length; ffValue++) { + if (formFieldObj['formFieldValues'][ffValue]['defaultValue'] == true) { + multiSelectArray.push(formFieldObj['formFieldValues'][ffValue]['id']); + this.formFieldListValueMap.set(formFieldObj['fieldId'], multiSelectArray); + isAdded = true; + } + } + if (!isAdded) { + this.formFieldListValueMap.set(formFieldObj['fieldId'], ''); + } + } else if (formFieldObj['fieldDisplayName'] == 'DefaultRadio') { + this.formFieldListValueMap.set(formFieldObj['fieldId'], ''); + + } else { + this.formFieldListValueMap.set(formFieldObj['fieldId'], ''); + } + } + + if (formFieldObj['triggerOtherFormFields'] === true) { + const formFieldId = formFieldObj['fieldId']; + this.triggerFormFieldArr.push(formFieldId); + this.initialObject[formFieldId] = []; + this.finalQueryParamsObj[formFieldId] = []; + } + } + + console.log(this.formFieldListValueMap); + + if (this.calledWithFormFields != true) { + if (this.formFieldGroupObjList !== null) { + for (const formFieldGroupObjItem of this.formFieldGroupObjList) { + if (formFieldGroupObjItem['name'] == this.groupSelectValue) { + this.toggleFormFieldRenderArr = formFieldGroupObjItem['formFieldList']; + for (let ffGrpValue = 0; ffGrpValue < formFieldGroupObjItem['formFieldList'].length; ffGrpValue++) { + if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length > 0) { + for (let ffValue = 0; ffValue < formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'].length; ffValue++) { + if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['defaultValue'] == true) { + if (formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldType'] == 'LIST_MULTI_SELECT') { + const multiSelectArray = []; + multiSelectArray.push(formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']); + this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], multiSelectArray); + } else { + this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], formFieldGroupObjItem['formFieldList'][ffGrpValue]['formFieldValues'][ffValue]['id']); + } + } + } + } else { + this.formFieldListValueMap.set(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId'], ''); + + } + } + } + + } + } + } + console.log('finalMap', this.formFieldListValueMap); + if (this.formFieldGroupObjList !== null) { + if (this.formFieldGroupObjList.length > 0) { + for (let ffl = 0; ffl < this.formFieldList.length; ffl++) { + for (let ffgl = 0; ffgl < this.formFieldGroupObjList.length; ffgl++) { + const inList = this.formFieldGroupObjList[ffgl]['formFieldList']; + + for (let inl = 0; inl < inList.length; inl++) { + let cntr = 0; + if (inList[inl]['fieldId'] == this.formFieldList[ffl]['fieldId']) { + cntr++; + } + if (cntr == 0) { + this.finalQueryParamsObj[inList[inl]['fieldId']] = '-1'; + } + } + + } + } + } + } + this.save = cloneDeep(this.formFieldGroupObjList); + }); + } + + generateQueryString() { + + this.queryString = ''; + for (let k = 0; k < Object.keys(this.finalQueryParamsObj).length; k++) { + if (typeof (this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]]) == 'object') { + const key = Object.keys(this.finalQueryParamsObj)[k]; + let qstr = ''; + let l = 0; + while (this.finalQueryParamsObj[key][l]) { + if (l === 0) { + qstr = qstr + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]][l]; + } else { + qstr = qstr + '|' + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]][l]; + } + l++; + } + if (qstr !== '') { + this.queryString = this.queryString + '&' + Object.keys(this.finalQueryParamsObj)[k] + '=' + qstr; + } + } else { + if (typeof (this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]]) == 'string') { + this.queryString = this.queryString + '&' + Object.keys(this.finalQueryParamsObj)[k] + '=' + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]]; + } else { + this.queryString = this.queryString + '&' + Object.keys(this.finalQueryParamsObj)[k] + '=' + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]]; + } + } + + } + + } + + showError(Errresponse: any) { + this.errorMessage = Errresponse['errormessage']; + this.stackTrace = Errresponse['stacktrace']; + this.error = true; + this.showSpinner = false; + } + + runReport() { + this.hitCnt++; + this.showSpinner = true; + if (this.iSDashboardReport !== 'Dashboard') { + if (this.formFieldList.length > 0) { + this.reportMode = 'FormField'; + this.generateQueryString(); + } else { + this.reportMode = 'Regular'; + } + this.showSpinner = false; + } else { + this.generateQueryString(); + this.showSpinner = false; + } + this.httpCacheService.setRouteCache(this.reportId, this.getQueryString()); + this.httpCacheService.setRouteGroupCache(this.reportId, this.groupSelectValue); + this.runReportAgain = !this.runReportAgain; + this.navigateToRun = true; + } + + editReport(reportId: string) { + this._router.navigate(['v2/app/reports', 'Edit', reportId]); + } + + showLabelFn() { + this.showLabel = !this.showLabel; + } + + setDefaultFieldGroupValueForNonSelected(formFieldsList: any) { + this.tempFieldValues = []; + const map = new Map<string, string>(); + for (const value in this.finalQueryParamsObj) { + map.set(value, this.finalQueryParamsObj[value]); + } + for (const ffl of formFieldsList) { + if (!map.get(ffl['fieldId']) && ffl['formFieldValues'].length === 1) { + this.tempFieldValues = ffl['formFieldValues']; + if (ffl['fieldDisplayName'] == this.tempFieldValues[0]['name']) { + this.finalQueryParamsObj[ffl['fieldId']] = '-1'; + } + } + } + } + + resetFormFieldValues() { + this.httpCacheService.clearCache(); + this._router.navigateByUrl('v2/app/refresh', {skipLocationChange: true}).then(() => + this._router.navigate(['v2/run', this.reportId])); + } + + goBack() { + const prevId = this.httpCacheService.getPreviousId(this.reportId) || null; + const prevIdParent = this.httpCacheService.getPreviousId(prevId) || null; + if (prevId) { + if (prevIdParent && prevIdParent === 'parent') { + this._router.navigate(['v2/run', prevId, this.httpCacheService.getRouteCache(prevId), this.httpCacheService.getRouteGroupCache(prevId), 'false', 'true']); + } else { + this._router.navigate(['v2/run', prevId, this.httpCacheService.getRouteCache(prevId), this.httpCacheService.getRouteGroupCache(prevId), 'true', 'true']); + } + } + } + + private delay(ms: number) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + private removePrevioustoggleGroupData() { + for (const formFieldGroupObjItem of this.formFieldGroupObjList) { + if (formFieldGroupObjItem['name'] == this.oldGroupSelectValue) { + for (let ffGrpValue = 0; ffGrpValue < formFieldGroupObjItem['formFieldList'].length; ffGrpValue++) { + this.finalQueryParamsObj[formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId']] = '-1'; + this.formFieldListValueMap.delete(formFieldGroupObjItem['formFieldList'][ffGrpValue]['fieldId']); + this.triggerFormFieldArr = []; + } + + } + } + } + + getTime(){ + for(let i=0; i<=59; i++){ + this.timeStampArray.push(i); + } + } + + getHours(){ + for(let i=0; i<=23; i++){ + this.hoursArray.push(i); + } + } +} |