From: Galen Charlton <gmc@equinoxinitiative.org>
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=3447fbc0928afdea02a321f51e8f8f8030e39ffb;p=evergreen%2Fequinox.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 <gmc@equinoxinitiative.org>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
---

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">
   <eg-grid-toolbar-action label="Action that needs a single row" i18n-label
     (onClick)="complimentEvergreen($event)" [disableOnRows]="notOneSelectedRow">
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<ComboboxEntry>;
 
     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) {