1 import {Component, OnInit, OnDestroy, Input} from '@angular/core';
2 import {Subscription} from 'rxjs';
3 import {Router} from '@angular/router';
4 import {OrgService} from '@eg/core/org.service';
5 import {NetService} from '@eg/core/net.service';
6 import {CatalogService} from '@eg/share/catalog/catalog.service';
7 import {BibRecordService, BibRecordSummary} from '@eg/share/catalog/bib-record.service';
8 import {CatalogSearchContext} from '@eg/share/catalog/search-context';
9 import {CatalogUrlService} from '@eg/share/catalog/catalog-url.service';
10 import {StaffCatalogService} from '../catalog.service';
11 import {BasketService} from '@eg/share/catalog/basket.service';
14 selector: 'eg-catalog-result-record',
15 templateUrl: 'record.component.html',
16 styleUrls: ['record.component.css']
18 export class ResultRecordComponent implements OnInit, OnDestroy {
20 @Input() index: number; // 0-index display row
21 @Input() summary: BibRecordSummary;
22 searchContext: CatalogSearchContext;
23 isRecordSelected: boolean;
24 basketSub: Subscription;
27 private router: Router,
28 private org: OrgService,
29 private net: NetService,
30 private bib: BibRecordService,
31 private cat: CatalogService,
32 private catUrl: CatalogUrlService,
33 private staffCat: StaffCatalogService,
34 private basket: BasketService
38 this.searchContext = this.staffCat.searchContext;
39 this.summary.getHoldCount();
40 this.isRecordSelected = this.basket.hasRecordId(this.summary.id);
42 // Watch for basket changes caused by other components
43 this.basketSub = this.basket.onChange.subscribe(() => {
44 this.isRecordSelected = this.basket.hasRecordId(this.summary.id);
49 this.basketSub.unsubscribe();
52 orgName(orgId: number): string {
53 return this.org.get(orgId).shortname();
56 iconFormatLabel(code: string): string {
57 return this.cat.iconFormatLabel(code);
62 let holdTarget = this.summary.id;
64 const ts = this.searchContext.termSearch;
65 if (ts.isMetarecordSearch()) {
67 holdTarget = this.summary.metabibId;
70 this.router.navigate([`/staff/catalog/hold/${holdType}`],
71 {queryParams: {target: holdTarget}});
75 alert('Adding to list for bib ' + this.summary.id);
78 searchAuthor(summary: any) {
79 this.searchContext.reset();
80 this.searchContext.termSearch.fieldClass = ['author'];
81 this.searchContext.termSearch.query = [summary.display.author];
82 this.staffCat.search();
86 * Propagate the search params along when navigating to each record.
88 navigateToRecord(summary: BibRecordSummary) {
89 const params = this.catUrl.toUrlParams(this.searchContext);
91 // Jump to metarecord constituent records page when a
92 // MR has more than 1 constituents.
93 if (summary.metabibId && summary.metabibRecords.length > 1) {
94 this.searchContext.termSearch.fromMetarecord = summary.metabibId;
95 this.staffCat.search();
100 ['/staff/catalog/record/' + summary.id], {queryParams: params});
103 toggleBasketEntry() {
104 if (this.isRecordSelected) {
105 return this.basket.addRecordIds([this.summary.id]);
107 return this.basket.removeRecordIds([this.summary.id]);