From a35868d2ab33d15ace33643bba99d676d90aff53 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 16 Jul 2019 12:10:36 -0400 Subject: [PATCH] LP1835982 Grid cell print values option Allow grid callers to implement functions that return plain text (printable) values for a given cell. These are primarily useful when a cell is rendered via cellTemplate, which may not produce content which is ideal for printing. Such functions are specified by the cellPrintValue attribute in the eg-grid-column element. Includes sample implementation for the Angular record detail copies grid, which uses several cellTemplate cells. Signed-off-by: Bill Erickson Signed-off-by: Galen Charlton Signed-off-by: Jane Sandberg --- .../src/app/share/grid/grid-column.component.ts | 2 ++ Open-ILS/src/eg2/src/app/share/grid/grid.ts | 16 ++++++++++++---- .../staff/catalog/record/copies.component.html | 9 +++++---- .../staff/catalog/record/copies.component.ts | 17 ++++++++++++++++- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts index c612eb42fd..57af2e8861 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts @@ -39,6 +39,7 @@ export class GridColumnComponent implements OnInit { // Used in conjunction with cellTemplate @Input() cellContext: any; @Input() cellTemplate: TemplateRef; + @Input() cellPrintValue: (row: any, cell: GridColumn) => string; @Input() disableTooltip: boolean; @@ -60,6 +61,7 @@ export class GridColumnComponent implements OnInit { col.hidden = this.hidden === true; col.isIndex = this.index === true; col.cellTemplate = this.cellTemplate; + col.cellPrintValue = this.cellPrintValue; col.cellContext = this.cellContext; col.disableTooltip = this.disableTooltip; col.isSortable = this.sortable; 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 87dfc2bd9a..42bd982f43 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.ts @@ -30,6 +30,11 @@ export class GridColumn { ternaryBool: boolean; timezoneContextOrg: number; cellTemplate: TemplateRef; + + // Provide a way for cells that are generated via cellTemplate's + // to provide an alternate text value suitable for printing. + cellPrintValue: (row: any, cell: GridColumn) => string; + cellContext: any; isIndex: boolean; isDragTarget: boolean; @@ -805,11 +810,14 @@ export class GridContext { getColumnTextContent(row: any, col: GridColumn): string { - if (col.cellTemplate) { - // TODO - // Extract the text content from the rendered template. + if (col.cellPrintValue) { + return col.cellPrintValue(row, col); } else { - return this.getRowColumnValue(row, col); + if (col.cellTemplate) { + return ''; // avoid 'undefined' values + } else { + return this.getRowColumnValue(row, col); + } } } diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/copies.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/record/copies.component.html index 7ee041ffee..4c2f10f494 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/record/copies.component.html +++ b/Open-ILS/src/eg2/src/app/staff/catalog/record/copies.component.html @@ -44,11 +44,11 @@ - + + [cellTemplate]="barcodeTemplate" [cellPrintValue]="cellPrintValues"> @@ -60,7 +60,8 @@ path="active_date" datatype="timestamp"> + [cellTemplate]="holdableTemplate" [cellContext]="copyContext" + [cellPrintValue]="cellPrintValues"> diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/copies.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/record/copies.component.ts index 24350d8afc..d0ce07434c 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/record/copies.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/record/copies.component.ts @@ -5,7 +5,7 @@ import {NetService} from '@eg/core/net.service'; import {StaffCatalogService} from '../catalog.service'; import {Pager} from '@eg/share/util/pager'; import {OrgService} from '@eg/core/org.service'; -import {GridDataSource} from '@eg/share/grid/grid'; +import {GridDataSource, GridColumn} from '@eg/share/grid/grid'; import {GridComponent} from '@eg/share/grid/grid.component'; @Component({ @@ -29,6 +29,8 @@ export class CopiesComponent implements OnInit { } } + cellPrintValues: (row: any, cell: GridColumn) => string; + constructor( private net: NetService, private org: OrgService, @@ -52,6 +54,19 @@ export class CopiesComponent implements OnInit { && copy.status_holdable === 't'; } }; + + // Text-ify function for cells that use display templates. + this.cellPrintValues = (row: any, cell: GridColumn): string => { + switch (cell.name) { + case 'callnumber': + return `${row.call_number_prefix_label} ` + + `${row.call_number_label} ${row.call_number_suffix_label}`; + case 'holdable': + return this.copyContext.holdable(row); + case 'barcode': + return row.barcode; + } + }; } collectData() { -- 2.43.2