9441a1f06a25ce8e36c0e350905d602ad39f27ba
[portal/sdk.git] /
1 import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core';
2 import { trigger, transition, style, animate } from '@angular/animations';
3 import { HttpClient } from '@angular/common/http';
4 import { ColumnService } from '../../column.service';
5
6
7
8 @Component({
9   selector: 'app-edit-drill-down-link',
10   templateUrl: './edit-drill-down-link.component.html',
11   styleUrls: ['./edit-drill-down-link.component.css']
12 })
13 export class EditDrillDownLinkComponent implements OnInit {
14
15   
16   @Input() closable = true;
17   @Input() visible: boolean;
18
19   @Input("reportId") reportId : number;
20   @Input("drillDownObj") drillDownObj : {};
21
22   @Output() completed = new EventEmitter<any>();
23
24   drillDownColsList : {}[];
25   valueOfColumnsList : {}[];
26   showSpinner : boolean;
27
28   valueOfColumns : string;
29   valueOfColumnsArr : any[];
30   valueOfFormFieldArr : any[];
31   fixedValueArr : any[];
32
33   noValueRadioArr : any[];
34   valueValueArr : any[];
35   radioButtonCheckedArr : boolean[];
36   fieldValuesArr : string[];
37
38
39   postDrillDownObj : {};
40   
41   constructor(private _http : HttpClient, private _columnService : ColumnService) {
42     this.drillDownColsList = new Array();
43     this.valueOfColumnsList = new Array();
44     this.showSpinner = true;
45     this.valueOfColumnsArr = new Array();
46     this.valueOfFormFieldArr = new Array();
47     this.postDrillDownObj = new Object();
48
49     this.noValueRadioArr = new Array();
50     this.valueValueArr = new Array();
51     this.radioButtonCheckedArr = new Array();
52     this.fieldValuesArr = new Array();
53
54     
55    }
56
57   ngOnInit() {
58
59     console.log(this.drillDownObj);
60
61     this._columnService.getDrillDownReportColumnDetails(this.drillDownObj["drillDownUrl"])
62     .subscribe((response) => {
63       console.log(response);
64       let i=0;
65
66       while(response[i])
67       {
68         this.drillDownColsList.push(response[i]);
69         // this.valueOfFormFieldArr.push(response[i]["name"]);
70         // console.log(response);
71         i++;
72       }
73         
74       console.log(this.drillDownColsList);
75
76       this._columnService.getValueOfColumnDetails(this.reportId)
77       .subscribe((responseValueOfColumn)=> {
78         console.log(responseValueOfColumn);
79
80         let k=0;
81
82         while(responseValueOfColumn[k])
83         {
84             this.valueOfColumnsList.push(responseValueOfColumn[k]);
85             k++;
86         }
87         // for(let l=0; l<this.drillDownColsList.length; l++)
88         // {
89         //   this.valueOfColumnsArr.push("site_state");
90         // }
91
92         console.log(this.drillDownObj["drillDownParams"]);
93
94       for(let kj=0; kj<this.drillDownObj["drillDownParams"].split("&").length; kj++)
95       {
96         for(let aj=0; aj<this.drillDownObj["drillDownParams"].split("&")[kj].split("=").length; aj++)
97         {
98           for(let lk=0; lk<this.drillDownColsList.length; lk++)
99           {
100             console.log(this.drillDownColsList[lk]["name"], this.drillDownObj["drillDownParams"].split("&")[kj].split("=")[1]);
101             if(this.drillDownColsList[lk]["id"] == this.drillDownObj["drillDownParams"].split("&")[kj].split("=")[0])
102             {
103               if(this.drillDownColsList[lk]["name"] == this.drillDownObj["drillDownParams"].split("&")[kj].split("=")[1])
104               {
105                 let index = (lk*5) + 3;
106                 this.radioButtonCheckedArr[index] = true;
107                 console.log(this.radioButtonCheckedArr);
108               }
109             }
110           }
111         }
112       }
113       
114
115
116
117         this.showSpinner = false;
118       });
119
120      
121       
122     });
123
124
125   }
126
127   ngDoCheck()
128   {
129     let queryParamsString = "";
130     // drillDownColsList
131     console.log(this.noValueRadioArr, this.valueValueArr);
132
133     if(this.noValueRadioArr && this.valueValueArr)
134     {
135       
136       for(let j=0; j<this.noValueRadioArr.length; j++)
137       {
138         console.log(+this.noValueRadioArr[j]);
139         if(this.valueValueArr[+this.noValueRadioArr[j]] !== null)
140         {
141           
142           // console.log(this.drillDownColsList[+this.noValueRadioArr[j]/5]["id"]);
143           // console.log(Math.floor((+this.noValueRadioArr[j]-1)/5));
144           
145           if(Math.floor((+this.noValueRadioArr[j]-1)/5) === 0)
146           {
147             queryParamsString = queryParamsString + this.drillDownColsList[Math.floor((+this.noValueRadioArr[j]-1)/5)]["id"] + "=" +  this.valueValueArr[+this.noValueRadioArr[j]];
148             // console.log(queryParamsString);
149           }
150           else
151           {
152             queryParamsString = queryParamsString + "&" + this.drillDownColsList[Math.floor((+this.noValueRadioArr[j]-1)/5)]["id"] + "=" +  this.valueValueArr[+this.noValueRadioArr[j]];
153             // console.log(queryParamsString);
154           }
155         }
156       }
157
158
159       // console.log(queryParamsString);
160
161     this.postDrillDownObj["drilldownParams"] =  queryParamsString;
162     this.postDrillDownObj["drilldownType"] =  "";
163
164     // console.log(this.postDrillDownObj);
165     
166     this.completed.emit(this.postDrillDownObj);
167     }
168   }
169
170
171
172
173 }