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 const ctx = this.staffCat.cloneContext(this.staffCat.searchContext);
64 ctx.pager.limit = MAX_FROM_SEARCH_RESULTS;
67 .then(_ => this.basket.addRecordIds(ctx.currentResultIds()))
68 .then(_ => this.addAllProgress.close());
73 // This does not propagate search params -- unclear if needed.
74 this.router.navigate(['/staff/catalog/search'],
75 {queryParams: {showBasket: true}});
79 this.basket.removeAllRecordIds();
83 this.basket.getRecordIds().then(ids => {
84 this.router.navigate(['/staff/catalog/hold/T'],
85 {queryParams: {target: ids}});
90 this.basket.getRecordIds().then(ids => {
93 'open-ils.search.biblio.record.print', ids
97 const html = at_event.template_output().data();
100 printContext: 'default'
108 this.basket.getRecordIds().then(ids => {
111 'open-ils.search.biblio.record.email',
112 this.auth.token(), ids
113 ).toPromise(); // fire-and-forget
118 this.router.navigate(
119 ['/staff/cat/vandelay/export/basket'],
120 {queryParamsHandling: 'merge'}
125 this.basket.getRecordIds().then(ids => {
126 this.addToBucketDialog.bucketClass = 'biblio';
127 this.addToBucketDialog.itemIds = ids;
128 this.addToBucketDialog.open({size: 'lg'});
134 // Resetting basketAction inside its onchange handler
135 // prevents the new value from propagating to Angular
136 // Reset after the current thread.
137 setTimeout(() => this.basketAction = ''); // reset