-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from UCI-IN4MATX-191-Token-ATM/feature-token-o…
…ption-grid-view Feature: grid view for token options
- Loading branch information
Showing
41 changed files
with
1,187 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/app/components/grid-view-display/grid-view-display.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<ag-grid-angular | ||
*ngIf="gridViewData && gridViewColDef" | ||
class="ag-theme-alpine w-100 h-100" | ||
[rowData]="gridViewData" | ||
[columnDefs]="gridViewColDef" | ||
[enableCellTextSelection]="true" | ||
(firstDataRendered)="onFirstDataRendered($event)" | ||
(displayedColumnsChanged)="columnChange.emit($event)" | ||
></ag-grid-angular> |
Empty file.
22 changes: 22 additions & 0 deletions
22
src/app/components/grid-view-display/grid-view-display.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
// import { GridViewDisplayComponent } from './grid-view-display.component'; | ||
|
||
// describe('GridViewDisplayComponent', () => { | ||
// let component: GridViewDisplayComponent; | ||
// let fixture: ComponentFixture<GridViewDisplayComponent>; | ||
|
||
// beforeEach(async () => { | ||
// await TestBed.configureTestingModule({ | ||
// declarations: [GridViewDisplayComponent] | ||
// }).compileComponents(); | ||
|
||
// fixture = TestBed.createComponent(GridViewDisplayComponent); | ||
// component = fixture.componentInstance; | ||
// fixture.detectChanges(); | ||
// }); | ||
|
||
// it('should create', () => { | ||
// expect(component).toBeTruthy(); | ||
// }); | ||
// }); |
103 changes: 103 additions & 0 deletions
103
src/app/components/grid-view-display/grid-view-display.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { Component, EventEmitter, Input, Output } from '@angular/core'; | ||
import type { | ||
ColDef, | ||
DisplayedColumnsChangedEvent, | ||
FirstDataRenderedEvent, | ||
ICellRendererParams, | ||
ValueFormatterParams | ||
} from 'ag-grid-community'; | ||
import type { GridViewData, GridViewDataPoint } from 'app/token-options/mixins/grid-view-data-source-mixin'; | ||
import { format } from 'date-fns'; | ||
|
||
type AGGridDataSource = { | ||
[key in string]: GridViewDataPoint['value']; | ||
}; | ||
|
||
@Component({ | ||
selector: 'app-grid-view-display', | ||
templateUrl: './grid-view-display.component.html', | ||
styleUrls: ['./grid-view-display.component.sass'] | ||
}) | ||
export class GridViewDisplayComponent { | ||
gridViewColDef?: ColDef<AGGridDataSource, GridViewDataPoint['value']>[]; | ||
gridViewData?: AGGridDataSource[]; | ||
@Output() columnChange = new EventEmitter<DisplayedColumnsChangedEvent>(); | ||
|
||
@Input() set data(data: [GridViewData[], string[]] | undefined) { | ||
this.gridViewColDef = undefined; | ||
this.gridViewData = undefined; | ||
if (!data) return; | ||
const [dataArray, colPreferences] = data; | ||
const columns: [string, string][] = [], | ||
colSet = new Set<string>(); | ||
this.gridViewData = []; | ||
for (const data of dataArray) { | ||
const dataObj: AGGridDataSource = {}; | ||
for (const entry of data.data) { | ||
const colIdentifier = JSON.stringify([entry.colName, entry.type]); | ||
dataObj[colIdentifier] = entry.value; | ||
if (colSet.has(colIdentifier)) continue; | ||
colSet.add(colIdentifier); | ||
columns.push([entry.colName, entry.type]); | ||
} | ||
this.gridViewData.push(dataObj); | ||
} | ||
this.gridViewColDef = columns.map(([name, type]) => { | ||
const colDef: ColDef<AGGridDataSource, GridViewDataPoint['value']> = { | ||
headerName: name, | ||
field: JSON.stringify([name, type]), | ||
resizable: true, | ||
wrapHeaderText: true, | ||
wrapText: true, | ||
autoHeaderHeight: true, | ||
autoHeight: true, | ||
sortable: true, | ||
filter: true | ||
}; | ||
switch (type) { | ||
case 'number': { | ||
colDef.cellDataType = 'number'; | ||
break; | ||
} | ||
case 'percentage': { | ||
colDef.cellDataType = 'number'; | ||
// TODO: custom formatting & sorting | ||
break; | ||
} | ||
case 'string': { | ||
colDef.cellDataType = 'text'; | ||
break; | ||
} | ||
case 'html': { | ||
colDef.cellRenderer = (params: ICellRendererParams) => params.value ?? ''; | ||
delete colDef.wrapText; | ||
delete colDef.sortable; | ||
delete colDef.filter; | ||
break; | ||
} | ||
case 'date': { | ||
colDef.cellDataType = 'date'; | ||
colDef.valueFormatter = ( | ||
params: ValueFormatterParams<AGGridDataSource, GridViewDataPoint['value']> | ||
) => (params.value instanceof Date ? format(params.value, 'MMM dd, yyyy HH:mm:ss') : ''); | ||
} | ||
} | ||
return colDef; | ||
}); | ||
const colOrdering = new Map<string, number>(), | ||
colPrefSet = new Set(colPreferences); | ||
for (const [ind, v] of colPreferences.entries()) { | ||
colOrdering.set(v, ind); | ||
} | ||
this.gridViewColDef.sort( | ||
(a, b) => (colOrdering.get(a.headerName as string) ?? -1) - (colOrdering.get(b.headerName as string) ?? -1) | ||
); | ||
for (const colDef of this.gridViewColDef) { | ||
if (!colPrefSet.has(colDef.headerName as string)) colDef.hide = true; | ||
} | ||
} | ||
|
||
onFirstDataRendered(event: FirstDataRenderedEvent) { | ||
event.columnApi.autoSizeAllColumns(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/app/components/grid-view-external-access/grid-view-external-access.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="vw-100 vh-100"> | ||
<app-grid-view-display [data]="data"></app-grid-view-display> | ||
</div> |
Empty file.
22 changes: 22 additions & 0 deletions
22
src/app/components/grid-view-external-access/grid-view-external-access.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
// import { GridViewExternalAccessComponent } from './grid-view-external-access.component'; | ||
|
||
// describe('GridViewExternalAccessComponent', () => { | ||
// let component: GridViewExternalAccessComponent; | ||
// let fixture: ComponentFixture<GridViewExternalAccessComponent>; | ||
|
||
// beforeEach(async () => { | ||
// await TestBed.configureTestingModule({ | ||
// declarations: [GridViewExternalAccessComponent] | ||
// }).compileComponents(); | ||
|
||
// fixture = TestBed.createComponent(GridViewExternalAccessComponent); | ||
// component = fixture.componentInstance; | ||
// fixture.detectChanges(); | ||
// }); | ||
|
||
// it('should create', () => { | ||
// expect(component).toBeTruthy(); | ||
// }); | ||
// }); |
43 changes: 43 additions & 0 deletions
43
src/app/components/grid-view-external-access/grid-view-external-access.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Component, Inject, OnDestroy } from '@angular/core'; | ||
import { NavigationEnd, Router } from '@angular/router'; | ||
import type { GridViewData } from 'app/token-options/mixins/grid-view-data-source-mixin'; | ||
import type { Subscription } from 'rxjs'; | ||
|
||
@Component({ | ||
selector: 'app-grid-view-external-access', | ||
templateUrl: './grid-view-external-access.component.html', | ||
styleUrls: ['./grid-view-external-access.component.sass'] | ||
}) | ||
export class GridViewExternalAccessComponent implements OnDestroy { | ||
private isListenerActive = false; | ||
data?: [GridViewData[], string[]]; | ||
subscription?: Subscription; | ||
|
||
messageListener = ( | ||
event: MessageEvent<{ | ||
type: 'GRID_VIEW_DATA'; | ||
value: [GridViewData[], string[]]; | ||
}> | ||
) => { | ||
if (event.origin != window.location.origin) return; | ||
if (event.data.type != 'GRID_VIEW_DATA') return; | ||
this.data = event.data.value; | ||
window.removeEventListener('message', this.messageListener); | ||
this.isListenerActive = false; | ||
}; | ||
|
||
constructor(@Inject(Router) private router: Router) { | ||
this.subscription = this.router.events.subscribe((event) => { | ||
if (!(event instanceof NavigationEnd)) return; | ||
if (!(event.url == '/grid-view')) return; | ||
if (this.isListenerActive) return; | ||
window.addEventListener('message', this.messageListener); | ||
this.isListenerActive = true; | ||
}); | ||
} | ||
|
||
ngOnDestroy(): void { | ||
if (!this.isListenerActive) window.removeEventListener('message', this.messageListener); | ||
if (this.subscription) this.subscription.unsubscribe(); | ||
} | ||
} |
Oops, something went wrong.