1 import {Component, Input, Output, OnInit, EventEmitter} from '@angular/core';
2 import {NetService} from '@eg/core/net.service';
3 import {PcrudService} from '@eg/core/pcrud.service';
4 import {DialogComponent} from '@eg/share/dialog/dialog.component';
5 import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
6 import {MarcField} from './marcrecord';
7 import {Pager} from '@eg/share/util/pager';
10 * MARC Authority Linking Dialog
14 selector: 'eg-authority-linking-dialog',
15 templateUrl: './authority-linking-dialog.component.html'
18 export class AuthorityLinkingDialogComponent
19 extends DialogComponent implements OnInit {
21 @Input() bibField: MarcField;
22 @Input() thesauri: string = null;
23 @Input() controlSet: number = null;
24 @Input() pager: Pager;
26 browseData: any[] = [];
28 // If false, show the raw MARC field data.
29 showAs: 'heading' | 'marc' = 'heading';
33 selectedSubfields: string[] = [];
36 private modal: NgbModal,
37 private pcrud: PcrudService,
38 private net: NetService) {
44 this.pager = new Pager();
48 this.onOpen$.subscribe(_ => this.initData());
51 fieldHash(field?: MarcField): any {
52 if (!field) { field = this.bibField; }
58 subfields: field.subfields.map(sf => [sf[0], sf[1]])
64 this.pager.offset = 0;
66 this.pcrud.search('acsbf',
67 {tag: this.bibField.tag},
68 {flesh: 1, flesh_fields: {acsbf: ['authority_field']}},
69 {atomic: true, anonymous: true}
71 ).subscribe(bibMetas => {
72 if (bibMetas.length === 0) { return; }
75 if (this.controlSet) {
76 bibMeta = bibMetas.filter(b =>
77 this.controlSet === +b.authority_field().control_set());
79 bibMeta = bibMetas[0];
83 this.authMeta = bibMeta.authority_field();
84 this.bibField.subfields.forEach(sf =>
85 this.selectedSubfields[sf[0]] =
86 this.isControlledBibSf(sf[0])
94 getPage(direction: number) {
99 } else if (direction < 0) {
102 this.pager.offset = 0;
105 const hash = this.fieldHash();
107 // Only search the selected subfields
109 hash.subfields.filter(sf => this.selectedSubfields[sf[0]]);
111 if (hash.subfields.length === 0) { return; }
115 'open-ils.cat.authority.bib_field.linking_browse',
116 hash, this.pager.limit,
117 this.pager.offset, this.thesauri
118 ).subscribe(entry => this.browseData.push(entry));
121 applyHeading(authField: MarcField) {
124 'open-ils.cat.authority.bib_field.overlay_authority',
125 this.fieldHash(), this.fieldHash(authField), this.controlSet
126 ).subscribe(field => this.close(field));
129 isControlledBibSf(sf: string): boolean {
130 return this.authMeta ?
131 this.authMeta.sf_list().includes(sf) : false;