1 import {Component, Input, OnInit, 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 {CatalogSearchContext, CatalogSearchState} from '@eg/share/catalog/search-context';
9 import {StaffCatalogService} from './catalog.service';
10 import {BucketDialogComponent
11 } from '@eg/staff/share/buckets/bucket-dialog.component';
12 import {ProgressDialogComponent} from '@eg/share/dialog/progress.component';
14 const MAX_FROM_SEARCH_RESULTS = 1000;
17 selector: 'eg-catalog-basket-actions',
18 templateUrl: 'basket-actions.component.html'
20 export class BasketActionsComponent implements OnInit {
24 @ViewChild('addBasketToBucketDialog', { static: true })
25 addToBucketDialog: BucketDialogComponent;
27 @ViewChild('addAllProgress', {static: true})
28 addAllProgress: ProgressDialogComponent;
31 private router: Router,
32 private net: NetService,
33 private auth: AuthService,
34 private printer: PrintService,
35 private basket: BasketService,
36 private cat: CatalogService,
37 private staffCat: StaffCatalogService
39 this.basketAction = '';
45 basketCount(): number {
46 return this.basket.recordCount();
49 isMetarecordSearch(): boolean {
50 return this.staffCat.searchContext &&
51 this.staffCat.searchContext.termSearch.isMetarecordSearch();
54 // TODO: confirmation dialogs?
56 applyAction(action: string) {
57 this.basketAction = action;
59 switch (this.basketAction) {
62 // Add all search results to basket.
64 this.addAllProgress.open();
66 const ctx = this.staffCat.cloneContext(this.staffCat.searchContext);
68 ctx.pager.limit = MAX_FROM_SEARCH_RESULTS;
71 .then(_ => this.basket.addRecordIds(ctx.currentResultIds()))
72 .then(_ => this.addAllProgress.close());
77 // This does not propagate search params -- unclear if needed.
78 this.router.navigate(['/staff/catalog/search'],
79 {queryParams: {showBasket: true}});
83 this.basket.removeAllRecordIds();
87 this.basket.getRecordIds().then(ids => {
88 this.router.navigate(['/staff/catalog/hold/T'],
89 {queryParams: {target: ids}});
94 this.basket.getRecordIds().then(ids => {
97 'open-ils.search.biblio.record.print', ids
101 const html = at_event.template_output().data();
104 printContext: 'default'
112 this.basket.getRecordIds().then(ids => {
115 'open-ils.search.biblio.record.email',
116 this.auth.token(), ids
117 ).toPromise(); // fire-and-forget
122 this.router.navigate(
123 ['/staff/cat/vandelay/export/basket'],
124 {queryParamsHandling: 'merge'}
129 this.basket.getRecordIds().then(ids => {
130 this.addToBucketDialog.bucketClass = 'biblio';
131 this.addToBucketDialog.itemIds = ids;
132 this.addToBucketDialog.open({size: 'lg'});
138 // Resetting basketAction inside its onchange handler
139 // prevents the new value from propagating to Angular
140 // Reset after the current thread.
141 setTimeout(() => this.basketAction = ''); // reset