4e751b83457777398c53c34a08d8c955b5edfe1e
[portal/sdk.git] /
1 import { Component, OnInit, Input, SimpleChange } from '@angular/core';
2 import { RunService } from '../run.service';
3 import { ActivatedRoute } from '@angular/router';
4
5 @Component({
6   selector: 'app-run-report-form-fields',
7   templateUrl: './run-report-form-fields.component.html',
8   styleUrls: ['./run-report-form-fields.component.css']
9 })
10 export class RunReportFormFieldsComponent implements OnInit {
11
12   @Input("formFieldList") formFieldList : {}[];
13   @Input("reportId") reportId : string;
14   
15
16   formFieldListValueArr : any[];
17   finalQueryParamsObj : {};
18   navigateToRun : boolean;
19   reportMode : string;
20   queryString : string;
21
22   constructor(private _runService : RunService, private _route : ActivatedRoute ) { 
23     this.formFieldListValueArr = new Array();
24     this.finalQueryParamsObj = new Object();
25     this.navigateToRun = false;
26     this.queryString = "";
27   }
28
29   ngOnInit() {
30     
31     this._route.params.subscribe(params => {
32       
33       this.reportId = params["reportId"];
34     });
35
36     this._runService.getReportData(this.reportId)
37     .subscribe((response) => {
38
39       if(response["formFieldList"].length > 0)
40       {
41         this.formFieldList = response["formFieldList"];
42         this.reportMode = "FormField";
43       }
44       else
45       {
46         this.reportMode = "Regular";
47         this.navigateToRun = true;
48         
49       }
50
51       console.log(this.navigateToRun);
52
53     });
54   }
55
56   ngDoCheck()
57   {
58     if(this.navigateToRun == false)
59     {
60     this.formFieldListValueArr = this.formFieldListValueArr;
61
62     for(let i=0; i<this.formFieldList.length; i++)
63     {
64       if(this.formFieldListValueArr[i])
65       {
66         this.finalQueryParamsObj[this.formFieldList[i]["fieldId"]] = this.formFieldListValueArr[i];
67       }
68     }
69     console.log(this.formFieldListValueArr);
70     console.log(this.finalQueryParamsObj);
71   }
72   
73   }
74
75   getQueryString()
76   {
77       return this.queryString;
78   }
79
80   runReport()
81   {
82     this._runService.getReportData(this.reportId)
83     .subscribe((response) => {
84       this.navigateToRun = false;
85       if(response["formFieldList"].length > 0)
86       {
87         this.formFieldList = response["formFieldList"];
88         this.reportMode = "FormField";
89
90         for(let i=0; i<this.formFieldList.length; i++)
91         {
92           if(this.formFieldListValueArr[i])
93           {
94             this.finalQueryParamsObj[this.formFieldList[i]["fieldId"]] = this.formFieldListValueArr[i];
95           }
96         }
97
98         this.queryString="";
99     for(let k=0; k<Object.keys(this.finalQueryParamsObj).length; k++)
100     {
101       this.queryString = this.queryString + "&" + Object.keys(this.finalQueryParamsObj)[k] + "=" + this.finalQueryParamsObj[Object.keys(this.finalQueryParamsObj)[k]];
102     }
103
104     console.log(this.queryString);
105     this.navigateToRun = true;
106     console.log(this.navigateToRun);
107       }
108       else
109       {
110         this.navigateToRun = true;
111         this.reportMode = "Regular";
112       }
113
114       
115
116     
117     });
118
119     
120       // this._runService.getReportDataWithFormFields(this.finalQueryParamsObj, this.reportId)
121       // .subscribe((responseFormFields) => {
122       //   console.log(responseFormFields);
123       // });
124       
125   }
126
127   
128
129 }