]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.ts
LP1806087 Angular catalog Ang7 & lint repairs
[working/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} 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';
12
13 @Component({
14   selector: 'eg-catalog-result-record',
15   templateUrl: 'record.component.html',
16   styleUrls: ['record.component.css']
17 })
18 export class ResultRecordComponent implements OnInit, OnDestroy {
19
20     @Input() index: number;  // 0-index display row
21     @Input() summary: BibRecordSummary;
22     searchContext: CatalogSearchContext;
23     isRecordSelected: boolean;
24     basketSub: Subscription;
25
26     constructor(
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
35     ) {}
36
37     ngOnInit() {
38         this.searchContext = this.staffCat.searchContext;
39         this.summary.getHoldCount();
40         this.isRecordSelected = this.basket.hasRecordId(this.summary.id);
41
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);
45         });
46     }
47
48     ngOnDestroy() {
49         this.basketSub.unsubscribe();
50     }
51
52     orgName(orgId: number): string {
53         return this.org.get(orgId).shortname();
54     }
55
56     iconFormatLabel(code: string): string {
57         return this.cat.iconFormatLabel(code);
58     }
59
60     placeHold(): void {
61         let holdType = 'T';
62         let holdTarget = this.summary.id;
63
64         const ts = this.searchContext.termSearch;
65         if (ts.isMetarecordSearch()) {
66             holdType = 'M';
67             holdTarget = this.summary.metabibId;
68         }
69
70         this.router.navigate([`/staff/catalog/hold/${holdType}`],
71             {queryParams: {target: holdTarget}});
72     }
73
74     addToList(): void {
75         alert('Adding to list for bib ' + this.summary.id);
76     }
77
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();
83     }
84
85     /**
86      * Propagate the search params along when navigating to each record.
87      */
88     navigateToRecord(summary: BibRecordSummary) {
89         const params = this.catUrl.toUrlParams(this.searchContext);
90
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();
96             return;
97         }
98
99         this.router.navigate(
100             ['/staff/catalog/record/' + summary.id], {queryParams: params});
101     }
102
103     toggleBasketEntry() {
104         if (this.isRecordSelected) {
105             return this.basket.addRecordIds([this.summary.id]);
106         } else {
107             return this.basket.removeRecordIds([this.summary.id]);
108         }
109     }
110 }
111
112