import {ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit, ViewChild} from '@angular/core'; import {MatPaginator} from '@angular/material/paginator'; import {MatSort} from '@angular/material/sort'; import {MatTable} from '@angular/material/table'; import {DataTableDataSource, DataTableItem} from './column-list-datasource'; import {HttpClient} from '@angular/common/http'; import {ColumnService} from '../column.service'; import {SemaphoreList} from '../model/semaphore-list'; import {Semaphore} from '../model/semaphore'; @Component({ selector: 'app-column-list', templateUrl: './column-list.component.html', styleUrls: ['./column-list.component.css'], }) export class ColumnListComponent implements OnInit { @ViewChild(MatPaginator, {static: false} as any) paginator: MatPaginator; @ViewChild(MatSort, {static: false} as any) sort: MatSort; @ViewChild(MatTable, {static: false} as any) table: MatTable; @Input('reportId') reportId: number; dataSource: DataTableDataSource; finalGetObj: {}; finalEditRowGetObj: {}; finalObjArr: DataTableItem[]; status: string; message: string; showDialog: boolean; closable: boolean; columnId: string; id: string; name: string; noWrap: boolean; visible: boolean; dependsOnFormFields: string; dataType: string; groupByPos: string; customTextForSubTotal: string; hideRepeatedValues: boolean; multiGroupColumnLevel; colspan: string; displayName: string; displayWidthInPixel: string; indentation: string; displayAlignment: string; displayHeaderAlignment: string; sortable: boolean; drilldownURL: string; displayTotal: string; URLListObj: {}; URLListObjArray: {}[]; TotalColListObj: {}; TotalColListObjArray: {}[]; finalPOSTObj: {}; isDisabled: boolean; showConfirmButton: boolean; SQLstatus: string; SQLmessage: string; showSaveColDialog: boolean; Colclosable: boolean; EditColmessage: string; EditColstatus: string; showEditDrillDownPage: boolean; showAdvancedDisplayPage = false; drillDownReportId: string; drilldownParams: string; drilldownType: string; drillDownObj: {}; checkCnt: number; showSpinner: boolean; displayTable: boolean; semaphoreList: SemaphoreList; semaphoreName: String; semaphoreId: String; incomingDrillDownParams: string; isIncomingDrillDownParams: boolean; SQLclosable: any; private newSemaphoreList: any; private addDisplay = false; columnList: any; isCrossTab: boolean; displayedColumns: any; crossTabValue: String; displaymsg: boolean; checkRowHeading: boolean; checkCoumnHeading: boolean; checkValue: boolean; crossTabValuesArr: any; constructor(private _http: HttpClient, private _columnService: ColumnService, private changeDetectorRefs: ChangeDetectorRef) { this.showEditDrillDownPage = false; this.showAdvancedDisplayPage = false; this.showConfirmButton = false; this.addDisplay = false; this.dataSource = new DataTableDataSource(); this.finalGetObj = {}; this.finalObjArr = []; this.finalEditRowGetObj = {}; this.URLListObjArray = []; this.TotalColListObjArray = []; this.finalPOSTObj = {}; this.drillDownObj = {}; this.checkCnt = 0; this.showSpinner = false; this.semaphoreList = new class implements SemaphoreList { semaphore: Semaphore[]; }; this.semaphoreName = 'No Display'; this.semaphoreId = ''; this.incomingDrillDownParams = ''; this.isIncomingDrillDownParams = false; this.isCrossTab = false; this.displaymsg = false; this.crossTabValuesArr = []; } ngOnInit() { this.displayTable = true; this._columnService.getColumnList() .subscribe((response) => { this.showSpinner = true; this.finalGetObj = response; this.columnList = response; let fgo_counter = 0; while (this.finalGetObj[fgo_counter]) { this.finalGetObj[fgo_counter]['no'] = fgo_counter + 1; this.finalGetObj[fgo_counter]['edit'] = ''; this.finalObjArr.push(this.finalGetObj[fgo_counter]); if (this.finalGetObj[fgo_counter]['crossTabValue'] !== null && this.finalGetObj[fgo_counter]['crossTabValue'] !== 'Cross-Tab') { this.isCrossTab = true; } fgo_counter++; } for (let i = 0; i < this.finalObjArr.length; i++) { this.crossTabValuesArr.push(this.finalObjArr[i]['crossTabValue']) } if (this.crossTabValuesArr.includes('Row headings')) this.checkRowHeading = true; if (this.crossTabValuesArr.includes('Column headings')) this.checkCoumnHeading = true; if (this.crossTabValuesArr.includes('Report values')) this.checkValue = true; if (this.isCrossTab) { if (this.checkRowHeading && this.checkCoumnHeading && this.checkValue) { this.displaymsg = false; } else { this.displaymsg = true; } } if (this.isCrossTab) { this.displayedColumns = ['no', 'id', 'name', 'Cross-Tab Usage', 'edit']; } else { this.displayedColumns = ['no', 'id', 'name', 'edit']; } this.dataSource.data = this.finalObjArr; this.dataSource.sort = this.sort; this.dataSource.paginator = this.paginator; this.table.dataSource = this.dataSource; this.dataSource.data = this.finalObjArr; this.showSpinner = false; }); this.showDialog = false; this.showSaveColDialog = false; } ngDoCheck() { this.drillDownReportId = this.drilldownURL; this.drillDownObj['drillDownUrl'] = this.drilldownURL; this.drillDownObj['drillDownParams'] = this.drilldownParams; this.drillDownObj['drillDownType'] = this.drilldownType; } editRecord(id: string) { this.showSpinner = true; this.semaphoreList = new class implements SemaphoreList { semaphore: Semaphore[]; }; this.semaphoreName = 'No Display'; this.semaphoreId = ''; this.columnId = id; this._columnService.getIndividualColumnData(id) .subscribe((response) => { this.finalEditRowGetObj = response; this.id = this.finalEditRowGetObj['colId']; this.name = this.finalEditRowGetObj['colName']; this.noWrap = (this.finalEditRowGetObj['noWrap'] === 'Y' ? true : false); this.visible = this.finalEditRowGetObj['visible']; this.dependsOnFormFields = this.finalEditRowGetObj['depeondsOnForField']; this.dataType = this.finalEditRowGetObj['dataType']; this.groupByPos = (this.finalEditRowGetObj['groupByPos'] == null ? 0 : this.finalEditRowGetObj['groupByPos']); this.customTextForSubTotal = this.finalEditRowGetObj['subTotalCustomText']; this.hideRepeatedValues = this.finalEditRowGetObj['hideRepeatedKey']; this.multiGroupColumnLevel = (this.finalEditRowGetObj['level'] == null ? 0 : this.finalEditRowGetObj['level']); this.colspan = (this.finalEditRowGetObj['colspan'] == null ? 0 : this.finalEditRowGetObj['colspan']); this.displayName = this.finalEditRowGetObj['displayName']; this.displayWidthInPixel = (this.finalEditRowGetObj['displayWidthInPixel'] == null ? 0 : this.finalEditRowGetObj['displayWidthInPixel']); this.indentation = (this.finalEditRowGetObj['indentation'] == null ? 0 : this.finalEditRowGetObj['indentation']); this.displayAlignment = this.finalEditRowGetObj['displayAlignment']; this.displayHeaderAlignment = (this.finalEditRowGetObj['displayHeaderAlignment'] == null ? '' : this.finalEditRowGetObj['displayHeaderAlignment']); this.sortable = this.finalEditRowGetObj['sortable']; this.drilldownURL = this.finalEditRowGetObj['drilldownURL']; this.drilldownParams = this.finalEditRowGetObj['drilldownParams']; this.drilldownType = this.finalEditRowGetObj['drilldownType']; this.drillDownObj['drillDownUrl'] = this.drilldownURL; this.drillDownObj['drillDownParams'] = this.drilldownParams; this.drillDownObj['drillDownType'] = this.drilldownType; this.semaphoreList = this.finalEditRowGetObj['semaphoreList']; this.semaphoreId = this.finalEditRowGetObj['semaphoreId']; if (this.isCrossTab) { this.crossTabValue = this.finalEditRowGetObj['crossTabValue']; } if (this.semaphoreId === '') { this.semaphoreName = 'No Display'; } else { if(this.semaphoreList && this.semaphoreList.semaphore){ for (let semCtr = 0; semCtr < this.semaphoreList.semaphore.length; semCtr++) { if (this.semaphoreId === this.semaphoreList.semaphore[semCtr]['semaphoreId']) { this.semaphoreName = this.semaphoreList.semaphore[semCtr]['semaphoreName']; } } } } this.displayTotal = (this.finalEditRowGetObj['displayTotal'] == null ? '' : this.finalEditRowGetObj['displayTotal']); this._columnService.getDrillDownReportList() .subscribe((responseURLList) => { this.URLListObj = responseURLList; let listCtr = 0; while (this.URLListObj[listCtr]) { this.URLListObjArray.push(this.URLListObj[listCtr]); listCtr++; } }); this._columnService.getResponseTotalColsList() .subscribe((responseTotalColList) => { this.TotalColListObj = responseTotalColList; let colCtr = 0; while (this.TotalColListObj[colCtr]) { this.TotalColListObjArray.push(this.TotalColListObj[colCtr]); colCtr++; } }); this.status = 'Success!'; this.message = 'Report Column - Edit'; this.showDialog = !this.showDialog; this.closable = true; this.showSpinner = false; }); } ngOnChanges() { console.log('Hit'); } close() { this.changeDetectorRefs.detectChanges(); this._columnService.getColumnList() .subscribe((response) => { this.showSpinner = true; this.dataSource = new DataTableDataSource(); this.finalObjArr = []; this.finalGetObj = response; let fgo_counter = 0; while (this.finalGetObj[fgo_counter]) { this.finalGetObj[fgo_counter]['no'] = fgo_counter + 1; this.finalGetObj[fgo_counter]['edit'] = ''; this.finalObjArr.push(this.finalGetObj[fgo_counter]); fgo_counter++; } this.crossTabValuesArr = []; this.checkRowHeading = false; this.checkCoumnHeading = false; this.checkValue = false; for (let i = 0; i < this.finalObjArr.length; i++) { this.crossTabValuesArr.push(this.finalObjArr[i]['crossTabValue']) } if (this.crossTabValuesArr.includes('Row headings')) this.checkRowHeading = true; if (this.crossTabValuesArr.includes('Column headings')) this.checkCoumnHeading = true; if (this.crossTabValuesArr.includes('Report values')) this.checkValue = true; if (this.isCrossTab) { if (this.checkRowHeading && this.checkCoumnHeading && this.checkValue) { this.displaymsg = false; } else { this.displaymsg = true; } } this.dataSource.data = this.finalObjArr; this.dataSource.sort = this.sort; this.dataSource.paginator = this.paginator; this.table.dataSource = this.dataSource; this.dataSource.data = this.finalObjArr; this.showSpinner = false; }); this.showDialog = false; this.showSaveColDialog = false; this.closable = false; this.showEditDrillDownPage = false; this.showAdvancedDisplayPage = false; this.addDisplay = false; this.Colclosable = false; this.showConfirmButton = false; this.changeDetectorRefs.detectChanges(); } complete() { this.showEditDrillDownPage = !this.showEditDrillDownPage; this.showConfirmButton = false; this.isIncomingDrillDownParams = true; } onCompleted(drilldownParamsArr: any) { this.incomingDrillDownParams = drilldownParamsArr; } save() { this.changeDetectorRefs.detectChanges(); this.showSpinner = true; this.finalPOSTObj['tabId'] = 'ColEdit'; this.finalPOSTObj['tabName'] = 'Column Edit'; this.finalPOSTObj['colId'] = this.id; this.finalPOSTObj['colName'] = this.name; this.finalPOSTObj['colType'] = ''; this.finalPOSTObj['colspan'] = this.colspan; this.finalPOSTObj['dataType'] = this.dataType; this.finalPOSTObj['depeondsOnForField'] = this.dependsOnFormFields; this.finalPOSTObj['displayAlignment'] = this.displayAlignment; this.finalPOSTObj['displayHeaderAlignment'] = this.displayHeaderAlignment; this.finalPOSTObj['displayName'] = this.displayName; this.finalPOSTObj['displayTotal'] = this.displayTotal; this.finalPOSTObj['displayWidth'] = 10; this.finalPOSTObj['displayWidthInPixel'] = this.displayWidthInPixel; if (this.isIncomingDrillDownParams) { this.finalPOSTObj['drilldownParams'] = this.incomingDrillDownParams; } else { this.finalPOSTObj['drilldownParams'] = this.drilldownParams; } this.finalPOSTObj['drilldownType'] = ''; this.finalPOSTObj['drilldownURL'] = this.drilldownURL; this.finalPOSTObj['errorMessage'] = ''; this.finalPOSTObj['errorStackTrace'] = ''; this.finalPOSTObj['groupByPos'] = this.groupByPos; this.finalPOSTObj['hideRepeatedKey'] = this.hideRepeatedValues; this.finalPOSTObj['indentation'] = this.indentation; this.finalPOSTObj['level'] = this.multiGroupColumnLevel; this.finalPOSTObj['noWrap'] = (this.noWrap === true ? 'Y' : 'N'); this.finalPOSTObj['sortable'] = this.sortable; this.finalPOSTObj['subTotalCustomText'] = this.displayTotal; if (this.isCrossTab) { this.finalPOSTObj['crossTabValue'] = this.crossTabValue; } this.finalPOSTObj['visible'] = this.visible; if (this.semaphoreName === 'No Display') { this.semaphoreId = ''; } else { if(this.semaphoreList && this.semaphoreList.semaphore){ for (let slcount = 0; slcount < this.semaphoreList.semaphore.length; slcount++) { if (this.semaphoreName === this.semaphoreList.semaphore[slcount].semaphoreName) { this.semaphoreId = this.semaphoreList.semaphore[slcount].semaphoreId; this.semaphoreList.semaphore[slcount].comment = this.id; } } } } this.finalPOSTObj['semaphoreId'] = this.semaphoreId; this.finalPOSTObj['semaphoreList'] = this.semaphoreList; this._columnService.postColumnChanges(this.finalPOSTObj) .subscribe((finalPOSTResponse) => { if (finalPOSTResponse) { this.EditColstatus = 'Success!'; this.EditColmessage = 'Your change has been saved! Row definition is updated.'; this.showSaveColDialog = !this.showSaveColDialog; this.Colclosable = true; } else { this.EditColstatus = 'Failure!'; this.EditColmessage = 'Row definition could not be updated.'; this.showSaveColDialog = !this.showSaveColDialog; this.Colclosable = true; } this.showEditDrillDownPage = false; this.showAdvancedDisplayPage = false; this.isIncomingDrillDownParams = false; this.addDisplay = false; this.showSpinner = false; }); } drillDownLinkPage() { this.showEditDrillDownPage = !this.showEditDrillDownPage; this.showConfirmButton = true; } editDisplay() { this.showAdvancedDisplayPage = true; } finishAdvancedDisplay(displayObj: any) { this.addDisplay = false; this.semaphoreName = displayObj['semName']; this.semaphoreList = displayObj['semList']; this.semaphoreId = displayObj['semId']; this.showAdvancedDisplayPage = displayObj['setCloseDisplay']; } addNewDisplay() { this.showAdvancedDisplayPage = true; this.addDisplay = true; } }