// Used in conjunction with cellTemplate
@Input() cellContext: any;
@Input() cellTemplate: TemplateRef<any>;
+ @Input() cellPrintValue: (row: any, cell: GridColumn) => string;
@Input() disableTooltip: boolean;
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;
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 + '"');
+ }
}
}
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(',');
}
ternaryBool: boolean;
timezoneContextOrg: number;
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;
}
}
+// 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};
showLinkSelectors: 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.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);
+ }
}
}
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">
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;
+ cellTextGenerator: GridCellTextGenerator;
+
constructor(
private router: Router,
private pcrud: PcrudService,
});
};
+ this.cellTextGenerator = {
+ name: row => row.name()
+ };
+
this.createNew = () => {
this.editDialog.mode = 'create';
this.editDialog.open({size: 'lg'})
<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"
(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>
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;
+ cellTextGenerator: GridCellTextGenerator;
+
constructor(
private router: Router,
private route: ActivatedRoute,
return this.loadQueueRecords(pager);
};
+ this.cellTextGenerator = {
+ '+matches': row => row.matches.length + '',
+ 'import_error': row => row.import_error,
+ 'imported_as': row => row.imported_as + ''
+ };
}
ngOnInit() {
<ng-container *ngIf="queueType == 'bib'">
<eg-grid #bibGrid [dataSource]="bibDataSource"
(onRowClick)="matchRowClick($event)"
- [disableSelect]="true" [disableMultiSelect]="true">
+ [disableSelect]="true" [disableMultiSelect]="true" [cellTextGenerator]="cellTextGenerator">
<!--
<eg-grid-toolbar-action i18n-label label="Mark As Overlay Target"
[action]="markOverlayTarget">
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};
+ cellTextGenerator: GridCellTextGenerator;
+
constructor(
private router: Router,
private route: ActivatedRoute,
return this.getBibMatchRows(pager);
};
+ this.cellTextGenerator = {
+ selected: row => this.isOverlayTarget(row.id) + '',
+ eg_record: row => row.eg_record + ''
+ };
+
+
/* TODO
this.authDataSource.getRows = (pager: Pager) => {
}
<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>
<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">
+ <eg-grid-column i18n-label label="Call Number / Item Notes" name="callnumber"
+ [cellTemplate]="cnTemplate">
</eg-grid-column>
<eg-grid-column i18n-label label="Barcode" name="barcode"
[cellTemplate]="barcodeTemplate">
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>
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, GridCellTextGenerator} from '@eg/share/grid/grid';
import {GridComponent} from '@eg/share/grid/grid.component';
@Component({
}
}
+ cellTextGenerator: GridCellTextGenerator;
+
constructor(
private net: NetService,
private org: OrgService,
&& copy.status_holdable === 't';
}
};
+
+ 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
+ };
}
collectData() {
<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 -->
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';
renderFromPrefs: boolean;
rowClassCallback: (row: any) => string;
+ cellTextGenerator: GridCellTextGenerator;
private _recId: number;
@Input() set recordId(id: number) {
}
};
+ // 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;
</div>
<eg-grid #holdsGrid [dataSource]="gridDataSource" [sortable]="true"
- [useLocalSort]="enablePreFetch"
+ [useLocalSort]="enablePreFetch" [cellTextGenerator]="cellTextGenerator"
[multiSortable]="true" [persistKey]="persistKey"
(onRowActivate)="showDetail($event)">
{{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"></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} 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
}
}
+ cellTextGenerator: GridCellTextGenerator;
+
constructor(
private net: NetService,
private org: OrgService,
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