]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.ts
664d36661e2c634238384a5c51f9c4f4e38d6518
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / catalog / result / record.component.ts
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
14 @Component({
15   selector: 'eg-catalog-result-record',
16   templateUrl: 'record.component.html',
17   styleUrls: ['record.component.css']
18 })
19 export class ResultRecordComponent implements OnInit, OnDestroy {
20
21     @Input() index: number;  // 0-index display row
22     @Input() summary: BibRecordSummary;
23
24     // Optional call number (acn) object to highlight
25     // Assumed prefix/suffix are fleshed
26     // Used by call number browse.
27     @Input() callNumber: IdlObject;
28
29     searchContext: CatalogSearchContext;
30     isRecordSelected: boolean;
31     basketSub: Subscription;
32
33     constructor(
34         private router: Router,
35         private org: OrgService,
36         private net: NetService,
37         private bib: BibRecordService,
38         private cat: CatalogService,
39         private catUrl: CatalogUrlService,
40         private staffCat: StaffCatalogService,
41         private basket: BasketService
42     ) {}
43
44     ngOnInit() {
45         this.searchContext = this.staffCat.searchContext;
46         this.isRecordSelected = this.basket.hasRecordId(this.summary.id);
47
48         // Watch for basket changes caused by other components
49         this.basketSub = this.basket.onChange.subscribe(() => {
50             this.isRecordSelected = this.basket.hasRecordId(this.summary.id);
51         });
52     }
53
54     ngOnDestroy() {
55         this.basketSub.unsubscribe();
56     }
57
58     orgName(orgId: number): string {
59         return this.org.get(orgId).shortname();
60     }
61
62     iconFormatLabel(code: string): string {
63         return this.cat.iconFormatLabel(code);
64     }
65
66     placeHold(): void {
67         let holdType = 'T';
68         let holdTarget = this.summary.id;
69
70         const ts = this.searchContext.termSearch;
71         if (ts.isMetarecordSearch()) {
72             holdType = 'M';
73             holdTarget = this.summary.metabibId;
74         }
75
76         this.router.navigate([`/staff/catalog/hold/${holdType}`],
77             {queryParams: {target: holdTarget}});
78     }
79
80     addToList(): void {
81         alert('Adding to list for bib ' + this.summary.id);
82     }
83
84     // Params to genreate a new author search based on a reset
85     // clone of the current page params.
86     getAuthorSearchParams(summary: BibRecordSummary): any {
87         return this.staffCat.getAuthorSearchParams(summary);
88     }
89
90     // Returns the URL parameters for the current page plus the
91     // "fromMetarecord" param used for linking title links to
92     // MR constituent result records list.
93     appendFromMrParam(summary: BibRecordSummary): any {
94         const tmpContext = this.staffCat.cloneContext(this.searchContext);
95         tmpContext.termSearch.fromMetarecord = summary.metabibId;
96         return this.catUrl.toUrlParams(tmpContext);
97     }
98
99     // Returns true if the selected record summary is a metarecord summary
100     // and it links to more than one constituent bib record.
101     hasMrConstituentRecords(summary: BibRecordSummary): boolean {
102         return (
103             summary.metabibId && summary.metabibRecords.length > 1
104         );
105     }
106
107     currentParams(): any {
108         return this.catUrl.toUrlParams(this.searchContext);
109     }
110
111     toggleBasketEntry() {
112         if (this.isRecordSelected) {
113             return this.basket.addRecordIds([this.summary.id]);
114         } else {
115             return this.basket.removeRecordIds([this.summary.id]);
116         }
117     }
118 }
119
120