From: Galen Charlton Date: Fri, 3 Jan 2020 16:33:19 +0000 (-0500) Subject: LP#1835982: add GridCellTextGenerator to the btGrid in the sandbox X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d9ed4e71d2092634eb82684d629fcd154cecc880;p=working%2FEvergreen.git 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 --- 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 23c22f2bef..3a275eb8d6 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.ts @@ -390,6 +390,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 ed1b5813b4..4605ab3321 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 0dc8ee05f6..3992b71a58 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(); editSelected: (rows: IdlObject[]) => void; @ViewChild('acpGrid', { static: true }) acpGrid: GridComponent; @@ -200,6 +201,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) {