25f5109c11857a93c6547944ed93e9563a05df3d
[portal/sdk.git] /
1 import { AfterViewInit, Component, OnInit, ViewChild, SimpleChange, Input, Output } 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 import {SemaphoreList} from '../model/semaphore-list';
10 import {Semaphore} from '../model/semaphore';
11
12 @Component({
13     selector: 'app-column-list',
14     templateUrl: './column-list.component.html',
15     styleUrls: ['./column-list.component.css']
16 })
17 export class ColumnListComponent implements OnInit {
18     @ViewChild(MatPaginator, {static: false} as any) paginator: MatPaginator;
19     @ViewChild(MatSort, {static: false} as any) sort: MatSort;
20     @ViewChild(MatTable, {static: false} as any) table: MatTable<DataTableItem>;
21
22     @Input('reportId') reportId: number;
23
24
25
26     dataSource: DataTableDataSource;
27     finalGetObj: {};
28     finalEditRowGetObj: {};
29     finalObjArr: DataTableItem[];
30     status: string;
31     message: string;
32     showDialog: boolean;
33     closable: boolean;
34
35     columnId: string;
36     id: string;
37     name: string;
38     noWrap: boolean;
39     visible: boolean;
40     dependsOnFormFields: string;
41     dataType: string;
42     groupByPos: string;
43     customTextForSubTotal: string;
44     hideRepeatedValues: boolean;
45     multiGroupColumnLevel;
46     colspan: string;
47     displayName: string;
48     displayWidthInPixel: string;
49     indentation: string;
50     displayAlignment: string;
51     displayHeaderAlignment: string;
52     sortable: boolean;
53     drilldownURL: string;
54     displayTotal: string;
55     URLListObj: {};
56     URLListObjArray: {}[];
57     TotalColListObj: {};
58     TotalColListObjArray: {}[];
59     finalPOSTObj: {};
60     isDisabled: boolean;
61     showConfirmButton: boolean;
62
63     /** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
64     displayedColumns = ['no', 'id', 'name', 'edit'];
65     SQLstatus: string;
66     SQLmessage: string;
67     showSaveColDialog: boolean;
68     Colclosable: boolean;
69     EditColmessage: string;
70     EditColstatus: string;
71
72     showEditDrillDownPage: boolean;
73     showAdvancedDisplayPage = false;
74     drillDownReportId: string;
75     drilldownParams: string;
76     drilldownType: string;
77     drillDownObj: {};
78     checkCnt: number;
79     showSpinner: boolean;
80     displayTable: boolean;
81     semaphoreList: SemaphoreList;
82     semaphoreName: String;
83     semaphoreId: String;
84     private newSemaphoreList: any;
85     private addDisplay = false;
86     incomingDrillDownParams: string;
87     isIncomingDrillDownParams: boolean;
88
89     constructor(private _http: HttpClient, private _columnService: ColumnService) {
90
91         this.showEditDrillDownPage = false;
92         this.showAdvancedDisplayPage = false;
93         this.showConfirmButton = false;
94         this.addDisplay = false;
95
96         this.dataSource = new DataTableDataSource();
97
98         this.finalGetObj = new Object();
99         this.finalObjArr = new Array();
100         this.finalEditRowGetObj = new Object();
101         this.URLListObjArray = new Array();
102         this.TotalColListObjArray = new Array();
103         this.finalPOSTObj = new Object();
104         this.drillDownObj = new Object();
105         this.checkCnt = 0;
106         this.showSpinner = false;
107         this.semaphoreList = new class implements SemaphoreList {
108             semaphore: Semaphore[];
109         };
110         this.semaphoreName = 'No Display';
111         this.incomingDrillDownParams = '';
112         this.isIncomingDrillDownParams = false;
113
114     }
115
116     ngOnInit() {
117         this.showSpinner = true;
118         this.displayTable = true;
119         this._columnService.getColumnList()
120             .subscribe((response) => {
121                 this.showSpinner = true;
122                 this.finalGetObj = response;
123                 let fgo_counter = 0;
124                 while (this.finalGetObj[fgo_counter]) {
125                     this.finalGetObj[fgo_counter]['no'] = fgo_counter + 1;
126                     this.finalGetObj[fgo_counter]['edit'] = '';
127                     this.finalObjArr.push(this.finalGetObj[fgo_counter]);
128                     fgo_counter++;
129                 }
130                 this.dataSource.data = this.finalObjArr;
131                 this.dataSource.sort = this.sort;
132                 this.dataSource.paginator = this.paginator;
133                 this.table.dataSource = this.dataSource;
134                 this.dataSource.data = this.finalObjArr;
135                 this.showSpinner = false;
136             });
137         this.showDialog = false;
138         this.showSaveColDialog = false;
139
140
141     }
142
143
144     ngDoCheck() {
145         this.drillDownReportId = this.drilldownURL;
146         this.drillDownObj['drillDownUrl'] = this.drilldownURL;
147         this.drillDownObj['drillDownParams'] = this.drilldownParams;
148         this.drillDownObj['drillDownType'] = this.drilldownType;
149     }
150
151
152     editRecord(id: string) {
153         this.showSpinner = true;
154
155         this.columnId = id;
156         this._columnService.getIndividualColumnData(id)
157             .subscribe((response) => {
158                 this.finalEditRowGetObj = response;
159                 this.id = this.finalEditRowGetObj['colId'];
160                 this.name = this.finalEditRowGetObj['colName'];
161                 this.noWrap = (this.finalEditRowGetObj['noWrap'] === 'Y' ? true : false);
162                 this.visible = this.finalEditRowGetObj['visible'];
163                 this.dependsOnFormFields = this.finalEditRowGetObj['depeondsOnForField'];
164                 this.dataType = this.finalEditRowGetObj['dataType'];
165                 this.groupByPos = (this.finalEditRowGetObj['groupByPos'] == null ? 0 : this.finalEditRowGetObj['groupByPos'] );
166                 this.customTextForSubTotal = this.finalEditRowGetObj['subTotalCustomText'];
167                 this.hideRepeatedValues = this.finalEditRowGetObj['hideRepeatedKey'];
168                 this.multiGroupColumnLevel = (this.finalEditRowGetObj['level'] == null ? 0 : this.finalEditRowGetObj['level']);
169                 this.colspan  = (this.finalEditRowGetObj['colspan'] == null ? 0 : this.finalEditRowGetObj['colspan']);
170                 this.displayName = this.finalEditRowGetObj['displayName'];
171                 this.displayWidthInPixel = (this.finalEditRowGetObj['displayWidthInPixel'] == null ? 0 : this.finalEditRowGetObj['displayWidthInPixel'] );
172                 this.indentation = (this.finalEditRowGetObj['indentation'] == null ? 0 : this.finalEditRowGetObj['indentation']);
173                 this.displayAlignment = this.finalEditRowGetObj['displayAlignment'];
174                 this.displayHeaderAlignment = (this.finalEditRowGetObj['displayHeaderAlignment'] == null ? '' : this.finalEditRowGetObj['displayHeaderAlignment']);
175                 this.sortable = this.finalEditRowGetObj['sortable'];
176                 this.drilldownURL = this.finalEditRowGetObj['drilldownURL'];
177                 this.drilldownParams = this.finalEditRowGetObj['drilldownParams'];
178                 this.drilldownType = this.finalEditRowGetObj['drilldownType'];
179                 this.drillDownObj['drillDownUrl'] = this.drilldownURL;
180                 this.drillDownObj['drillDownParams'] = this.drilldownParams;
181                 this.drillDownObj['drillDownType'] = this.drilldownType;
182                 this.semaphoreList =  this.finalEditRowGetObj['semaphoreList'];
183                 this.semaphoreId = this.finalEditRowGetObj['semaphoreId'];
184                 if (this.semaphoreId === '') {
185                     this.semaphoreName = 'No Display';
186                 } else {
187                     if(this.semaphoreList && this.semaphoreList.semaphore){
188                         for (let semCtr = 0; semCtr < this.semaphoreList.semaphore.length; semCtr++) {
189                             if (this.semaphoreId === this.semaphoreList.semaphore[semCtr]['semaphoreId']) {
190                                 this.semaphoreName = this.semaphoreList.semaphore[semCtr]['semaphoreName'];
191                             }
192                         }
193                     }
194                 }
195                 this. displayTotal = (this.finalEditRowGetObj['displayTotal'] == null ? '' : this.finalEditRowGetObj['displayTotal']);
196                 this._columnService.getDrillDownReportList()
197                     .subscribe((responseURLList) => {
198                         this.URLListObj = responseURLList;
199
200                         let listCtr = 0;
201                         while (this.URLListObj[listCtr]) {
202                             this.URLListObjArray.push(this.URLListObj[listCtr]);
203                             listCtr++;
204                         }
205                     });
206
207                 this._columnService.getResponseTotalColsList()
208                     .subscribe((responseTotalColList) => {
209                         this.TotalColListObj = responseTotalColList;
210                         let colCtr = 0;
211                         while (this.TotalColListObj[colCtr]) {
212                             this.TotalColListObjArray.push(this.TotalColListObj[colCtr]);
213                             colCtr++;
214                         }
215                     });
216                 this.status = 'Success!';
217                 this.message = 'Report Column - Edit';
218                 this.showDialog = !this.showDialog;
219                 this.closable = true;
220                 this.showSpinner = false;
221             });
222     }
223
224     ngOnChanges() {
225         console.log('Hit');
226     }
227
228
229     close() {
230         this._columnService.getColumnList()
231             .subscribe((response) => {
232                 this.showSpinner = true;
233                 this.dataSource = new DataTableDataSource();
234                 this.finalObjArr = [];
235                 this.finalGetObj = response;
236
237                 let fgo_counter = 0;
238                 while (this.finalGetObj[fgo_counter]) {
239                     this.finalGetObj[fgo_counter]['no'] = fgo_counter + 1;
240                     this.finalGetObj[fgo_counter]['edit'] = '';
241                     this.finalObjArr.push(this.finalGetObj[fgo_counter]);
242                     fgo_counter++;
243                 }
244                 this.dataSource.data = this.finalObjArr;
245                 this.dataSource.sort = this.sort;
246                 this.dataSource.paginator = this.paginator;
247                 this.table.dataSource = this.dataSource;
248                 this.dataSource.data = this.finalObjArr;
249                 this.showSpinner = false;
250             });
251         this.showDialog = false;
252         this.showSaveColDialog = false;
253         this.closable = false;
254         this.showEditDrillDownPage = false;
255         this.showAdvancedDisplayPage = false;
256         this.addDisplay = false;
257         this.Colclosable = false;
258         this.showConfirmButton = false;
259     }
260
261     complete() {
262         this.showEditDrillDownPage = !this.showEditDrillDownPage;
263         this.showConfirmButton = false;
264         this.isIncomingDrillDownParams = true;
265     }
266
267     onCompleted(drilldownParamsArr: any) {
268         this.incomingDrillDownParams = drilldownParamsArr;
269     }
270
271
272     save() {
273
274         this.showSpinner = true;
275
276         this.finalPOSTObj['tabId'] = 'ColEdit';
277         this.finalPOSTObj['tabName'] = 'Column Edit';
278
279         this.finalPOSTObj['colId'] = this.id;
280         this.finalPOSTObj['colName'] = this.name;
281
282         this.finalPOSTObj['colType'] = '';
283         this.finalPOSTObj['colspan'] = this.colspan;
284         this.finalPOSTObj['dataType'] = this.dataType;
285         this.finalPOSTObj['depeondsOnForField'] = this.dependsOnFormFields;
286         this.finalPOSTObj['displayAlignment'] = this.displayAlignment;
287         this.finalPOSTObj['displayHeaderAlignment'] = this.displayHeaderAlignment;
288         this.finalPOSTObj['displayName'] = this.displayName;
289         this.finalPOSTObj['displayTotal'] = this.displayTotal;
290         this.finalPOSTObj['displayWidth'] = 10;
291         this.finalPOSTObj['displayWidthInPixel'] = this.displayWidthInPixel;
292         if (this.isIncomingDrillDownParams) {
293             this.finalPOSTObj['drilldownParams'] = this.incomingDrillDownParams;
294         } else {
295             this.finalPOSTObj['drilldownParams'] = this.drilldownParams;
296         }
297         this.finalPOSTObj['drilldownType'] = '';
298         this.finalPOSTObj['drilldownURL'] = this.drilldownURL;
299         this.finalPOSTObj['errorMessage'] = '';
300         this.finalPOSTObj['errorStackTrace'] = '';
301         this.finalPOSTObj['groupByPos'] = this.groupByPos;
302         this.finalPOSTObj['hideRepeatedKey'] = this.hideRepeatedValues;
303         this.finalPOSTObj['indentation'] = this.indentation;
304         this.finalPOSTObj['level'] = this.multiGroupColumnLevel;
305         this.finalPOSTObj['noWrap'] = (this.noWrap === true ? 'Y' : 'N');
306         this.finalPOSTObj['sortable'] = this.sortable;
307         this.finalPOSTObj['subTotalCustomText'] = this.displayTotal;
308         this.finalPOSTObj['visible'] = this.visible;
309         if (this.semaphoreName === 'No Display') {
310             this.semaphoreId = '';
311         } else {
312             for ( let slcount = 0 ; slcount < this.semaphoreList.semaphore.length; slcount++) {
313                 if (this.semaphoreName === this.semaphoreList.semaphore[slcount].semaphoreName) {
314                     this.semaphoreId = this.semaphoreList.semaphore[slcount].semaphoreId;
315                 }
316             }
317         }
318         this.finalPOSTObj['semaphoreId'] = this.semaphoreId;
319         this.finalPOSTObj['semaphoreList'] = this.semaphoreList;
320
321
322         this._columnService.postColumnChanges(this.finalPOSTObj)
323             .subscribe((finalPOSTResponse) => {
324
325                 if (finalPOSTResponse) {
326                     this.EditColstatus = 'Success!';
327                     this.EditColmessage = 'Your change has been saved! Row definition is updated.';
328                     this.showSaveColDialog = !this.showSaveColDialog;
329
330                     this.Colclosable = true;
331
332                 } else {
333                     this.EditColstatus = 'Failure!';
334                     this.EditColmessage = 'Row definition could not be updated.';
335                     this.showSaveColDialog = !this.showSaveColDialog;
336
337                     this.Colclosable = true;
338                 }
339
340                 this.showEditDrillDownPage = false;
341                 this.showAdvancedDisplayPage = false;
342                 this.isIncomingDrillDownParams = false;
343                 this.addDisplay = false;
344                 this.showSpinner = false;
345             });
346
347     }
348
349
350     drillDownLinkPage() {
351         this.showEditDrillDownPage = !this.showEditDrillDownPage;
352         this.showConfirmButton = true;
353     }
354
355     editDisplay() {
356         this.showAdvancedDisplayPage = true;
357     }
358
359
360     finishAdvancedDisplay(displayObj: any) {
361         this.addDisplay = false;
362         this.semaphoreName = displayObj['semName'];
363         this.semaphoreList = displayObj['semList'];
364         this.semaphoreId = displayObj['semId'];
365         this.showAdvancedDisplayPage = displayObj['setCloseDisplay'];
366     }
367
368     addNewDisplay() {
369         this.showAdvancedDisplayPage = true;
370         this.addDisplay = true;
371     }
372 }