From 6ba4090ce72fe9f19f656c51d6d263870a28db4f Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 9 Aug 2019 12:47:37 -0400 Subject: [PATCH] LP1835982 Grid cell text generator API migration Migrate cell-specific cellPrintValue handlers to a grid-wide cellTextGenerator handler. This simplifies the client-side API and helps to formalize the API a bit more by providing a new GridCellTextGenerator interface. Warning messages are now display at page load time when a grid cell uses a cellTemplate but does not have a matching text generator. Signed-off-by: Bill Erickson Signed-off-by: Galen Charlton Signed-off-by: Jane Sandberg --- .../eg2/src/app/share/grid/grid-column.component.ts | 6 ++++++ .../eg2/src/app/share/grid/grid-print.component.ts | 7 ------- .../src/eg2/src/app/share/grid/grid.component.ts | 7 ++++++- Open-ILS/src/eg2/src/app/share/grid/grid.ts | 16 ++++++++++++++-- .../staff/cat/vandelay/match-set-list.component.html | 4 ++-- .../staff/cat/vandelay/match-set-list.component.ts | 12 ++++-------- .../src/app/staff/cat/vandelay/queue.component.html | 2 +- .../src/app/staff/cat/vandelay/queue.component.ts | 15 ++++++--------- .../vandelay/queued-record-matches.component.html | 5 +++-- .../cat/vandelay/queued-record-matches.component.ts | 13 +++++-------- .../app/staff/catalog/record/copies.component.html | 6 +++--- .../src/app/staff/catalog/record/copies.component.ts | 20 +++++++------------- .../app/staff/catalog/record/holdings.component.html | 6 ++---- .../app/staff/catalog/record/holdings.component.ts | 17 ++++++----------- .../src/app/staff/share/holds/grid.component.html | 6 +++--- .../eg2/src/app/staff/share/holds/grid.component.ts | 12 +++++------- 16 files changed, 73 insertions(+), 81 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 57af2e8861..bb30842445 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 @@ -73,6 +73,12 @@ export class GridColumnComponent implements OnInit { col.timezoneContextOrg = this.timezoneContextOrg; col.isAuto = false; this.grid.context.columnSet.add(col); + + if (this.cellTemplate && + !this.grid.context.columnHasTextGenerator(col)) { + console.warn( + 'No cellTextGenerator provided for "' + col.name + '"'); + } } } 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 d4e1d034a3..f7c857a4ab 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,13 +24,6 @@ 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/share/grid/grid.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid.component.ts index e3decc643f..191bec6d94 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.component.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.component.ts @@ -4,7 +4,8 @@ import {IdlService} from '@eg/core/idl.service'; import {OrgService} from '@eg/core/org.service'; import {ServerStoreService} from '@eg/core/server-store.service'; import {FormatService} from '@eg/core/format.service'; -import {GridContext, GridColumn, GridDataSource, GridRowFlairEntry} from './grid'; +import {GridContext, GridColumn, GridDataSource, + GridCellTextGenerator, GridRowFlairEntry} from './grid'; import {GridToolbarComponent} from './grid-toolbar.component'; /** @@ -107,6 +108,8 @@ export class GridComponent implements OnInit, AfterViewInit, OnDestroy { // would go out of view @Input() stickyHeader: boolean; + @Input() cellTextGenerator: GridCellTextGenerator; + context: GridContext; // These events are emitted from our grid-body component. @@ -148,6 +151,8 @@ export class GridComponent implements OnInit, AfterViewInit, OnDestroy { this.context.showDeclaredFieldsOnly = this.showDeclaredFieldsOnly; this.context.rowFlairCallback = this.rowFlairCallback; this.context.disablePaging = this.disablePaging === true; + this.context.cellTextGenerator = this.cellTextGenerator; + if (this.showFields) { this.context.defaultVisibleFields = this.showFields.split(','); } 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 42bd982f43..20bde50f5e 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 { } } +// Maps colunm names to functions which return plain text values for +// each mapped column on a given row. This is primarily useful for +// generating print-friendly content for grid cells rendered via +// cellTemplate. +export interface GridCellTextGenerator { + [columnName: string]: (row: any) => string; +} export class GridRowSelector { indexes: {[string: string]: boolean}; @@ -495,6 +502,7 @@ export class GridContext { overflowCells: boolean; disablePaging: boolean; showDeclaredFieldsOnly: boolean; + cellTextGenerator: GridCellTextGenerator; // Allow calling code to know when the select-all-rows-in-page // action has occurred. @@ -810,8 +818,8 @@ export class GridContext { getColumnTextContent(row: any, col: GridColumn): string { - if (col.cellPrintValue) { - return col.cellPrintValue(row, col); + if (this.columnHasTextGenerator(col)) { + return this.cellTextGenerator[col.name](row); } else { if (col.cellTemplate) { return ''; // avoid 'undefined' values @@ -1099,6 +1107,10 @@ export class GridContext { if (!persistKey) { return Promise.resolve(null); } return this.store.getItem('eg.grid.' + persistKey); } + + columnHasTextGenerator(col: GridColumn): boolean { + return this.cellTextGenerator && col.name in this.cellTextGenerator; + } } 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 74cad9743c..67c9588d98 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 @@ -19,14 +19,14 @@ - - + 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 c58735fc3a..7ea2ae833f 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 @@ -6,7 +6,7 @@ import {PcrudService} from '@eg/core/pcrud.service'; import {OrgService} from '@eg/core/org.service'; import {AuthService} from '@eg/core/auth.service'; import {GridComponent} from '@eg/share/grid/grid.component'; -import {GridDataSource, GridColumn} from '@eg/share/grid/grid'; +import {GridDataSource, GridColumn, GridCellTextGenerator} from '@eg/share/grid/grid'; import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component'; @Component({ @@ -21,7 +21,7 @@ export class MatchSetListComponent implements AfterViewInit { @ViewChild('grid', { static: true }) grid: GridComponent; @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent; - cellPrintValues: (row: any, cell: GridColumn) => string; + cellTextGenerator: GridCellTextGenerator; constructor( private router: Router, @@ -41,12 +41,8 @@ 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.cellTextGenerator = { + name: row => row.name() }; this.createNew = () => { 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 5ff7adc5bf..16c97da6a2 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 @@ -130,7 +130,7 @@ because there are a lot of them. string; + cellTextGenerator: GridCellTextGenerator; constructor( private router: Router, @@ -59,13 +59,10 @@ 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] || ''; + this.cellTextGenerator = { + '+matches': row => row.matches.length + '', + 'import_error': row => row.import_error, + 'imported_as': row => row.imported_as + '' }; } 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 346230a69b..2a14c31b8a 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 @@ -15,6 +15,7 @@ @@ -228,7 +228,6 @@ @@ -280,8 +279,7 @@ + [cellTemplate]="holdableTemplate" [cellContext]="gridTemplateContext"> diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/holdings.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/record/holdings.component.ts index 973f31a378..4186b7aad3 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/record/holdings.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/record/holdings.component.ts @@ -9,7 +9,7 @@ import {StaffCatalogService} from '../catalog.service'; import {OrgService} from '@eg/core/org.service'; import {PcrudService} from '@eg/core/pcrud.service'; import {AuthService} from '@eg/core/auth.service'; -import {GridDataSource, GridColumn} from '@eg/share/grid/grid'; +import {GridDataSource, GridColumn, GridCellTextGenerator} from '@eg/share/grid/grid'; import {GridComponent} from '@eg/share/grid/grid.component'; import {GridToolbarCheckboxComponent } from '@eg/share/grid/grid-toolbar-checkbox.component'; @@ -131,7 +131,7 @@ export class HoldingsMaintenanceComponent implements OnInit { renderFromPrefs: boolean; rowClassCallback: (row: any) => string; - cellPrintValues: (row: any, cell: GridColumn) => string; + cellTextGenerator: GridCellTextGenerator; private _recId: number; @Input() set recordId(id: number) { @@ -184,15 +184,10 @@ export class HoldingsMaintenanceComponent implements OnInit { }; // Text-ify function for cells that use display templates. - this.cellPrintValues = (row: any, cell: GridColumn): string => { - switch (cell.name) { - case 'owner_label': - return row.locationLabel; - case 'holdable': - return row.copy ? - this.gridTemplateContext.copyIsHoldable(row.copy) : - ''; - } + this.cellTextGenerator = { + owner_label: row => row.locationLabel, + holdable: row => row.copy ? + this.gridTemplateContext.copyIsHoldable(row.copy) : '' }; this.gridTemplateContext = { 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 a4d088caac..b3c7705b36 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 @@ -31,7 +31,7 @@ @@ -92,7 +92,7 @@ + [cellTemplate]="barcodeTmpl"> @@ -119,7 +119,7 @@ + [cellTemplate]="titleTmpl"> 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 effa7c553c..029883b3b0 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, GridColumn} from '@eg/share/grid/grid'; +import {GridDataSource, GridColumn, GridCellTextGenerator} from '@eg/share/grid/grid'; import {GridComponent} from '@eg/share/grid/grid.component'; import {ProgressDialogComponent} from '@eg/share/dialog/progress.component'; import {MarkDamagedDialogComponent @@ -111,7 +111,7 @@ export class HoldsGridComponent implements OnInit { } } - cellPrintValues: (row: any, cell: GridColumn) => string; + cellTextGenerator: GridCellTextGenerator; constructor( private net: NetService, @@ -146,11 +146,9 @@ export class HoldsGridComponent implements OnInit { }; // 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] || ''; + this.cellTextGenerator = { + title: row => row.title, + cp_barcode: row => row.cp_barcode }; } -- 2.11.0