From: blake Date: Mon, 18 Nov 2019 16:00:57 +0000 (-0600) Subject: LP1835982 Grid cell text generator API migration X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=4c4bdcd2eadc9560f9d6cdc846d4803fedb4de82;p=working%2FEvergreen.git LP1835982 Grid cell text generator API migration Merge conflict resolution Signed-off-by: blake --- 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..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 @@ -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; @@ -71,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.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid.component.ts index 0d2321f116..490cd9f70d 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'; /** @@ -119,6 +120,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. @@ -161,6 +164,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 01b5c09aa8..fade713f7d 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; @@ -385,6 +390,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}; @@ -482,6 +494,7 @@ export class GridContext { showLinkSelectors: boolean; disablePaging: boolean; showDeclaredFieldsOnly: boolean; + cellTextGenerator: GridCellTextGenerator; // Allow calling code to know when the select-all-rows-in-page // action has occurred. @@ -797,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 (this.columnHasTextGenerator(col)) { + return this.cellTextGenerator[col.name](row); } else { - return this.getRowColumnValue(row, col); + if (col.cellTemplate) { + return ''; // avoid 'undefined' values + } else { + return this.getRowColumnValue(row, col); + } } } @@ -1091,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 26c1ca0068..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,7 +19,7 @@ - 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..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,6 +21,8 @@ export class MatchSetListComponent implements AfterViewInit { @ViewChild('grid', { static: true }) grid: GridComponent; @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent; + cellTextGenerator: GridCellTextGenerator; + constructor( private router: Router, private pcrud: PcrudService, @@ -39,6 +41,10 @@ export class MatchSetListComponent implements AfterViewInit { }); }; + this.cellTextGenerator = { + name: row => 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..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. - + + label="Import Errors" [cellTemplate]="errorsTmpl" + [cellPrintValue]="cellPrintValues"> - + 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..02d0034421 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 @@ -10,7 +10,7 @@ import {AuthService} from '@eg/core/auth.service'; import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component'; import {ProgressDialogComponent} from '@eg/share/dialog/progress.component'; 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 {VandelayService, VandelayImportSelection, VANDELAY_EXPORT_PATH} from './vandelay.service'; @@ -38,6 +38,8 @@ export class QueueComponent implements OnInit, AfterViewInit { @ViewChild('confirmDelDlg', { static: false }) confirmDelDlg: ConfirmDialogComponent; @ViewChild('progressDlg', { static: true }) progressDlg: ProgressDialogComponent; + cellTextGenerator: GridCellTextGenerator; + constructor( private router: Router, private route: ActivatedRoute, @@ -57,6 +59,11 @@ export class QueueComponent implements OnInit, AfterViewInit { return this.loadQueueRecords(pager); }; + this.cellTextGenerator = { + '+matches': row => row.matches.length + '', + 'import_error': row => row.import_error, + 'imported_as': row => row.imported_as + '' + }; } 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..f149cc8429 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,7 +15,7 @@ + [disableSelect]="true" [disableMultiSelect]="true" [cellTextGenerator]="cellTextGenerator"> 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 1c78e5906f..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} 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,6 +131,7 @@ export class HoldingsMaintenanceComponent implements OnInit { renderFromPrefs: boolean; rowClassCallback: (row: any) => string; + cellTextGenerator: GridCellTextGenerator; private _recId: number; @Input() set recordId(id: number) { @@ -182,6 +183,13 @@ export class HoldingsMaintenanceComponent implements OnInit { } }; + // Text-ify function for cells that use display templates. + this.cellTextGenerator = { + owner_label: row => row.locationLabel, + holdable: row => row.copy ? + this.gridTemplateContext.copyIsHoldable(row.copy) : '' + }; + this.gridTemplateContext = { toggleExpandRow: (row: HoldingsEntry) => { row.treeNode.expanded = !row.treeNode.expanded; 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..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 @@ @@ -118,8 +118,8 @@ {{hold.title}} - + 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..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} 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,6 +111,8 @@ export class HoldsGridComponent implements OnInit { } } + cellTextGenerator: GridCellTextGenerator; + constructor( private net: NetService, private org: OrgService, @@ -142,6 +144,12 @@ 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.cellTextGenerator = { + title: row => row.title, + cp_barcode: row => row.cp_barcode + }; } // Returns true after all data/settings/etc required to render the