1 /* eslint-disable no-magic-numbers */
3 * Common code for mananging holdings
5 import {Injectable} from '@angular/core';
6 import {IdlObject} from '@eg/core/idl.service';
7 import {tap} from 'rxjs/operators';
8 import {NetService} from '@eg/core/net.service';
9 import {AnonCacheService} from '@eg/share/util/anon-cache.service';
10 import {PcrudService} from '@eg/core/pcrud.service';
11 import {AuthService} from '@eg/core/auth.service';
12 import {EventService} from '@eg/core/event.service';
14 export interface CallNumData {
23 export class HoldingsService {
25 copyStatuses: {[id: number]: IdlObject};
28 private net: NetService,
29 private auth: AuthService,
30 private pcrud: PcrudService,
31 private evt: EventService,
32 private anonCache: AnonCacheService
35 // Open the holdings editor UI in a new browser window/tab.
37 recordId: number, // Bib record ID
38 editExistingCallNums?: number[], // Add copies to / modify existing CNs
39 newCallNumData?: CallNumData[], // Creating new call numbers
40 editCopyIds?: number[], // Edit existing items
41 hideCopies?: boolean, // Hide the copy edit pane
44 const raw: any[] = [];
46 if (editExistingCallNums) {
47 editExistingCallNums.forEach(
48 callNumId => raw.push({callnumber: callNumId}));
49 } else if (newCallNumData) {
50 newCallNumData.forEach(data => raw.push(data));
53 this.anonCache.setItem(null, 'edit-these-copies', {
57 hide_vols : hideVols === true,
58 hide_copies : hideCopies === true
61 console.error('Could not create holds cache key!');
65 const tab = hideVols ? 'attrs' : 'holdings';
66 const url = `/eg2/staff/cat/volcopy/${tab}/session/${key}`;
67 window.open(url, '_blank');
72 // Using open-ils.actor.get_barcodes
73 getItemIdFromBarcode(barcode: string): Promise<number> {
74 return this.net.request(
76 'open-ils.actor.get_barcodes',
77 this.auth.token(), this.auth.user().ws_ou(), 'asset', barcode
78 ).toPromise().then(resp => {
79 if (this.evt.parse(resp)) {
80 return Promise.reject(resp);
81 } else if (resp.length === 0) {
89 /* TODO: make these more configurable per lp1616170 */
90 getMagicCopyStatuses(): Promise<number[]> {
91 return Promise.resolve([
97 18 // Canceled Transit
101 getCopyStatuses(): Promise<{[id: number]: IdlObject}> {
102 if (this.copyStatuses) {
103 return Promise.resolve(this.copyStatuses);
106 this.copyStatuses = {};
107 return this.pcrud.retrieveAll('ccs', {order_by: {ccs: 'name'}})
108 .pipe(tap(stat => this.copyStatuses[stat.id()] = stat))
109 .toPromise().then(_ => this.copyStatuses);