c1b79ba0c7533706186f56b575e226745575a348
[portal/sdk.git] /
1 import { AfterViewInit, Component, OnInit, ViewChild, SimpleChange } from '@angular/core';
2 import { MatPaginator } from '@angular/material/paginator';
3 import { MatSort } from '@angular/material/sort';
4 import { MatTable } from '@angular/material/table';
5 import { DataTableDataSource, DataTableItem } from './column-list-datasource';
6 import { HttpClient } from '@angular/common/http';
7 import { environment } from '../../../../../../../environments/environment';
8 import { ColumnService } from '../column.service';
9
10 @Component({
11   selector: 'app-column-list',
12   templateUrl: './column-list.component.html',
13   styleUrls: ['./column-list.component.css']
14 })
15 export class ColumnListComponent implements OnInit {
16   @ViewChild(MatPaginator, {static: false} as any) paginator: MatPaginator;
17   @ViewChild(MatSort, {static: false} as any) sort: MatSort;
18   @ViewChild(MatTable, {static: false} as any) table: MatTable<DataTableItem>;
19
20   
21   dataSource: DataTableDataSource;
22   finalGetObj : {};
23   finalEditRowGetObj : {};
24   finalObjArr: DataTableItem[];
25   status : string;
26   message : string;
27   showDialog : boolean;
28   closable : boolean;
29
30   columnId : string;
31   id : string;
32   name : string;
33   noWrap : boolean;
34   visible : boolean;
35   dependsOnFormFields : string;
36   dataType : string;
37   groupByPos : string;
38   customTextForSubTotal : string;
39   hideRepeatedValues : boolean;
40   multiGroupColumnLevel;
41   colspan : string;
42   displayName : string;
43   displayWidthInPixel : string;
44   indentation : string;
45   displayAlignment : string;
46   displayHeaderAlignment : string;
47   sortable : boolean;
48   drilldownURL : string;
49   displayTotal : string;
50   URLListObj : {};
51   URLListObjArray : {}[];
52   TotalColListObj : {};
53   TotalColListObjArray : {}[];
54   finalPOSTObj : {};
55
56   
57
58   /** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
59   displayedColumns = ['no', 'id', 'name', 'edit'];
60   SQLstatus: string;
61   SQLmessage: string;
62   showSaveColDialog: boolean;
63   Colclosable: boolean;
64   EditColmessage: string;
65   EditColstatus: string;
66
67   constructor(private _http : HttpClient, private _columnService : ColumnService){
68
69     this.dataSource = new DataTableDataSource();
70
71     this.finalGetObj = new Object();
72     this.finalObjArr = new Array();
73     this.finalEditRowGetObj = new Object();
74   this.URLListObjArray = new Array();
75   this.TotalColListObjArray = new Array();
76     this.finalPOSTObj = new Object();
77
78   }
79
80   ngOnInit() {
81     this._columnService.getColumnList()
82     .subscribe((response) => {
83       //console.log(response);
84
85      this.finalGetObj = response;
86
87      let k=0;
88      while(this.finalGetObj[k])
89      {
90       this.finalGetObj[k]["no"] = k+1;
91       this.finalGetObj[k]["edit"] = "";
92
93       this.finalObjArr.push(this.finalGetObj[k]);
94
95       //console.log(this.finalObjArr);
96       k++;
97      }
98
99
100      
101
102       this.dataSource.data = this.finalObjArr;
103
104       this.dataSource.sort = this.sort;
105     this.dataSource.paginator = this.paginator;
106     this.table.dataSource = this.dataSource;
107     this.dataSource.data = this.finalObjArr;
108       //this.dataSource.data = [{id:"1", no:1, name:"1", edit:""}];
109     });
110     this.showDialog = false;
111     this.showSaveColDialog =false;
112     
113   }
114
115   ngAfterViewInit() {
116    
117   }
118
119
120   editRecord(id : string)
121   {
122     this.columnId = id;
123     this._columnService.getIndividualColumnData(id)
124     .subscribe((response) => {
125       this.finalEditRowGetObj = response;
126       //console.log(response);
127
128       this.id = this.finalEditRowGetObj["colId"];
129       this.name = this.finalEditRowGetObj["colName"];
130
131       this.noWrap = (this.finalEditRowGetObj["noWrap"] === "Y" ? true : false);
132       this.visible = this.finalEditRowGetObj["visible"];
133
134       this.dependsOnFormFields = this.finalEditRowGetObj["depeondsOnForField"];
135       this.dataType = this.finalEditRowGetObj["dataType"];
136       this.groupByPos = (this.finalEditRowGetObj["groupByPos"] == null ? 0 : this.finalEditRowGetObj["groupByPos"] );
137       this.customTextForSubTotal = this.finalEditRowGetObj["subTotalCustomText"];
138       this.hideRepeatedValues = this.finalEditRowGetObj["hideRepeatedKey"];
139       this.multiGroupColumnLevel = (this.finalEditRowGetObj["level"] == null ? 0 : this.finalEditRowGetObj["level"]);
140       this.colspan  = (this.finalEditRowGetObj["colspan"] == null ? 0 : this.finalEditRowGetObj["colspan"]);
141       this.displayName = this.finalEditRowGetObj["displayName"];
142       this.displayWidthInPixel = (this.finalEditRowGetObj["displayWidthInPixel"] == null ? 0 : this.finalEditRowGetObj["displayWidthInPixel"] );
143       this.indentation = (this.finalEditRowGetObj["indentation"] == null ? 0 : this.finalEditRowGetObj["indentation"]);
144       this.displayAlignment = this.finalEditRowGetObj["displayAlignment"];
145       this.displayHeaderAlignment = (this.finalEditRowGetObj["displayHeaderAlignment"] == null ? "" : this.finalEditRowGetObj["displayHeaderAlignment"]);
146       this.sortable = this.finalEditRowGetObj["sortable"];
147       this.drilldownURL = this.finalEditRowGetObj["drilldownURL"];
148       this. displayTotal = (this.finalEditRowGetObj["displayTotal"] == null ? "" : this.finalEditRowGetObj["displayTotal"]);
149
150
151       this._columnService.getDrillDownReportList()
152       .subscribe((responseURLList) => {
153         
154         this.URLListObj = responseURLList;
155
156         let l=0;
157         while(this.URLListObj[l])
158         {
159             this.URLListObjArray.push(this.URLListObj[l]);
160             l++;
161         }
162         //console.log(this.URLListObjArray);
163
164       });
165
166
167       this._columnService.getResponseTotalColsList()
168       .subscribe((responseTotalColList) => {
169         //console.log(responseTotalColList);
170
171         this.TotalColListObj = responseTotalColList;
172
173         let l=0;
174         while(this.TotalColListObj[l])
175         {
176             this.TotalColListObjArray.push(this.TotalColListObj[l]);
177             l++;
178         }
179         //console.log(this.TotalColListObjArray);
180       });
181
182       this.status = "Success!";
183       this.message = "Report Column - Edit";
184         this.showDialog = !this.showDialog;
185         this.closable = true; 
186
187     });
188
189
190     
191   }
192
193   
194   close() {
195     this.showDialog = !this.showDialog;
196     this.closable = false;
197
198     this.showSaveColDialog =false;
199     this.Colclosable = false;
200   }
201
202
203   save()
204   {
205
206     this.showDialog = !this.showDialog; 
207     this.closable = true;
208
209     this.finalPOSTObj["tabId"] = "ColEdit";
210     this.finalPOSTObj["tabName"] = "Column Edit";
211
212     this.finalPOSTObj["colId"] = this.id;
213     this.finalPOSTObj["colName"] = this.name;
214
215     this.finalPOSTObj["colType"] = "";
216     this.finalPOSTObj["colspan"] = this.colspan;
217     this.finalPOSTObj["dataType"] = this.dataType;
218     this.finalPOSTObj["depeondsOnForField"] = this.dependsOnFormFields;
219     this.finalPOSTObj["displayAlignment"] = this.displayAlignment;
220     this.finalPOSTObj["displayHeaderAlignment"] = this.displayHeaderAlignment;
221     this.finalPOSTObj["displayName"] = this.displayName;
222     this.finalPOSTObj["displayTotal"] = this.displayTotal;
223     this.finalPOSTObj["displayWidth"] = 10;
224     this.finalPOSTObj["displayWidthInPixel"] = this.displayWidthInPixel;
225     this.finalPOSTObj["drilldownParams"] = "";
226     this.finalPOSTObj["drilldownType"] = "";
227     this.finalPOSTObj["drilldownURL"] = this.drilldownURL;
228     this.finalPOSTObj["errorMessage"] = "";
229     this.finalPOSTObj["errorStackTrace"] = "";
230     this.finalPOSTObj["groupByPos"] = this.groupByPos;
231     this.finalPOSTObj["hideRepeatedKey"] = this.hideRepeatedValues;
232     this.finalPOSTObj["indentation"] = this.indentation;
233     this.finalPOSTObj["level"] = this.multiGroupColumnLevel;
234     this.finalPOSTObj["noWrap"] = (this.noWrap === true? "Y" : "N");
235     this.finalPOSTObj["sortable"] = this.sortable;
236     this.finalPOSTObj["subTotalCustomText"] = this.displayTotal;
237     this.finalPOSTObj["visible"] = this.visible;
238
239     //console.log(this.finalPOSTObj);
240
241     this._columnService.postColumnChanges(this.finalPOSTObj)
242     .subscribe((finalPOSTResponse) => {
243       console.log(finalPOSTResponse);
244
245       if(finalPOSTResponse)
246       {
247         this.EditColstatus = "Success!";
248         this.EditColmessage = "Your change has been saved! Row definition is updated.";
249           this.showSaveColDialog = !this.showSaveColDialog;
250           this.Colclosable = true; 
251       }
252       else
253       {
254         this.EditColstatus = "Failure!";
255         this.EditColmessage = "Row definition could not be updated.";
256           this.showSaveColDialog = !this.showSaveColDialog;
257           this.Colclosable = true;
258       }
259
260
261     });
262
263     
264     console.log("Saved!!!");
265   }
266
267
268 }