1 import {Component, OnInit, OnDestroy, Input} from '@angular/core';
2 import {Subscription} from 'rxjs';
3 import {Router, ParamMap} from '@angular/router';
4 import {OrgService} from '@eg/core/org.service';
5 import {NetService} from '@eg/core/net.service';
6 import {IdlObject} from '@eg/core/idl.service';
7 import {CatalogService} from '@eg/share/catalog/catalog.service';
8 import {BibRecordService, BibRecordSummary} from '@eg/share/catalog/bib-record.service';
9 import {CatalogSearchContext} from '@eg/share/catalog/search-context';
10 import {CatalogUrlService} from '@eg/share/catalog/catalog-url.service';
11 import {StaffCatalogService} from '../catalog.service';
12 import {BasketService} from '@eg/share/catalog/basket.service';
13 import {CourseService} from '@eg/staff/share/course.service';
16 selector: 'eg-catalog-result-record',
17 templateUrl: 'record.component.html',
18 styleUrls: ['record.component.css']
20 export class ResultRecordComponent implements OnInit, OnDestroy {
22 @Input() index: number; // 0-index display row
23 @Input() summary: BibRecordSummary;
25 // Optional call number (acn) object to highlight
26 // Assumed prefix/suffix are fleshed
27 // Used by call number browse.
28 @Input() callNumber: IdlObject;
30 searchContext: CatalogSearchContext;
31 isRecordSelected: boolean;
32 basketSub: Subscription;
34 courseNames: any[] = [];
37 private router: Router,
38 private org: OrgService,
39 private net: NetService,
40 private bib: BibRecordService,
41 private cat: CatalogService,
42 private catUrl: CatalogUrlService,
43 private staffCat: StaffCatalogService,
44 private basket: BasketService,
45 private course: CourseService
49 this.searchContext = this.staffCat.searchContext;
50 this.loadCourseInformation(this.summary.id)
51 this.isRecordSelected = this.basket.hasRecordId(this.summary.id);
53 // Watch for basket changes caused by other components
54 this.basketSub = this.basket.onChange.subscribe(() => {
55 this.isRecordSelected = this.basket.hasRecordId(this.summary.id);
60 this.basketSub.unsubscribe();
63 loadCourseInformation(recordId) {
64 console.log("Entering loadCourseInformation");
65 this.course.isOptedIn().then(res => {
67 this.course.fetchCopiesInCourseFromRecord(recordId).then(course_list => {
68 Object.keys(course_list).forEach(key => {
69 this.courseNames.push(course_list[key].name() +
70 "(" + course_list[key].course_number() + ")");
72 this.has_course = true;
75 this.has_course = false;
80 orgName(orgId: number): string {
81 return this.org.get(orgId).shortname();
84 iconFormatLabel(code: string): string {
85 return this.cat.iconFormatLabel(code);
90 let holdTarget = this.summary.id;
92 const ts = this.searchContext.termSearch;
93 if (ts.isMetarecordSearch()) {
95 holdTarget = this.summary.metabibId;
98 this.router.navigate([`/staff/catalog/hold/${holdType}`],
99 {queryParams: {target: holdTarget}});
103 alert('Adding to list for bib ' + this.summary.id);
106 // Params to genreate a new author search based on a reset
107 // clone of the current page params.
108 getAuthorSearchParams(summary: BibRecordSummary): any {
109 return this.staffCat.getAuthorSearchParams(summary);
112 // Returns the URL parameters for the current page plus the
113 // "fromMetarecord" param used for linking title links to
114 // MR constituent result records list.
115 appendFromMrParam(summary: BibRecordSummary): any {
116 const tmpContext = this.staffCat.cloneContext(this.searchContext);
117 tmpContext.termSearch.fromMetarecord = summary.metabibId;
118 return this.catUrl.toUrlParams(tmpContext);
121 // Returns true if the selected record summary is a metarecord summary
122 // and it links to more than one constituent bib record.
123 hasMrConstituentRecords(summary: BibRecordSummary): boolean {
125 summary.metabibId && summary.metabibRecords.length > 1
129 currentParams(): any {
130 return this.catUrl.toUrlParams(this.searchContext);
133 toggleBasketEntry() {
134 if (this.isRecordSelected) {
135 return this.basket.addRecordIds([this.summary.id]);
137 return this.basket.removeRecordIds([this.summary.id]);