From: Bill Erickson Date: Tue, 16 Jul 2019 16:10:36 +0000 (-0400) Subject: LP1835982 Grid cell print values option X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Fuser%2Fberick%2Flp1835982-grid-csv-template-fields;p=working%2FEvergreen.git 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. Includes sample implementation for the Angular record detail copies grid, which uses several cellTemplate cells. Signed-off-by: Bill Erickson --- 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 fc18fc7258..c162a5238f 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 @@ -33,6 +33,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; @@ -54,6 +55,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 ae681694d8..bda09d1002 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.ts @@ -28,6 +28,11 @@ export class GridColumn { datePlusTime: boolean; ternaryBool: boolean; 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; @@ -741,11 +746,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 709dff2a1f..649b7f6130 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 a478777a9e..0f80133ad6 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() {