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} 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 cellPrintValues: (row: any, cell: GridColumn) => string;
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 // Text-ify function for cells that use display templates.
59 this.cellPrintValues = (row: any, cell: GridColumn): string => {
62 return `${row.call_number_prefix_label} ` +
63 `${row.call_number_label} ${row.call_number_suffix_label}`;
65 return this.copyContext.holdable(row);
73 if (!this.recId) { return; }
76 orgName(orgId: number): string {
77 return this.org.get(orgId).shortname();
80 fetchCopies(pager: Pager): Observable<any> {
81 if (!this.recId) { return of([]); }
83 // "Show Result from All Libraries" i.e. global search displays
84 // copies from all branches, sorted by search/pref libs.
85 const copy_depth = this.staffCat.searchContext.global ?
86 this.org.root().ou_type().depth() :
87 this.staffCat.searchContext.searchOrg.ou_type().depth();
89 return this.net.request(
91 'open-ils.search.bib.copies.staff',
93 this.staffCat.searchContext.searchOrg.id(),
97 this.staffCat.prefOrg ? this.staffCat.prefOrg.id() : null
99 copy.active_date = copy.active_date || copy.create_date;