From 97ad87b1b94d64e35097a188e266b0d31d167e20 Mon Sep 17 00:00:00 2001
From: Bill Erickson <berickxx@gmail.com>
Date: Fri, 9 Aug 2019 11:52:05 -0400
Subject: [PATCH] LP1835982 More grid cell print generators

Adds additional print content generators for Angular grid cells which
are rendered via cell templates.

* Vandelay match set list grid
* Vandelay queue contents grid
* Vandelay queued record matches grid
* Catalog holds grid.

Also adds a warning to the grid component when an attempt is made to
print a templated cell which has no print content generator.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
---
 Open-ILS/src/eg2/src/app/share/grid/grid-print.component.ts  |  7 +++++++
 .../src/app/staff/cat/vandelay/match-set-list.component.html |  2 +-
 .../src/app/staff/cat/vandelay/match-set-list.component.ts   | 10 ++++++++++
 .../src/eg2/src/app/staff/cat/vandelay/queue.component.html  | 11 ++++++-----
 .../src/eg2/src/app/staff/cat/vandelay/queue.component.ts    | 10 ++++++++++
 .../staff/cat/vandelay/queued-record-matches.component.html  |  4 ++--
 .../staff/cat/vandelay/queued-record-matches.component.ts    | 11 +++++++++++
 .../src/eg2/src/app/staff/share/holds/grid.component.html    |  6 +++---
 Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts | 12 +++++++++++-
 9 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-print.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-print.component.ts
