1 import {Component, OnInit, ViewChild} from '@angular/core';
2 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
3 import {Observable, empty} from 'rxjs';
4 import {map, switchMap} from 'rxjs/operators';
5 import {NgbTabset, NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap';
6 import {IdlObject} from '@eg/core/idl.service';
7 import {Pager} from '@eg/share/util/pager';
8 import {NetService} from '@eg/core/net.service';
9 import {PcrudService} from '@eg/core/pcrud.service';
10 import {OrgService} from '@eg/core/org.service';
11 import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
13 /* Find, merge, and edit authority records */
16 templateUrl: 'manage.component.html'
18 export class ManageAuthorityComponent implements OnInit {
23 linkedBibIdSource: (pager: Pager, sort: any) => Promise<number[]>;
26 private router: Router,
27 private route: ActivatedRoute,
28 private net: NetService,
29 private org: OrgService,
30 private pcrud: PcrudService
35 this.route.paramMap.subscribe((params: ParamMap) => {
36 this.authTab = params.get('tab') || 'bibs';
37 const id = +params.get('id');
39 if (id !== this.authId) {
44 'open-ils.search.authority.main_entry', this.authId
45 ).subscribe(meta => this.authMeta = meta);
49 this.linkedBibIdSource = (pager: Pager, sort: any) => {
50 return this.getLinkedBibIds(pager, sort);
54 getLinkedBibIds(pager: Pager, sort: any): Promise<number[]> {
55 const orderBy: any = {};
56 if (sort.length && sort[0].name === 'id') {
57 orderBy.abl = 'bib ' + sort[0].dir;
59 return this.pcrud.search('abl',
60 {authority: this.authId},
61 {limit: pager.limit, offset: pager.offset, order_by: orderBy},
63 ).pipe(map(links => links.map(l => l.bib()))
67 // Changing a tab in the UI means changing the route.
68 // Changing the route ultimately results in changing the tab.
69 beforeTabChange(evt: NgbTabChangeEvent) {
71 // prevent tab changing until after route navigation
74 this.authTab = evt.nextId;
80 `/staff/cat/authority/manage/${this.authId}/${this.authTab}`;
81 this.router.navigate([url]);