import { AfterViewInit, Component, OnInit, ViewChild, SimpleChange, Input, Output } 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 { environment } from '../../../../../../../environments/environment'; 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; /** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */ displayedColumns = ['no', 'id', 'name', 'edit']; 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; private newSemaphoreList: any; private addDisplay = false; incomingDrillDownParams: string; isIncomingDrillDownParams: boolean; constructor(private _http: HttpClient, private _columnService: ColumnService) { this.showEditDrillDownPage = false; this.showAdvancedDisplayPage = false; this.showConfirmButton = false; this.addDisplay = false; this.dataSource = new DataTableDataSource(); this.finalGetObj = new Object(); this.finalObjArr = new Array(); this.finalEditRowGetObj = new Object(); this.URLListObjArray = new Array(); this.TotalColListObjArray = new Array(); this.finalPOSTObj = new Object(); this.drillDownObj = new Object(); this.checkCnt = 0; this.showSpinner = false; this.semaphoreList = new class implements SemaphoreList { semaphore: Semaphore[]; }; this.semaphoreName = 'No Display'; this.incomingDrillDownParams = ''; this.isIncomingDrillDownParams = false; } ngOnInit() { this.showSpinner = true; this.displayTable = true; this._columnService.getColumnList() .subscribe((response) => { this.showSpinner = true; 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.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.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.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._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.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; } complete() { this.showEditDrillDownPage = !this.showEditDrillDownPage; this.showConfirmButton = false; this.isIncomingDrillDownParams = true; } onCompleted(drilldownParamsArr: any) { this.incomingDrillDownParams = drilldownParamsArr; } save() { 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; this.finalPOSTObj['visible'] = this.visible; if (this.semaphoreName === 'No Display') { this.semaphoreId = ''; } else { 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.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; } }