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} 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();
33 private net: NetService,
34 private org: OrgService,
35 private staffCat: StaffCatalogService,
37 this.gridDataSource = new GridDataSource();
43 this.gridDataSource.getRows = (pager: Pager, sort: any[]) => {
44 // sorting not currently supported
45 return this.fetchCopies(pager);
49 holdable: (copy: any) => {
50 return copy.holdable === 't'
51 && copy.location_holdable === 't'
52 && copy.status_holdable === 't';
58 if (!this.recId) { return; }
61 orgName(orgId: number): string {
62 return this.org.get(orgId).shortname();
65 fetchCopies(pager: Pager): Observable<any> {
66 if (!this.recId) { return of([]); }
68 // "Show Result from All Libraries" i.e. global search displays
69 // copies from all branches, sorted by search/pref libs.
70 const copy_depth = this.staffCat.searchContext.global ?
71 this.org.root().ou_type().depth() :
72 this.staffCat.searchContext.searchOrg.ou_type().depth();
74 return this.net.request(
76 'open-ils.search.bib.copies.staff',
78 this.staffCat.searchContext.searchOrg.id(),
82 this.staffCat.prefOrg ? this.staffCat.prefOrg.id() : null
84 copy.active_date = copy.active_date || copy.create_date;