LP1835982 Grid cell print values option user/berick/lp1835982-grid-csv-template-fields
authorBill Erickson <berickxx@gmail.com>
Tue, 16 Jul 2019 16:10:36 +0000 (12:10 -0400)
committerBill Erickson <berickxx@gmail.com>
Tue, 16 Jul 2019 16:10:38 +0000 (12:10 -0400)
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 <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts
Open-ILS/src/eg2/src/app/share/grid/grid.ts
Open-ILS/src/eg2/src/app/staff/catalog/record/copies.component.html
Open-ILS/src/eg2/src/app/staff/catalog/record/copies.component.ts

index fc18fc7..c162a52 100644 (file)
@@ -33,6 +33,7 @@ export class GridColumnComponent implements OnInit {
     // Used in conjunction with cellTemplate
     @Input() cellContext: any;
     @Input() cellTemplate: TemplateRef<any>;
+    @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;
index ae68169..bda09d1 100644 (file)
@@ -28,6 +28,11 @@ export class GridColumn {
     datePlusTime: boolean;
     ternaryBool: boolean;
     cellTemplate: TemplateRef<any>;
+
+    // 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);
+            }
         }
     }
 
index 709dff2..649b7f6 100644 (file)
     </eg-grid-column>
     <eg-grid-column i18n-label label="Location" path="circ_lib" datatype="org_unit">
     </eg-grid-column>
-    <eg-grid-column i18n-label label="Call Number / Copy Notes" 
-      name="callnumber" [cellTemplate]="cnTemplate">
+    <eg-grid-column i18n-label label="Call Number / Copy Notes" name="callnumber" 
+      [cellTemplate]="cnTemplate" [cellPrintValue]="cellPrintValues">
     </eg-grid-column>
     <eg-grid-column i18n-label label="Barcode" name="barcode"
-      [cellTemplate]="barcodeTemplate">
+      [cellTemplate]="barcodeTemplate" [cellPrintValue]="cellPrintValues">
     </eg-grid-column>
     <eg-grid-column i18n-label label="Shelving Location" path="copy_location">
     </eg-grid-column>
@@ -60,7 +60,8 @@
       path="active_date" datatype="timestamp">
     </eg-grid-column>
     <eg-grid-column i18n-label label="Holdable?" name="holdable" 
-      [cellTemplate]="holdableTemplate" [cellContext]="copyContext">
+      [cellTemplate]="holdableTemplate" [cellContext]="copyContext" 
+      [cellPrintValue]="cellPrintValues">
     </eg-grid-column>
     <eg-grid-column i18n-label label="Status" path="copy_status">
     </eg-grid-column>
index a478777..0f80133 100644 (file)
@@ -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() {