]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/catalog/catalog.component.ts
LP 2061136 follow-up: ng lint --fix
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / catalog / catalog.component.ts
1 import {Component, HostListener, OnDestroy, OnInit} from '@angular/core';
2 import {IdlObject} from '@eg/core/idl.service';
3 import {StaffCatalogService} from './catalog.service';
4 import {BasketService} from '@eg/share/catalog/basket.service';
5 import {Subject} from 'rxjs';
6 import {takeUntil} from 'rxjs/operators';
7
8 @Component({
9     templateUrl: 'catalog.component.html'
10 })
11 export class CatalogComponent implements OnInit, OnDestroy {
12
13     private onDestroy = new Subject<null>();
14
15     constructor(
16         private basket: BasketService,
17         private staffCat: StaffCatalogService
18     ) {}
19
20     ngOnInit() {
21         // Create the search context that will be used by all of my
22         // child components.  After initial creation, the context is
23         // reset and updated as needed to apply new search parameters.
24         this.staffCat.createContext();
25
26         // listen for hold patron target changes from other tabs
27         // until there's a route change
28         this.staffCat.onChangeHoldPatron().pipe(
29             takeUntil(this.onDestroy)
30         ).subscribe();
31
32         // Subscribe to these emissions so that we can force
33         // change detection in this component even though the
34         // hold-for value was modified by a child component.
35         this.staffCat.holdForChange.subscribe(() => {});
36     }
37
38     // Returns the 'au' object for the patron who we are
39     // trying to place a hold for.
40     holdForUser(): IdlObject {
41         return this.staffCat.holdForUser;
42     }
43
44     clearHoldPatron() {
45         this.staffCat.clearHoldPatron();
46     }
47
48     @HostListener('window:beforeunload')
49     onBeforeUnload(): void {
50         this.staffCat.onBeforeUnload();
51     }
52
53     ngOnDestroy(): void {
54         this.clearHoldPatron();
55         this.onDestroy.next(null);
56     }
57 }
58