1 import {Component, Input, OnInit, ViewChild} from '@angular/core';
2 import {Observable, empty, from} from 'rxjs';
3 import {map, tap, switchMap} from 'rxjs/operators';
4 import {IdlObject} from '@eg/core/idl.service';
5 import {Pager} from '@eg/share/util/pager';
6 import {NetService} from '@eg/core/net.service';
7 import {PcrudService} from '@eg/core/pcrud.service';
8 import {OrgService} from '@eg/core/org.service';
9 import {GridComponent} from '@eg/share/grid/grid.component';
10 import {GridContext, GridDataSource, GridCellTextGenerator} from '@eg/share/grid/grid';
11 import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
14 /* Grid of bib records and associated actions. */
17 templateUrl: 'bib-list.component.html',
18 selector: 'eg-bib-list'
20 export class BibListComponent implements OnInit {
22 // Static source of bib record IDs
23 @Input() bibIds: number[];
24 // Dynamic source of bib record IDs
25 @Input() bibIdSource: (pager: Pager, sort: any) => Promise<number[]>;
26 @Input() gridPersistKey: string;
28 dataSource: GridDataSource;
29 cellTextGenerator: GridCellTextGenerator;
31 @ViewChild('grid', {static: false}) grid: GridComponent;
34 private net: NetService,
35 private org: OrgService,
36 private pcrud: PcrudService
41 this.dataSource = new GridDataSource();
43 this.dataSource.getRows = (pager: Pager, sort: any): Observable<any> => {
45 if (this.bibIds || this.bibIdSource) {
46 return this.loadIds(pager, sort);
52 this.cellTextGenerator = {
53 title: row => row.title
57 loadIds(pager: Pager, sort: any): Observable<any> {
59 let promise: Promise<number[]>;
61 if (this.bibIdSource) {
62 promise = this.bibIdSource(pager, sort);
64 } else if (this.bibIds && this.bibIds.length > 0) {
65 promise = Promise.resolve(
66 this.bibIds.slice(pager.offset, pager.offset + pager.limit));
72 // ID is the currently only supported sort column. If other
73 // columns are added, callers providing a bibIdSource will need
74 // to implement the new columns as well.
75 const orderBy = {rmsr: 'id'};
76 if (sort.length && sort[0].name === 'id') {
77 orderBy.rmsr = orderBy.rmsr + ' ' + sort[0].dir;
80 return from(promise).pipe(switchMap(bibIds => {
82 if (bibIds.length === 0) { return empty(); }
84 return this.pcrud.search('rmsr', {id: bibIds}, {
88 rmsr: ['biblio_record'],
89 bre: ['creator', 'editor']