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 + '"');
+ }
}
}
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();
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';
/**
// would go out of view
@Input() stickyHeader: boolean;
+ @Input() cellTextGenerator: GridCellTextGenerator;
+
context: GridContext;
// These events are emitted from our grid-body component.
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(',');
}
}
}
+// 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};
overflowCells: boolean;
disablePaging: boolean;
showDeclaredFieldsOnly: boolean;
+ cellTextGenerator: GridCellTextGenerator;
// Allow calling code to know when the select-all-rows-in-page
// action has occurred.
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
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;
+ }
}
</a>
</ng-template>
-<eg-grid #grid [dataSource]="gridSource"
+<eg-grid #grid [dataSource]="gridSource" [cellTextGenerator]="cellTextGenerator"
persistKey="cat.vandelay.match_set.list"
idlClass="vms" [dataSource]="queueSource">
<eg-grid-toolbar-button label="New Match Set" i18n-label [action]="createNew">
</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" [cellPrintValue]="cellPrintValues">
+ <eg-grid-column name="name" [cellTemplate]="nameTmpl">
</eg-grid-column>
</eg-grid>
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({
@ViewChild('grid', { static: true }) grid: GridComponent;
@ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent;
- cellPrintValues: (row: any, cell: GridColumn) => string;
+ cellTextGenerator: GridCellTextGenerator;
constructor(
private router: Router,
});
};
- // 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 = () => {
<eg-grid #queueGrid [dataSource]="queueSource"
persistKey="cat.vandelay.queue.{{queueType}}"
(onRowActivate)="openRecord($event)"
- [pageOffset]="queuePageOffset()"
+ [pageOffset]="queuePageOffset()" [cellTextGenerator]="cellTextGenerator"
hideFields="language,pagination,price,rec_identifier,eg_tcn_source,eg_identifier,item_barcode,zsource">
<eg-grid-toolbar-checkbox i18n-label label="Records With Matches"
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';
@ViewChild('confirmDelDlg', { static: false }) confirmDelDlg: ConfirmDialogComponent;
@ViewChild('progressDlg', { static: true }) progressDlg: ProgressDialogComponent;
- cellPrintValues: (row: any, cell: GridColumn) => string;
+ cellTextGenerator: GridCellTextGenerator;
constructor(
private router: Router,
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 + ''
};
}
<ng-container *ngIf="queueType == 'bib'">
<eg-grid #bibGrid [dataSource]="bibDataSource"
(onRowClick)="matchRowClick($event)"
+ [cellTextGenerator]="cellTextGenerator"
[disableSelect]="true" [disableMultiSelect]="true">
<!--
<eg-grid-toolbar-action i18n-label label="Mark As Overlay Target"
i18n-label label="Match ID">
</eg-grid-column>
<eg-grid-column name="selected" i18n-label label="Merge Target"
- [cellTemplate]="targetTemplate" [cellPrintValue]="cellPrintValues">
+ [cellTemplate]="targetTemplate">
</eg-grid-column>
<eg-grid-column name="eg_record" i18n-label label="Record ID"
- [cellTemplate]="bibIdTemplate" [cellPrintValue]="cellPrintValues">
+ [cellTemplate]="bibIdTemplate">
</eg-grid-column>
<eg-grid-column name="match_score" i18n-label label="Match Score">
</eg-grid-column>
import {map} from 'rxjs/operators';
import {Pager} from '@eg/share/util/pager';
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 {IdlObject} from '@eg/core/idl.service';
import {EventService} from '@eg/core/event.service';
import {NetService} from '@eg/core/net.service';
matchRowClick: (row: any) => void;
matchMap: {[id: number]: IdlObject};
- cellPrintValues: (row: any, cell: GridColumn) => string;
+ cellTextGenerator: GridCellTextGenerator;
constructor(
private router: Router,
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] || '';
+ this.cellTextGenerator = {
+ selected: row => this.isOverlayTarget(row.id) + '',
+ eg_record: row => row.eg_record + ''
};
<div class='eg-copies w-100 mt-3'>
<eg-grid #copyGrid [dataSource]="gridDataSource"
- [disableSelect]="true"
+ [disableSelect]="true" [cellTextGenerator]="cellTextGenerator"
[sortable]="false" persistKey="catalog.record.copies">
<eg-grid-column i18n-label label="Item ID" path="id"
[hidden]="true" [index]="true">
<eg-grid-column i18n-label label="Location" path="circ_lib" datatype="org_unit">
</eg-grid-column>
<eg-grid-column i18n-label label="Call Number / Item Notes" name="callnumber"
- [cellTemplate]="cnTemplate" [cellPrintValue]="cellPrintValues">
+ [cellTemplate]="cnTemplate">
</eg-grid-column>
<eg-grid-column i18n-label label="Barcode" name="barcode"
- [cellTemplate]="barcodeTemplate" [cellPrintValue]="cellPrintValues">
+ [cellTemplate]="barcodeTemplate">
</eg-grid-column>
<eg-grid-column i18n-label label="Shelving Location" path="copy_location">
</eg-grid-column>
import {StaffCatalogService} from '../catalog.service';
import {Pager} from '@eg/share/util/pager';
import {OrgService} from '@eg/core/org.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';
@Component({
}
}
- cellPrintValues: (row: any, cell: GridColumn) => string;
+ cellTextGenerator: GridCellTextGenerator;
constructor(
private net: NetService,
}
};
- // 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;
- }
+ this.cellTextGenerator = {
+ callnumber: row => `${row.call_number_prefix_label} ` +
+ `${row.call_number_label} ${row.call_number_suffix_label}`,
+ holdable: row => this.copyContext.holdable(row),
+ barcode: row => row.barcode
};
}
<div class='eg-copies w-100 mt-3'>
<eg-grid #holdingsGrid [dataSource]="gridDataSource"
(onRowActivate)="onRowActivate($event)" [disablePaging]="true"
- [rowClassCallback]="rowClassCallback"
+ [rowClassCallback]="rowClassCallback" [cellTextGenerator]="cellTextGenerator"
[sortable]="false" persistKey="cat.holdings">
<!-- checkboxes / filters -->
</eg-grid-column>
<eg-grid-column name="owner_label" [flex]="4"
[cellTemplate]="locationTemplate" [cellContext]="gridTemplateContext"
- [cellPrintValue]="cellPrintValues"
label="Location/Barcode" [disableTooltip]="true" i18n-label>
</eg-grid-column>
<eg-grid-column path="callNumCount" datatype="number" label="Call Numbers" i18n-label>
<eg-grid-column i18n-label label="Deposit Amount" path="copy.deposit_amount"
name="deposit_amount" datatype="money" [hidden]="true"></eg-grid-column>
<eg-grid-column i18n-label label="Holdable?" name="holdable"
- [cellTemplate]="holdableTemplate" [cellContext]="gridTemplateContext"
- [cellPrintValue]="cellPrintValues">
+ [cellTemplate]="holdableTemplate" [cellContext]="gridTemplateContext">
</eg-grid-column>
<eg-grid-column i18n-label label="Reference?" path="copy.ref"
name="ref" datatype="bool" [hidden]="true"></eg-grid-column>
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';
renderFromPrefs: boolean;
rowClassCallback: (row: any) => string;
- cellPrintValues: (row: any, cell: GridColumn) => string;
+ cellTextGenerator: GridCellTextGenerator;
private _recId: number;
@Input() set recordId(id: number) {
};
// 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 = {
</div>
<eg-grid #holdsGrid [dataSource]="gridDataSource" [sortable]="true"
- [useLocalSort]="enablePreFetch"
+ [useLocalSort]="enablePreFetch" [cellTextGenerator]="cellTextGenerator"
[multiSortable]="true" [persistKey]="persistKey"
(onRowActivate)="showDetail($event)">
</a>
</ng-template>
<eg-grid-column i18n-label label="Current Item" name='cp_barcode'
- [cellTemplate]="barcodeTmpl" [cellPrintValue]="cellPrintValues">
+ [cellTemplate]="barcodeTmpl">
</eg-grid-column>
<ng-template #userBarcodeTmpl let-hold="row">
</a>
</ng-template>
<eg-grid-column i18n-label label="Title" [hidden]="true" name='title'
- [cellTemplate]="titleTmpl" [cellPrintValue]="cellPrintValues"></eg-grid-column>
+ [cellTemplate]="titleTmpl"></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">
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
}
}
- cellPrintValues: (row: any, cell: GridColumn) => string;
+ cellTextGenerator: GridCellTextGenerator;
constructor(
private net: NetService,
};
// 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
};
}