index f7c857a4ab..d4e1d034a3 100644
--- a/Open-ILS/src/eg2/src/app/share/grid/grid-print.component.ts
+++ b/Open-ILS/src/eg2/src/app/share/grid/grid-print.component.ts
@@ -24,6 +24,13 @@ export class GridPrintComponent {
         const columns = this.gridContext.columnSet.displayColumns();
         const textItems = {columns: columns, rows: []};
 
+        // Warn on missing print value generators for cells using templates.
+        columns.forEach(col => {
+            if (col.cellTemplate && !col.cellPrintValue) {
+                console.warn("No print value generator set for: " + col.name);
+            }
+        });
+
         this.gridContext.getAllRowsAsText().subscribe(
             row => {
               this.progressDialog.increment();
diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-list.component.html b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-list.component.html
index 26c1ca0068..74cad9743c 100644
--- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-list.component.html
+++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-list.component.html
@@ -26,7 +26,7 @@
   </eg-grid-toolbar-button>
   <eg-grid-toolbar-action label="Delete Selected" i18n-label 
     [action]="deleteSelected"></eg-grid-toolbar-action>
-  <eg-grid-column name="name" [cellTemplate]="nameTmpl">
+  <eg-grid-column name="name" [cellTemplate]="nameTmpl" [cellPrintValue]="cellPrintValues">
   </eg-grid-column>
 </eg-grid>
 
diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-list.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-list.component.ts
index 5f49fc19e9..c58735fc3a 100644
--- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-list.component.ts
+++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-list.component.ts
@@ -21,6 +21,8 @@ export class MatchSetListComponent implements AfterViewInit {
     @ViewChild('grid', { static: true }) grid: GridComponent;
     @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent;
 
+    cellPrintValues: (row: any, cell: GridColumn) => string;
+
     constructor(
         private router: Router,
         private pcrud: PcrudService,
@@ -39,6 +41,14 @@ export class MatchSetListComponent implements AfterViewInit {
             });
         };
 
+        // Text-ify function for cells that use display templates.
+        this.cellPrintValues = (row: any, cell: GridColumn): string => {
+            switch (cell.name) {
+                case 'name':
+                    return row.name();
+            }
+        };
+
         this.createNew = () => {
             this.editDialog.mode = 'create';
             this.editDialog.open({size: 'lg'})
diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.html b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.html
index 2c1b3c3215..5ff7adc5bf 100644
--- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.html
+++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.html
@@ -143,13 +143,14 @@ because there are a lot of them.
     (onChange)="limitToImportErrors($event)"></eg-grid-toolbar-checkbox>
 
   <eg-grid-column name="id" [index]="true" [hidden]="true"></eg-grid-column>
-  <eg-grid-column i18n-label label="Matches"
-    name="+matches" [cellTemplate]="matchesTmpl"></eg-grid-column>
+  <eg-grid-column i18n-label label="Matches" name="+matches" 
+    [cellTemplate]="matchesTmpl" [cellPrintValue]="cellPrintValues"></eg-grid-column>
   <eg-grid-column name="import_error" i18n-label
-    label="Import Errors" [cellTemplate]="errorsTmpl"></eg-grid-column>
+    label="Import Errors" [cellTemplate]="errorsTmpl" 
+      [cellPrintValue]="cellPrintValues"></eg-grid-column>
   <eg-grid-column name="import_time" i18n-label
     label="Import Date" datatype="timestamp"></eg-grid-column>
-  <eg-grid-column name="imported_as" i18n-label
-    label="Imported As" [cellTemplate]="importedAsTmpl"></eg-grid-column>
+  <eg-grid-column name="imported_as" i18n-label label="Imported As" 
+    [cellTemplate]="importedAsTmpl" [cellPrintValue]="cellPrintValues"></eg-grid-column>
 </eg-grid>
 
diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.ts
index 6e6fca24dc..e763130e55 100644
--- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.ts
+++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.ts
@@ -38,6 +38,8 @@ export class QueueComponent implements OnInit, AfterViewInit {
     @ViewChild('confirmDelDlg', { static: false }) confirmDelDlg: ConfirmDialogComponent;
     @ViewChild('progressDlg', { static: true }) progressDlg: ProgressDialogComponent;
 
+    cellPrintValues: (row: any, cell: GridColumn) => string;
+
     constructor(
         private router: Router,
         private route: ActivatedRoute,
@@ -57,6 +59,14 @@ export class QueueComponent implements OnInit, AfterViewInit {
             return this.loadQueueRecords(pager);
         };
 
+        // Text-ify function for cells that use display templates.
+        this.cellPrintValues = (row: any, cell: GridColumn): string => {
+            return ({
+                '+matches': row.matches.length + '',
+                'import_error': row.import_error,
+                'imported_as': row.imported_as + ''
+            })[cell.name] || '';
+        };
     }
 
     ngOnInit() {
diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queued-record-matches.component.html b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queued-record-matches.component.html
index 679f71695a..346230a69b 100644
--- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queued-record-matches.component.html
+++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queued-record-matches.component.html
@@ -25,10 +25,10 @@
       i18n-label label="Match ID">
     </eg-grid-column>
     <eg-grid-column name="selected" i18n-label label="Merge Target"
-      [cellTemplate]="targetTemplate">
+      [cellTemplate]="targetTemplate" [cellPrintValue]="cellPrintValues">
     </eg-grid-column>
     <eg-grid-column name="eg_record" i18n-label label="Record ID"
-      [cellTemplate]="bibIdTemplate">
+      [cellTemplate]="bibIdTemplate" [cellPrintValue]="cellPrintValues">
     </eg-grid-column>
     <eg-grid-column name="match_score" i18n-label label="Match Score">
     </eg-grid-column>
diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queued-record-matches.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queued-record-matches.component.ts
index a4ac067535..7f2eefbace 100644
--- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queued-record-matches.component.ts
+++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queued-record-matches.component.ts
@@ -31,6 +31,8 @@ export class QueuedRecordMatchesComponent implements OnInit {
     matchRowClick: (row: any) => void;
     matchMap: {[id: number]: IdlObject};
 
+    cellPrintValues: (row: any, cell: GridColumn) => string;
+
     constructor(
         private router: Router,
         private route: ActivatedRoute,
@@ -48,6 +50,15 @@ export class QueuedRecordMatchesComponent implements OnInit {
             return this.getBibMatchRows(pager);
         };
 
+        // Text-ify function for cells that use display templates.
+        this.cellPrintValues = (row: any, cell: GridColumn): string => {
+            return ({
+                'selected': this.isOverlayTarget(row.id) + '',
+                'eg_record': row.eg_record + ''
+            })[cell.name] || '';
+        };
+
+
         /* TODO
         this.authDataSource.getRows = (pager: Pager) => {
         }
diff --git a/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.html b/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.html
index 14f96e5755..a4d088caac 100644
--- a/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.html
+++ b/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.html
@@ -92,7 +92,7 @@
         </a>
       </ng-template>
       <eg-grid-column i18n-label label="Current Item" name='cp_barcode'
-        [cellTemplate]="barcodeTmpl">
+        [cellTemplate]="barcodeTmpl" [cellPrintValue]="cellPrintValues">
       </eg-grid-column>
 
       <ng-template #userBarcodeTmpl let-hold="row">
@@ -118,8 +118,8 @@
           {{hold.title}}
         </a>
       </ng-template>
-      <eg-grid-column i18n-label label="Title" [hidden]="true"
-          name='title' [cellTemplate]="titleTmpl"></eg-grid-column>
+      <eg-grid-column i18n-label label="Title" [hidden]="true" name='title' 
+        [cellTemplate]="titleTmpl" [cellPrintValue]="cellPrintValues"></eg-grid-column>
       <eg-grid-column i18n-label label="Author" path='author'
           [hidden]="true"></eg-grid-column>
       <eg-grid-column i18n-label label="Potential Items" path='potentials' datatype="int">
diff --git a/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts b/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts
index 1cc352fcc5..effa7c553c 100644
--- a/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts
+++ b/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts
@@ -6,7 +6,7 @@ import {OrgService} from '@eg/core/org.service';
 import {AuthService} from '@eg/core/auth.service';
 import {Pager} from '@eg/share/util/pager';
 import {ServerStoreService} from '@eg/core/server-store.service';
-import {GridDataSource} from '@eg/share/grid/grid';
+import {GridDataSource, GridColumn} from '@eg/share/grid/grid';
 import {GridComponent} from '@eg/share/grid/grid.component';
 import {ProgressDialogComponent} from '@eg/share/dialog/progress.component';
 import {MarkDamagedDialogComponent
@@ -111,6 +111,8 @@ export class HoldsGridComponent implements OnInit {
         }
     }
 
+    cellPrintValues: (row: any, cell: GridColumn) => string;
+
     constructor(
         private net: NetService,
         private org: OrgService,
@@ -142,6 +144,14 @@ export class HoldsGridComponent implements OnInit {
             sort = sort.length > 0 ? sort : this.defaultSort;
             return this.fetchHolds(pager, sort);
         };
+
+        // Text-ify function for cells that use display templates.
+        this.cellPrintValues = (row: any, cell: GridColumn): string => {
+            return ({
+                'title': row.title,
+                'cp_barcode': row.cp_barcode
+            })[cell.name] || '';
+        };
     }
 
     // Returns true after all data/settings/etc required to render the
-- 
2.11.0