1 import {Component, OnInit, Input, ViewChild} from '@angular/core';
2 import {Observable} from 'rxjs/Observable';
3 import {map} from 'rxjs/operators/map';
4 import {of} from 'rxjs';
5 import {NetService} from '@eg/core/net.service';
6 import {StaffCatalogService} from '../catalog.service';
7 import {Pager} from '@eg/share/util/pager';
8 import {OrgService} from '@eg/core/org.service';
9 import {GridDataSource} from '@eg/share/grid/grid';
10 import {GridComponent} from '@eg/share/grid/grid.component';
13 selector: 'eg-catalog-copies',
14 templateUrl: 'copies.component.html'
16 export class CopiesComponent implements OnInit {
20 gridDataSource: GridDataSource;
21 copyContext: any; // grid context
22 @ViewChild('copyGrid') copyGrid: GridComponent;
24 @Input() set recordId(id: number) {
26 // Only force new data collection when recordId()
27 // is invoked after ngInit() has already run.
29 this.copyGrid.reload();
34 private net: NetService,
35 private org: OrgService,
36 private staffCat: StaffCatalogService,
38 this.gridDataSource = new GridDataSource();
44 this.gridDataSource.getRows = (pager: Pager, sort: any[]) => {
45 // sorting not currently supported
46 return this.fetchCopies(pager);
50 holdable: (copy: any) => {
51 return copy.holdable === 't'
52 && copy.location_holdable === 't'
53 && copy.status_holdable === 't';
59 if (!this.recId) { return; }
62 orgName(orgId: number): string {
63 return this.org.get(orgId).shortname();
66 fetchCopies(pager: Pager): Observable<any> {
67 if (!this.recId) { return of([]); }
69 // "Show Result from All Libraries" i.e. global search displays
70 // copies from all branches, sorted by search/pref libs.
71 const copy_depth = this.staffCat.searchContext.global ?
72 this.org.root().ou_type().depth() :
73 this.staffCat.searchContext.searchOrg.ou_type().depth();
75 return this.net.request(
77 'open-ils.search.bib.copies.staff',
79 this.staffCat.searchContext.searchOrg.id(),
83 this.staffCat.prefOrg ? this.staffCat.prefOrg.id() : null
85 copy.active_date = copy.active_date || copy.create_date;