1 import {Component, OnInit, Input, ViewChild} from '@angular/core';
2 import {Observable, of} from 'rxjs';
3 import {map} from 'rxjs/operators';
4 import {NetService} from '@eg/core/net.service';
5 import {StaffCatalogService} from '../catalog.service';
6 import {Pager} from '@eg/share/util/pager';
7 import {OrgService} from '@eg/core/org.service';
8 import {GridDataSource, GridColumn, GridCellTextGenerator} from '@eg/share/grid/grid';
9 import {GridComponent} from '@eg/share/grid/grid.component';
12 selector: 'eg-catalog-copies',
13 templateUrl: 'copies.component.html'
15 export class CopiesComponent implements OnInit {
19 gridDataSource: GridDataSource;
20 copyContext: any; // grid context
21 @ViewChild('copyGrid', { static: true }) copyGrid: GridComponent;
23 @Input() set recordId(id: number) {
25 // Only force new data collection when recordId()
26 // is invoked after ngInit() has already run.
28 this.copyGrid.reload();
32 cellTextGenerator: GridCellTextGenerator;
35 private net: NetService,
36 private org: OrgService,
37 private staffCat: StaffCatalogService,
39 this.gridDataSource = new GridDataSource();
45 this.gridDataSource.getRows = (pager: Pager, sort: any[]) => {
46 // sorting not currently supported
47 return this.fetchCopies(pager);
51 holdable: (copy: any) => {
52 return copy.holdable === 't'
53 && copy.location_holdable === 't'
54 && copy.status_holdable === 't';
58 this.cellTextGenerator = {
59 callnumber: row => (`${row.call_number_prefix_label} ` +
60 `${row.call_number_label} ${row.call_number_suffix_label}`).trim(),
61 holdable: row => this.copyContext.holdable(row),
62 barcode: row => row.barcode
67 if (!this.recId) { return; }
70 orgName(orgId: number): string {
71 return this.org.get(orgId).shortname();
74 fetchCopies(pager: Pager): Observable<any> {
75 if (!this.recId) { return of([]); }
77 // "Show Result from All Libraries" i.e. global search displays
78 // copies from all branches, sorted by search/pref libs.
79 const copy_depth = this.staffCat.searchContext.global ?
80 this.org.root().ou_type().depth() :
81 this.staffCat.searchContext.searchOrg.ou_type().depth();
83 return this.net.request(
85 'open-ils.search.bib.copies.staff',
87 this.staffCat.searchContext.searchOrg.id(),
91 this.staffCat.prefOrg ? this.staffCat.prefOrg.id() : null
93 copy.active_date = copy.active_date || copy.create_date;