From 3447fbc0928afdea02a321f51e8f8f8030e39ffb Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 3 Jan 2020 11:33:19 -0500 Subject: [PATCH] LP#1835982: add GridCellTextGenerator to the btGrid in the sandbox This patch also adds a usage note: since the GridCellTextGenerator only has access to the row object but a cellTemplate can be passed arbitrary context in addition to the row, a GridCellTextGenerator that needs that additional context to have the print content match the displayed content may require that the caller stick it in the row object. Signed-off-by: Galen Charlton Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg --- Open-ILS/src/eg2/src/app/share/grid/grid.ts | 7 +++++++ .../eg2/src/app/staff/sandbox/sandbox.component.html | 1 + .../eg2/src/app/staff/sandbox/sandbox.component.ts | 11 ++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid.ts b/Open-ILS/src/eg2/src/app/share/grid/grid.ts index 93094c3398..59baa63ef4 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.ts @@ -399,6 +399,13 @@ export class GridColumnSet { // each mapped column on a given row. This is primarily useful for // generating print-friendly content for grid cells rendered via // cellTemplate. +// +// USAGE NOTE: Since a cellTemplate can be passed arbitrary context +// but a GridCellTextGenerator only gets the row object, +// if it's important to include content that's not available +// by default in the row object, you may want to stick +// it in the row object as an additional attribute. +// export interface GridCellTextGenerator { [columnName: string]: (row: any) => string; } diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html index d456ae08a3..3b9609b399 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html @@ -217,6 +217,7 @@ [rowFlairCallback]="btGridRowFlairCallback" [cellClassCallback]="btGridCellClassCallback" [stickyHeader]="true" + [cellTextGenerator]="btGridCellTextGenerator" [sortable]="true"> diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts index 13cd009d60..c44a7f7a0b 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts @@ -5,7 +5,7 @@ import {ProgressDialogComponent} from '@eg/share/dialog/progress.component'; import {ToastService} from '@eg/share/toast/toast.service'; import {StringService} from '@eg/share/string/string.service'; import {map, take} from 'rxjs/operators'; -import {GridDataSource, GridColumn, GridRowFlairEntry} from '@eg/share/grid/grid'; +import {GridDataSource, GridColumn, GridRowFlairEntry, GridCellTextGenerator} from '@eg/share/grid/grid'; import {IdlService, IdlObject} from '@eg/core/idl.service'; import {PcrudService} from '@eg/core/pcrud.service'; import {OrgService} from '@eg/core/org.service'; @@ -62,6 +62,7 @@ export class SandboxComponent implements OnInit { cbAsyncSource: (term: string) => Observable; btSource: GridDataSource = new GridDataSource(); + btGridCellTextGenerator: GridCellTextGenerator; acpSource: GridDataSource = new GridDataSource(); eventsDataSource: GridDataSource = new GridDataSource(); editSelected: (rows: IdlObject[]) => void; @@ -201,6 +202,14 @@ export class SandboxComponent implements OnInit { })); }; + // GridCellTextGenerator for the btGrid; note that this + // also demonstrates that a GridCellTextGenerator only has + // access to the row, and does not have access to any additional + // context that might be passed to a cellTemplate + this.btGridCellTextGenerator = { + test: row => 'HELLO universe ' + row.id() + }; + this.acpSource.getRows = (pager: Pager, sort: any[]) => { const orderBy: any = {acp: 'id'}; if (sort.length) { -- 2.43.2