1 import { Component, OnInit, Input, SimpleChange, SystemJsNgModuleLoader } from '@angular/core';
2 import { RunService } from '../run.service';
3 import { ActivatedRoute, Router } from '@angular/router';
4 import { inlineInterpolate } from '@angular/core/src/view';
7 selector: 'app-run-report-form-fields',
8 templateUrl: './run-report-form-fields.component.html',
9 styleUrls: ['./run-report-form-fields.component.css']
11 export class RunReportFormFieldsComponent implements OnInit {
13 @Input("formFieldList") formFieldList : {}[];
14 @Input("reportId") reportId : string;
17 staticFormFieldList : {}[] = [];
18 formFieldListValueArr : any[];
19 finalQueryParamsObj : {};
20 navigateToRun : boolean;
24 showSpinner : boolean;
26 runDashboardReport : boolean;
27 DashboardReportObj : {}[] = new Array();
28 triggerFormFieldArr = new Array();
29 initialObject = new Object();
30 formFieldGroupObjList : {}[] = [];
31 toggleFormFieldRenderArr : {}[] = [];
32 groupSelectValue : string = "";
33 oldGroupSelectValue : string = "";
34 unCommonCnt : number = 0;
35 commonCount : number = 0;
36 totalCount : number = 0;
37 errorMessage : string = "";
38 stackTrace : string = "";
39 error : boolean = false;
40 iSDashboardReport : string = "";
42 directCallQueryParams : any = "";
43 calledWithFormFields : boolean = false;
46 constructor(private _runService : RunService, private _route : ActivatedRoute, private _router : Router) {
47 this.formFieldListValueArr = new Array();
48 this.finalQueryParamsObj = new Object();
49 this.navigateToRun = false;
50 this.queryString = "";
51 this.showSpinner = false;
52 this.showLabel = false;
53 this.runDashboardReport = false;
55 this._router.routeReuseStrategy.shouldReuseRoute = function() {
62 this.showSpinner = true;
63 this.navigateToRun = false;
65 this._route.params.subscribe(params => {
67 this.reportId = params["reportId"];
69 if(params["queryParameters"])
71 this.directCallQueryParams = params["queryParameters"];
72 this.calledWithFormFields = true;
79 this._runService.getDefinitionPageDetails(+this.reportId)
80 .subscribe((responseDefPage) => {
82 this.reportName = responseDefPage["reportName"];
83 if(responseDefPage["reportType"] !== "Dashboard")
85 if(this.calledWithFormFields == false)
87 this._runService.getReportData(this.reportId)
88 .subscribe((response) => {
89 if(response["errormessage"])
91 this.showError(response);
96 this.reportName = response["reportName"];
97 if(response["formFieldList"].length > 0)
99 this.fetchAndPopulateFormFields(response, this.reportId);
103 this.reportMode = "Regular";
104 this.navigateToRun = true;
107 this.showSpinner = false;
113 this.reportMode = "FormField";
114 this.navigateToRun = true;
115 this.showSpinner = false;
120 this.iSDashboardReport = "Dashboard";
121 this.reportName = responseDefPage["reportName"];
122 this.DashboardReportObj = JSON.parse(responseDefPage["dashboardLayoutJSON"]);
124 let subReportId = "";
126 while(this.DashboardReportObj[i])
128 subReportId = this.DashboardReportObj[i]["hasContent"]["id"].split("#")[1];
133 this._runService.getReportData(subReportId)
134 .subscribe((response) => {
135 if(response["errormessage"])
137 this.showError(response);
142 if(response["formFieldList"].length > 0)
144 this.fetchAndPopulateFormFields(response, subReportId);
146 this.runDashboardReport = true;
147 this.showSpinner = false;
162 if(this.formFieldList !== undefined)
164 if(this.groupSelectValue !== this.oldGroupSelectValue)
168 this.oldGroupSelectValue = this.groupSelectValue;
169 for(let formFieldGroupObjItem of this.formFieldGroupObjList)
171 if(formFieldGroupObjItem["name"] == this.groupSelectValue)
173 this.toggleFormFieldRenderArr = formFieldGroupObjItem["formFieldList"];
178 if(this.toggleFormFieldRenderArr.length > 0)
180 for(let i=0; i<this.toggleFormFieldRenderArr.length; i++)
182 let formFieldObj = this.toggleFormFieldRenderArr[i];
183 if(formFieldObj["triggerOtherFormFields"] === true)
185 let formFieldId = formFieldObj["fieldId"];
186 this.triggerFormFieldArr.push(formFieldId);
187 this.initialObject[formFieldId] = "1";
188 this.finalQueryParamsObj[formFieldId] = "1";
193 for(let fvl=this.commonCount; fvl < this.formFieldListValueArr.length; fvl++)
195 this.formFieldListValueArr[fvl] = null;
198 if(this.formFieldGroupObjList.length > 0)
200 for(let k=0; k<this.formFieldList.length; k++)
202 for(let i=0; i<this.formFieldGroupObjList.length; i++)
204 let inList = this.formFieldGroupObjList[i]["formFieldList"];
206 for(let j=0; j<inList.length; j++)
209 if(inList[j]["fieldId"] == this.formFieldList[k]["fieldId"])
215 this.finalQueryParamsObj[inList[j]["fieldId"]] = "1";
227 //Toggle Form Field Block Begins
229 for(let tffr=0; tffr<this.toggleFormFieldRenderArr.length; tffr++)
231 if(this.formFieldListValueArr[tffr + this.commonCount])
233 if(this.toggleFormFieldRenderArr[tffr]["validationType"] == "DATE")
235 this.finalQueryParamsObj[this.toggleFormFieldRenderArr[tffr]["fieldId"]] = this.convertDate(this.formFieldListValueArr[tffr + this.commonCount]);
239 this.finalQueryParamsObj[this.toggleFormFieldRenderArr[tffr]["fieldId"]] = this.formFieldListValueArr[tffr + this.commonCount];
240 for(let trigElement of this.triggerFormFieldArr)
242 if(this.initialObject[trigElement] !== this.finalQueryParamsObj[trigElement])
244 this.initialObject[trigElement] = this.finalQueryParamsObj[trigElement];
245 this.generateQueryString();
246 this._runService.refreshFormFields(this.reportId, this.queryString)
247 .subscribe((responseRefreshFF) => {
248 for(let rrff=0; rrff<responseRefreshFF["formFieldList"].length; rrff++)
250 for(let innerTFRR=0; innerTFRR<this.toggleFormFieldRenderArr.length; innerTFRR++)
252 if(responseRefreshFF["formFieldList"][rrff]["fieldId"] == this.toggleFormFieldRenderArr[innerTFRR]["fieldId"])
254 this.toggleFormFieldRenderArr[innerTFRR] = responseRefreshFF["formFieldList"][rrff];
259 this.initialObject[trigElement] = this.finalQueryParamsObj[trigElement];
267 //Toggle Form Field Block Ends
269 this.formFieldListValueArr = this.formFieldListValueArr;
270 if(this.reportMode !== "Regular" && this.reportMode !== "Dashboard")
272 for(let ffl=0; ffl<this.formFieldList.length; ffl++)
274 if(this.formFieldListValueArr[ffl])
276 if(this.formFieldList[ffl]["validationType"] == "DATE")
278 this.finalQueryParamsObj[this.formFieldList[ffl]["fieldId"]] = this.convertDate(this.formFieldListValueArr[ffl]);
282 this.finalQueryParamsObj[this.formFieldList[ffl]["fieldId"]] = this.formFieldListValueArr[ffl];
283 for(let trigElement of this.triggerFormFieldArr)
285 if(this.initialObject[trigElement] !== this.finalQueryParamsObj[trigElement])
287 this.initialObject[trigElement] = this.finalQueryParamsObj[trigElement];
288 this.generateQueryString();
289 this._runService.refreshFormFields(this.reportId, this.queryString)
290 .subscribe((responseRefreshFF) => {
292 for(let rrff=0; rrff<responseRefreshFF["formFieldList"].length; rrff++)
294 for(let innerFFL=0; innerFFL<this.formFieldList.length; innerFFL++)
296 if(responseRefreshFF["formFieldList"][rrff]["fieldId"] == this.formFieldList[innerFFL]["fieldId"])
298 this.formFieldList[innerFFL] = responseRefreshFF["formFieldList"][rrff];
314 var date = new Date(str),
315 mnth = ("0" + (date.getMonth() + 1)).slice(-2),
316 day = ("0" + date.getDate()).slice(-2);
317 return [mnth, day, date.getFullYear()].join("/");
322 if(this.directCallQueryParams !== "")
324 return this.directCallQueryParams;
328 return this.queryString;
332 fetchAndPopulateFormFields(respObj : any, ffReportId : string)
335 this._runService.getFormFieldGroupsData(ffReportId)
336 .subscribe((responseFormFieldGroups) => {
337 this.formFieldGroupObjList = JSON.parse(responseFormFieldGroups["formFieldGroupsJSON"]);
340 this.formFieldList = respObj["formFieldList"];
341 this.staticFormFieldList = respObj["formFieldList"];
342 this.reportMode = "FormField";
343 this.totalCount = this.formFieldList.length;
344 if(this.formFieldGroupObjList !== null)
346 for(let ffgl=0; ffgl<this.formFieldGroupObjList.length; ffgl++)
348 for(let itemFFGL=0; itemFFGL<this.formFieldGroupObjList[ffgl]["formFieldList"].length; itemFFGL++)
350 let formFieldGroupItem = this.formFieldGroupObjList[ffgl]["formFieldList"][itemFFGL];
351 for(let fflg=0; fflg<this.formFieldList.length; fflg++)
353 if(formFieldGroupItem["id"] == this.formFieldList[fflg]["fieldId"])
355 this.formFieldGroupObjList[ffgl]["formFieldList"][itemFFGL] = this.formFieldList[fflg];
356 this.formFieldList.splice(fflg, 1);
364 this.commonCount = this.totalCount - this.unCommonCnt;
366 for(let i=0; i<this.formFieldList.length; i++)
368 let formFieldObj = this.formFieldList[i];
369 if(formFieldObj["triggerOtherFormFields"] === true)
371 let formFieldId = formFieldObj["fieldId"];
372 this.triggerFormFieldArr.push(formFieldId);
373 this.initialObject[formFieldId] = [];
374 this.finalQueryParamsObj[formFieldId] = [];
380 generateQueryString()
384 for(let k=0; k<Object.keys(this.finalQueryParamsObj).length; k++)
387 if(typeof(this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]]) == "object")
390 let key = Object.keys(this.finalQueryParamsObj)[k];
393 while(this.finalQueryParamsObj[key][l])
397 qstr = qstr + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]][l];
401 qstr = qstr + "|" + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]][l];
407 this.queryString = this.queryString + "&" + Object.keys(this.finalQueryParamsObj)[k] + "=" + qstr;
412 if(typeof(this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]]) == "string")
414 let stringParam = this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]];
415 if(stringParam.split(",").length > 1)
419 for(let param of stringParam.split(","))
427 qstr = qstr + "|" + param;
433 this.queryString = this.queryString + "&" + Object.keys(this.finalQueryParamsObj)[k] + "=" + qstr;
438 this.queryString = this.queryString + "&" + Object.keys(this.finalQueryParamsObj)[k] + "=" + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]];
443 this.queryString = this.queryString + "&" + Object.keys(this.finalQueryParamsObj)[k] + "=" + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]];
453 showError(Errresponse : any)
455 this.errorMessage = Errresponse["errormessage"];
456 this.stackTrace = Errresponse["stacktrace"];
458 this.showSpinner = false;
464 this.showSpinner = true;
467 if(this.iSDashboardReport !== "Dashboard")
470 if(this.formFieldList.length > 0)
472 this.reportMode = "FormField";
473 this.generateQueryString();
477 this.reportMode = "Regular";
481 this.showSpinner = false;
486 this.generateQueryString();
488 this.showSpinner = false;
491 this.navigateToRun = true;
494 editReport(reportId : string)
496 this._router.navigate(["v2/reports", "Edit", reportId]);
501 this.showLabel = !this.showLabel;