1 import {Injectable} from '@angular/core';
2 import {Observable, empty} from 'rxjs';
3 import {map, switchMap} from 'rxjs/operators';
4 import {IdlObject} from '@eg/core/idl.service';
5 import {Pager} from '@eg/share/util/pager';
6 import {NetService} from '@eg/core/net.service';
7 import {PcrudService} from '@eg/core/pcrud.service';
8 import {OrgService} from '@eg/core/org.service';
9 import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
11 /* Browse APIS and state maintenance */
14 export class BrowseService {
16 // Grid paging is disabled in this UI to support browsing in
17 // both directions. Define our own paging trackers.
22 authorityAxis: string;
23 authorityAxes: ComboboxEntry[];
24 markedForMerge: {[id: number]: boolean} = {};
27 private net: NetService,
28 private org: OrgService,
29 private pcrud: PcrudService
32 fetchAxes(): Promise<any> {
33 if (this.authorityAxes) {
34 return Promise.resolve(this.authorityAxes);
37 this.pcrud.retrieveAll('aba', {}, {atomic: true})
39 this.authorityAxes = axes
40 .map(axis => ({id: axis.code(), label: axis.name()}))
41 .sort((a1, a2) => a1.label < a2.label ? -1 : 1);
46 loadAuthorities(): Observable<any> {
48 if (!this.searchTerm || !this.authorityAxis) {
52 return this.net.request(
54 'open-ils.supercat.authority.browse.by_axis',
55 this.authorityAxis, this.searchTerm,
56 this.pageSize, this.searchOffset
58 ).pipe(switchMap(authIds => {
60 return this.net.request(
62 'open-ils.search.authority.main_entry', authIds
65 })).pipe(map(authMeta => {
67 const oOrg = this.org.get(authMeta.authority.owner());
70 authority: authMeta.authority,
71 link_count: authMeta.linked_bibs.length,
72 heading: authMeta.heading,
73 thesaurus: authMeta.thesaurus,
74 thesaurus_code: authMeta.thesaurus_code,
75 owner: oOrg ? oOrg.shortname() : ''