1 import {Component, ViewChild} from '@angular/core';
2 import {BasketService} from '@eg/share/catalog/basket.service';
3 import {Router} from '@angular/router';
4 import {NetService} from '@eg/core/net.service';
5 import {AuthService} from '@eg/core/auth.service';
6 import {PrintService} from '@eg/share/print/print.service';
7 import {CatalogService} from '@eg/share/catalog/catalog.service';
8 import {StaffCatalogService} from './catalog.service';
9 import {BucketDialogComponent
10 } from '@eg/staff/share/buckets/bucket-dialog.component';
11 import {ProgressDialogComponent} from '@eg/share/dialog/progress.component';
13 const MAX_FROM_SEARCH_RESULTS = 1000;
16 selector: 'eg-catalog-basket-actions',
17 templateUrl: 'basket-actions.component.html'
19 export class BasketActionsComponent {
23 @ViewChild('addBasketToBucketDialog', { static: true })
24 addToBucketDialog: BucketDialogComponent;
26 @ViewChild('addAllProgress', {static: true})
27 addAllProgress: ProgressDialogComponent;
30 private router: Router,
31 private net: NetService,
32 private auth: AuthService,
33 private printer: PrintService,
34 private basket: BasketService,
35 private cat: CatalogService,
36 private staffCat: StaffCatalogService
38 this.basketAction = '';
41 basketCount(): number {
42 return this.basket.recordCount();
45 isMetarecordSearch(): boolean {
46 return this.staffCat.searchContext &&
47 this.staffCat.searchContext.termSearch.isMetarecordSearch();
50 // TODO: confirmation dialogs?
52 applyAction(action: string) {
53 this.basketAction = action;
55 switch (this.basketAction) {
58 // Add all search results to basket.
60 this.addAllProgress.open();
62 // eslint-disable-next-line no-case-declarations
63 const ctx = this.staffCat.cloneContext(this.staffCat.searchContext);
65 ctx.pager.limit = MAX_FROM_SEARCH_RESULTS;
68 .then(_ => this.basket.addRecordIds(ctx.currentResultIds()))
69 .then(_ => this.addAllProgress.close());
74 // This does not propagate search params -- unclear if needed.
75 this.router.navigate(['/staff/catalog/search'],
76 {queryParams: {showBasket: true}});
80 this.basket.removeAllRecordIds();
84 this.basket.getRecordIds().then(ids => {
85 this.router.navigate(['/staff/catalog/hold/T'],
86 {queryParams: {target: ids}});
91 this.basket.getRecordIds().then(ids => {
94 'open-ils.search.biblio.record.print', ids
98 const html = at_event.template_output().data();
101 printContext: 'default'
109 this.basket.getRecordIds().then(ids => {
112 'open-ils.search.biblio.record.email',
113 this.auth.token(), ids
114 ).toPromise(); // fire-and-forget
119 this.router.navigate(
120 ['/staff/cat/vandelay/export/basket'],
121 {queryParamsHandling: 'merge'}
126 this.basket.getRecordIds().then(ids => {
127 this.addToBucketDialog.bucketClass = 'biblio';
128 this.addToBucketDialog.itemIds = ids;
129 this.addToBucketDialog.open({size: 'lg'});
135 // Resetting basketAction inside its onchange handler
136 // prevents the new value from propagating to Angular
137 // Reset after the current thread.
138 setTimeout(() => this.basketAction = ''); // reset