1 import {Component, OnInit, ViewChild, Input, AfterViewInit} from '@angular/core';
2 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
3 import {IdlObject} from '@eg/core/idl.service';
4 import {NetService} from '@eg/core/net.service';
5 import {PcrudService} from '@eg/core/pcrud.service';
7 /* Component for retrieving bib records by ID, TCN */
10 templateUrl: 'bib-by-ident.component.html'
12 export class BibByIdentComponent implements OnInit, AfterViewInit {
14 identType: 'id' | 'tcn' = 'id';
17 multiRecordsFound = false;
20 private router: Router,
21 private route: ActivatedRoute,
22 private net: NetService,
23 private pcrud: PcrudService
27 this.route.paramMap.subscribe((params: ParamMap) => {
28 this.identType = params.get('identType') as 'id' | 'tcn';
33 const node = document.getElementById('bib-ident-value');
34 setTimeout(() => node.focus());
38 if (!this.identValue) { return; }
40 this.notFound = false;
41 this.multiRecordsFound = false;
44 if (this.identType === 'id') {
45 promise = this.getById();
47 } else if (this.identType === 'tcn') {
48 promise = this.getByTcn();
60 getById(): Promise<number> {
61 // Confirm the record exists before redirecting.
62 return this.pcrud.retrieve('bre', this.identValue).toPromise()
63 .then(rec => rec ? rec.id() : null);
66 getByTcn(): Promise<number> {
67 // Start by searching non-deleted records
69 return this.net.request(
71 'open-ils.search.biblio.tcn', this.identValue).toPromise()
75 return Promise.resolve(resp);
78 // No active records, see if we have any deleted records.
79 return this.net.request(
81 'open-ils.search.biblio.tcn', this.identValue, true
88 this.multiRecordsFound = true;
99 goToRecord(id: number) {
100 this.router.navigate([`/staff/catalog/record/${id}`]);