]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts
LP2061136 - Stamping 1405 DB upgrade script
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / share / holds / grid.component.ts
1 import {Component, OnInit, Input, Output, EventEmitter, ViewChild} from '@angular/core';
2 import {Location} from '@angular/common';
3 import {Observable, Observer, of, from} from 'rxjs';
4 import {concatMap} from 'rxjs/operators';
5 import {IdlObject} from '@eg/core/idl.service';
6 import {NetService} from '@eg/core/net.service';
7 import {OrgService} from '@eg/core/org.service';
8 import {AuthService} from '@eg/core/auth.service';
9 import {Pager} from '@eg/share/util/pager';
10 import {ServerStoreService} from '@eg/core/server-store.service';
11 import {GridDataSource, GridCellTextGenerator} from '@eg/share/grid/grid';
12 import {GridComponent} from '@eg/share/grid/grid.component';
13 import {ProgressDialogComponent} from '@eg/share/dialog/progress.component';
14 import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
15 import {MarkDamagedDialogComponent
16 } from '@eg/staff/share/holdings/mark-damaged-dialog.component';
17 import {MarkMissingDialogComponent
18 } from '@eg/staff/share/holdings/mark-missing-dialog.component';
19 import {MarkDiscardDialogComponent
20 } from '@eg/staff/share/holdings/mark-discard-dialog.component';
21 import {HoldRetargetDialogComponent
22 } from '@eg/staff/share/holds/retarget-dialog.component';
23 import {HoldTransferDialogComponent} from './transfer-dialog.component';
24 import {HoldCancelDialogComponent} from './cancel-dialog.component';
25 import {HoldManageDialogComponent} from './manage-dialog.component';
26 import {PrintService} from '@eg/share/print/print.service';
27 import {HoldingsService} from '@eg/staff/share/holdings/holdings.service';
28 import {OrgSelectComponent} from '@eg/share/org-select/org-select.component';
29 import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
30 import {HoldCopyLocationsDialogComponent} from './copy-locations-dialog.component';
31
32 /** Holds grid with access to detail page and other actions */
33
34 @Component({
35     selector: 'eg-holds-grid',
36     templateUrl: 'grid.component.html',
37     styles: ['.input-group > .form-control { width: auto; flex-grow: 0; }']
38 })
39 export class HoldsGridComponent implements OnInit {
40
41     // Hide the "Holds Count" header
42     @Input() hideHoldsCount = false;
43
44     // If either are set/true, the pickup lib selector will display
45     @Input() initialPickupLib: number | IdlObject;
46     @Input() hidePickupLibFilter: boolean;
47
48     // Setting a value here puts us into "pull list" mode.
49     @Input() pullListOrg: number;
50
51     // If true, only retrieve holds with a Hopeless Date
52     // and enable related Actions
53     @Input() hopeless: boolean;
54
55     // Grid persist key
56     @Input() persistKey: string;
57
58     @Input() preFetchSetting: string;
59
60     @Input() printTemplate: string;
61
62     // Adds a Place Hold grid toolbar button that emits
63     // placeHoldRequested on click.
64     @Input() showPlaceHoldButton = false;
65
66     // If set, all holds are fetched on grid load and sorting/paging all
67     // happens in the client.  If false, sorting and paging occur on
68     // the server.
69     @Input() enablePreFetch: boolean;
70
71     // How to sort when no sort parameters have been applied
72     // via grid controls.  This uses the eg-grid sort format:
73     // [{name: fname, dir: 'asc'}, {name: fname2, dir: 'desc'}]
74     @Input() defaultSort: any[];
75
76     // To pass through to the underlying eg-grid
77     @Input() showFields: string;
78
79     // Display bib record summary along the top of the detail page.
80     @Input() showRecordSummary = false;
81
82     // If true, avoid popping up the progress dialog.  Note the grid
83     // has it's own generic embedded 'loading' progress indicator.
84     @Input() noLoadProgress = false;
85
86     // Some default columns and actions do or don't make sense when
87     // displaying holds for a specific patron vs. e.g. a specific title.
88     @Input() patronFocused = false;
89
90     mode: 'list' | 'detail' | 'manage' = 'list';
91     initDone = false;
92     holdsCount: number;
93     pickupLib: IdlObject;
94     plCompLoaded = false;
95     gridDataSource: GridDataSource;
96     detailHold: any;
97     editHolds: number[];
98     transferTarget: number;
99     uncancelHoldCount: number;
100     copyLocationClass?: string;
101     copyLocationEntries: ComboboxEntry[] = [];
102     copyLocationIds: number[] = [];
103
104     @ViewChild('holdsGrid', { static: false }) private holdsGrid: GridComponent;
105     @ViewChild('progressDialog', { static: true })
106     private progressDialog: ProgressDialogComponent;
107     @ViewChild('transferDialog', { static: true })
108     private transferDialog: HoldTransferDialogComponent;
109     @ViewChild('markDamagedDialog', { static: true })
110     private markDamagedDialog: MarkDamagedDialogComponent;
111     @ViewChild('markMissingDialog', { static: true })
112     private markMissingDialog: MarkMissingDialogComponent;
113     @ViewChild('markDiscardDialog')
114     private markDiscardDialog: MarkDiscardDialogComponent;
115     @ViewChild('retargetDialog', { static: true })
116     private retargetDialog: HoldRetargetDialogComponent;
117     @ViewChild('cancelDialog', { static: true })
118     private cancelDialog: HoldCancelDialogComponent;
119     @ViewChild('manageDialog', { static: true })
120     private manageDialog: HoldManageDialogComponent;
121     @ViewChild('uncancelDialog') private uncancelDialog: ConfirmDialogComponent;
122     @ViewChild('copyLocationsDialog')
123     private copyLocationsDialog: HoldCopyLocationsDialogComponent;
124     @ViewChild('clearCopyLocationsDialog')
125     private clearCopyLocationsDialog: ConfirmDialogComponent;
126     @ViewChild('pullPickupLibFilter')
127     private pullPickupLibFilter: OrgSelectComponent;
128
129     // Bib record ID.
130     _recordId: number;
131     @Input() set recordId(id: number) {
132         this._recordId = id;
133         if (this.initDone) { // reload on update
134             this.holdsGrid.reload();
135         }
136     }
137
138     get recordId(): number {
139         return this._recordId;
140     }
141
142     _patronId: number;
143     @Input() set patronId(id: number) {
144         this._patronId = id;
145         if (this.initDone) {
146             this.holdsGrid.reload();
147         }
148     }
149     get patronId(): number {
150         return this._patronId;
151     }
152
153     // If true, show recently canceled holds only.
154     @Input() showRecentlyCanceled = false;
155
156     // Include holds fulfilled on or after hte provided date.
157     // If no value is passed, fulfilled holds are not displayed.
158     _showFulfilledSince: Date;
159     @Input() set showFulfilledSince(show: Date) {
160         this._showFulfilledSince = show;
161         if (this.initDone) { // reload on update
162             this.holdsGrid.reload();
163         }
164     }
165     get showFulfilledSince(): Date {
166         return this._showFulfilledSince;
167     }
168
169
170     cellTextGenerator: GridCellTextGenerator;
171
172     // Include holds marked Hopeless on or after this date.
173     _showHopelessAfter: Date;
174     @Input() set showHopelessAfter(show: Date) {
175         this._showHopelessAfter = show;
176         if (this.initDone) { // reload on update
177             this.holdsGrid.reload();
178         }
179     }
180
181     // Include holds marked Hopeless on or before this date.
182     _showHopelessBefore: Date;
183     @Input() set showHopelessBefore(show: Date) {
184         this._showHopelessBefore = show;
185         if (this.initDone) { // reload on update
186             this.holdsGrid.reload();
187         }
188     }
189
190     // Notify the caller the place hold button was clicked.
191     @Output() placeHoldRequested: EventEmitter<void> = new EventEmitter<void>();
192
193     constructor(
194         private ngLocation: Location,
195         private net: NetService,
196         private org: OrgService,
197         private store: ServerStoreService,
198         private auth: AuthService,
199         private printer: PrintService,
200         private holdings: HoldingsService
201     ) {
202         this.gridDataSource = new GridDataSource();
203         this.enablePreFetch = null;
204     }
205
206     ngOnInit() {
207         this.initDone = true;
208         this.pickupLib = this.org.get(this.initialPickupLib);
209
210         if (this.preFetchSetting) {
211             this.store.getItem(this.preFetchSetting).then(
212                 applied => this.enablePreFetch = Boolean(applied)
213             );
214         } else {
215             this.enablePreFetch = false;
216         }
217
218         if (!this.defaultSort) {
219             if (this.pullListOrg) {
220
221                 this.defaultSort = [
222                     {name: 'copy_location_order_position', dir: 'asc'},
223                     {name: 'acpl_name', dir: 'asc'},
224                     {name: 'ancp_label', dir: 'asc'}, // NOTE: API typo "ancp"
225                     {name: 'cn_label_sortkey', dir: 'asc'},
226                     {name: 'ancs_label', dir: 'asc'} // NOTE: API typo "ancs"
227                 ];
228
229             } else {
230                 this.defaultSort = [{name: 'request_time', dir: 'asc'}];
231             }
232         }
233
234         this.gridDataSource.getRows = (pager: Pager, sort: any[]) => {
235
236             if (!this.hidePickupLibFilter || this.pullListOrg) {
237                 // When the pickup lib selector is active, avoid any
238                 // data fetches until it has settled on a default value.
239                 // Once the final value is applied, its onchange will
240                 // fire and we'll be back here with plCompLoaded=true.
241                 if (!this.plCompLoaded) {return of([]);}
242             }
243
244             sort = sort.length > 0 ? sort : this.defaultSort;
245             return this.fetchHolds(pager, sort);
246         };
247
248         // Text-ify function for cells that use display templates.
249         this.cellTextGenerator = {
250             title: row => row.title,
251             // eslint-disable-next-line eqeqeq
252             cp_barcode: row => (row.cp_barcode == null) ? '' : row.cp_barcode,
253             current_item: row => row.current_copy ? row.cp_barcode : '',
254             requested_item: row => this.isCopyHold(row) ? row.cp_barcode : '',
255             ucard_barcode: row => row.ucard_barcode,
256             status_string: row => {
257                 switch (row.hold_status) {
258                     /* eslint-disable no-magic-numbers */
259                     case 1:
260                         return $localize`Waiting for Item`;
261                     case 2:
262                         return $localize`Waiting for Capture`;
263                     case 3:
264                         return $localize`In Transit`;
265                     case 4:
266                         return $localize`Ready for Pickup`;
267                     case 5:
268                         return $localize`Hold Shelf Delay`;
269                     case 6:
270                         return $localize`Canceled`;
271                     case 7:
272                         return $localize`Suspended`;
273                     case 8:
274                         return $localize`Wrong Shelf`;
275                     case 9:
276                         return $localize`Fulfilled`;
277                     default:
278                         return $localize`Unknown Error`;
279                     /* eslint-enable no-magic-numbers */
280                 }
281             }
282         };
283
284         if (this.pullListOrg) {
285             this.store.getItem('eg.holds.pull_list_filters').then(data => {
286                 if (data) {
287                     this.copyLocationClass = data.copyLocationClass;
288                     this.copyLocationEntries = data.copyLocationEntries;
289                     this.copyLocationIds = data.copyLocationIds;
290                     if (data.pickupLib) {
291                         this.pickupLib = this.org.get(data.pickupLib);
292                     }
293                 } else {
294                     this.copyLocationClass = 'acpl';
295                 }
296             });
297         }
298     }
299
300     // Returns true after all data/settings/etc required to render the
301     // grid have been fetched.
302     initComplete(): boolean {
303         return this.enablePreFetch !== null;
304     }
305
306     pickupLibChanged(org: IdlObject) {
307         this.pickupLib = org;
308         this.holdsGrid.reload();
309     }
310
311     pullPickupLibLoaded(): void {
312         this.plCompLoaded = true;
313         this.holdsGrid.reload();
314     }
315
316     resetPullPickupLibFilter(): void {
317         if (this.pickupLib) {
318             this.pullPickupLibFilter.reset();
319         }
320     }
321
322     pullPickupLibChanged(org: IdlObject): void {
323         if (org?.id() !== this.pickupLib?.id()) {
324             this.pickupLib = org;
325             this.savePullFilterSettings();
326             this.holdsGrid.reload();
327         }
328     }
329
330     openCopyLocationsDialog(): void {
331         this.copyLocationsDialog.init();
332         this.copyLocationsDialog.open({size: 'lg'}).subscribe(
333             ([fmClass, entries, ids]) => {
334                 this.copyLocationClass = fmClass;
335                 this.copyLocationEntries = entries;
336                 this.copyLocationIds = ids;
337                 this.savePullFilterSettings();
338                 this.holdsGrid.reload();
339             }
340         );
341     }
342
343     clearCopyLocations(): void {
344         if (!this.copyLocationEntries.length) {return;}
345         this.clearCopyLocationsDialog.open().subscribe(data => {
346             if (data) {
347                 this.copyLocationClass = 'acpl';
348                 this.copyLocationEntries = [];
349                 this.copyLocationIds = [];
350                 this.savePullFilterSettings();
351                 this.holdsGrid.reload();
352             }
353         });
354     }
355
356     pullListSettingsLoaded(): boolean {
357         return !!this.copyLocationClass;
358     }
359
360     savePullFilterSettings(): void {
361         this.store.setItem('eg.holds.pull_list_filters', {
362             copyLocationClass: this.copyLocationClass,
363             copyLocationEntries: this.copyLocationEntries,
364             copyLocationIds: this.copyLocationIds,
365             pickupLib: this.pickupLib ? +this.pickupLib.id() : undefined
366         });
367     }
368
369     pullListOrgChanged(org: IdlObject): void {
370         if (org && +org.id() !== +this.pullListOrg) {
371             this.pullListOrg = org.id();
372             this.holdsGrid.reload();
373         }
374     }
375
376     preFetchHolds(apply: boolean) {
377         this.enablePreFetch = apply;
378
379         if (apply) {
380             setTimeout(() => this.holdsGrid.reload());
381         }
382
383         if (this.preFetchSetting) {
384             // fire and forget
385             this.store.setItem(this.preFetchSetting, apply);
386         }
387     }
388
389     applyFilters(): any {
390
391         const filters: any = {};
392
393         if (this.copyLocationIds.length) {
394             filters['acpl.id'] = this.copyLocationIds;
395         }
396
397         if (this.pickupLib) {
398             filters.pickup_lib =
399                 this.org.descendants(this.pickupLib, true);
400         }
401
402         if (this.pullListOrg) {
403             filters.cancel_time = null;
404             filters.capture_time = null;
405             filters.frozen = 'f';
406
407             // cp.* fields are set for copy-level holds even if they
408             // have no current_copy.  Make sure current_copy is set.
409             filters.current_copy = {'is not': null};
410
411             // There are aliases for these (cp_status, cp_circ_lib),
412             // but the API complains when I use them.
413             filters['cp.status'] = {'in':{'select':{'ccs':['id']},'from':'ccs','where':{'holdable':'t','is_available':'t'}}};
414             filters['cp.circ_lib'] = this.pullListOrg;
415             // Avoid deleted copies AND this uses a database index on copy circ_lib where deleted is false.
416             filters['cp.deleted'] = 'f';
417
418             return filters;
419         }
420
421         if (this._showFulfilledSince) {
422             filters.fulfillment_time = this._showFulfilledSince.toISOString();
423         } else {
424             filters.fulfillment_time = null;
425         }
426
427
428         if (this.hopeless) {
429             filters['hopeless_holds'] = {
430                 'start_date' : this._showHopelessAfter
431                     ? (
432                 // FIXME -- consistency desired, string or object
433                         typeof this._showHopelessAfter === 'object'
434                             ? this._showHopelessAfter.toISOString()
435                             : this._showHopelessAfter
436                     )
437                     : '1970-01-01T00:00:00.000Z',
438                 'end_date' : this._showHopelessBefore
439                     ? (
440                 // FIXME -- consistency desired, string or object
441                         typeof this._showHopelessBefore === 'object'
442                             ? this._showHopelessBefore.toISOString()
443                             : this._showHopelessBefore
444                     )
445                     : (new Date()).toISOString()
446             };
447         }
448
449         if (this.recordId) {
450             filters.record_id = this.recordId;
451         }
452
453         if (this.patronId) {
454             filters.usr_id = this.patronId;
455         }
456
457         return filters;
458     }
459
460     fetchHolds(pager: Pager, sort: any[]): Observable<any> {
461
462         // We need at least one filter.
463         if (!this.recordId && !this.pickupLib && !this.patronId && !this.pullListOrg) {
464             return of([]);
465         }
466
467         const filters = this.applyFilters();
468
469         const orderBy: any = [];
470         if (sort.length > 0) {
471             sort.forEach(obj => {
472                 const subObj: any = {};
473                 subObj[obj.name] = {dir: obj.dir, nulls: 'last'};
474                 orderBy.push(subObj);
475             });
476         }
477
478         const limit = this.enablePreFetch ? null : pager.limit;
479         const offset = this.enablePreFetch ? 0 : pager.offset;
480         const options: any = {};
481         if (this.showRecentlyCanceled) {
482             options.recently_canceled = true;
483         } else {
484             filters.cancel_time = null;
485         }
486
487         let observer: Observer<any>;
488         const observable = new Observable(obs => observer = obs);
489
490         if (!this.noLoadProgress) {
491             // Note remaining dialog actions have no impact
492             this.progressDialog.open();
493         }
494
495         this.progressDialog.update({value: 0, max: 1});
496
497         let first = true;
498         let loadCount = 0;
499         this.net.request(
500             'open-ils.circ',
501             'open-ils.circ.hold.wide_hash.stream',
502             this.auth.token(), filters, orderBy, limit, offset, options
503         ).subscribe(
504             holdData => {
505
506                 if (first) { // First response is the hold count.
507                     this.holdsCount = Number(holdData);
508                     first = false;
509
510                 } else { // Subsequent responses are hold data blobs
511
512                     this.progressDialog.update(
513                         {value: ++loadCount, max: this.holdsCount});
514
515                     observer.next(holdData);
516                 }
517             },
518             (err: unknown) => {
519                 this.progressDialog.close();
520                 observer.error(err);
521             },
522             ()  => {
523                 this.progressDialog.close();
524                 observer.complete();
525             }
526         );
527
528         return observable;
529     }
530
531     metaRecordHoldsSelected(rows: IdlObject[]) {
532         let found = false;
533         rows.forEach( row => {
534             if (row.hold_type === 'M') {
535                 found = true;
536             }
537         });
538         return found;
539     }
540
541     nonTitleHoldsSelected(rows: IdlObject[]) {
542         let found = false;
543         rows.forEach( row => {
544             if (row.hold_type !== 'T') {
545                 found = true;
546             }
547         });
548         return found;
549     }
550
551     showDetails(rows: any[]) {
552         this.showDetail(rows[0]);
553     }
554
555     showHoldsForTitle(rows: any[]) {
556         if (rows.length === 0) { return; }
557
558         const url = this.ngLocation.prepareExternalUrl(
559             `/staff/catalog/record/${rows[0].record_id}/holds`);
560
561         window.open(url, '_blank');
562     }
563
564     showDetail(row: any) {
565         if (row) {
566             this.mode = 'detail';
567             this.detailHold = row;
568         }
569     }
570
571     showManager(rows: any[]) {
572         if (rows.length) {
573             this.mode = 'manage';
574             this.editHolds = rows.map(r => r.id);
575         }
576     }
577
578     handleModify(rowsModified: boolean) {
579         this.mode = 'list';
580
581         if (rowsModified) {
582             // give the grid a chance to render then ask it to reload
583             setTimeout(() => this.holdsGrid.reload());
584         }
585     }
586
587
588
589     showRecentCircs(rows: any[]) {
590         const copyIds = Array.from(new Set( rows.map(r => r.cp_id).filter( cp_id => Boolean(cp_id)) ));
591         copyIds.forEach( copyId => {
592             const url =
593                 '/eg/staff/cat/item/' + copyId + '/circ_list';
594             window.open(url, '_blank');
595         });
596     }
597
598     showPatron(rows: any[]) {
599         const usrIds = Array.from(new Set( rows.map(r => r.usr_id).filter( usr_id => Boolean(usr_id)) ));
600         usrIds.forEach( usrId => {
601             const url =
602                 '/eg/staff/circ/patron/' + usrId + '/checkout';
603             window.open(url, '_blank');
604         });
605     }
606
607     showOrder(rows: any[]) {
608         // Doesn't work in Typescript currently without compiler option:
609         //   const bibIds = [...new Set( rows.map(r => r.record_id) )];
610         const bibIds = Array.from(
611             new Set( rows.filter(r => r.hold_type !== 'M').map(r => r.record_id) ));
612         bibIds.forEach( bibId => {
613             const url =
614               '/eg/staff/acq/legacy/lineitem/related/' + bibId + '?target=bib';
615             window.open(url, '_blank');
616         });
617     }
618
619     addVolume(rows: any[]) {
620         const bibIds = Array.from(
621             new Set( rows.filter(r => r.hold_type !== 'M').map(r => r.record_id) ));
622         bibIds.forEach( bibId => {
623             this.holdings.spawnAddHoldingsUi(bibId);
624         });
625     }
626
627     showTitle(rows: any[]) {
628         const bibIds = Array.from(new Set( rows.map(r => r.record_id) ));
629         bibIds.forEach( bibId => {
630             // const url = '/eg/staff/cat/catalog/record/' + bibId;
631             const url = '/eg2/staff/catalog/record/' + bibId;
632             window.open(url, '_blank');
633         });
634     }
635
636     showManageDialog(rows: any[]) {
637         const holdIds = rows.map(r => r.id).filter(id => Boolean(id));
638         if (holdIds.length > 0) {
639             this.manageDialog.holdIds = holdIds;
640             this.manageDialog.open({size: 'lg'}).subscribe(
641                 rowsModified => {
642                     if (rowsModified) {
643                         this.holdsGrid.reload();
644                     }
645                 }
646             );
647         }
648     }
649
650     showTransferDialog(rows: any[]) {
651         const holdIds = rows.filter(r => r.hold_type === 'T').map(r => r.id).filter(id => Boolean(id));
652         if (holdIds.length > 0) {
653             this.transferDialog.holdIds = holdIds;
654             this.transferDialog.open({}).subscribe(
655                 rowsModified => {
656                     if (rowsModified) {
657                         this.holdsGrid.reload();
658                     }
659                 }
660             );
661         }
662     }
663
664     async showMarkDamagedDialog(rows: any[]) {
665         const copyIds = rows.map(r => r.cp_id).filter(id => Boolean(id));
666         if (copyIds.length === 0) { return; }
667
668         let rowsModified = false;
669
670         const markNext = async(ids: number[]) => {
671             if (ids.length === 0) {
672                 return Promise.resolve();
673             }
674
675             this.markDamagedDialog.copyId = ids.pop();
676             return this.markDamagedDialog.open({size: 'lg'}).subscribe(
677                 ok => {
678                     if (ok) { rowsModified = true; }
679                     return markNext(ids);
680                 },
681                 (dismiss: unknown) => markNext(ids)
682             );
683         };
684
685         await markNext(copyIds);
686         if (rowsModified) {
687             this.holdsGrid.reload();
688         }
689     }
690
691     showMarkMissingDialog(rows: any[]) {
692         const copyIds = rows.map(r => r.cp_id).filter(id => Boolean(id));
693         if (copyIds.length > 0) {
694             this.markMissingDialog.copyIds = copyIds;
695             this.markMissingDialog.open({}).subscribe(
696                 rowsModified => {
697                     if (rowsModified) {
698                         this.holdsGrid.reload();
699                     }
700                 }
701             );
702         }
703     }
704
705     showMarkDiscardDialog(rows: any[]) {
706         const copyIds = rows.map(r => r.cp_id).filter(id => Boolean(id));
707         if (copyIds.length > 0) {
708             this.markDiscardDialog.copyIds = copyIds;
709             this.markDiscardDialog.open({}).subscribe(
710                 rowsModified => {
711                     if (rowsModified) {
712                         this.holdsGrid.reload();
713                     }
714                 }
715             );
716         }
717     }
718
719
720     showRetargetDialog(rows: any[]) {
721         const holdIds = rows.map(r => r.id).filter(id => Boolean(id));
722         if (holdIds.length > 0) {
723             this.retargetDialog.holdIds = holdIds;
724             this.retargetDialog.open({}).subscribe(
725                 rowsModified => {
726                     if (rowsModified) {
727                         this.holdsGrid.reload();
728                     }
729                 }
730             );
731         }
732     }
733
734     showCancelDialog(rows: any[]) {
735         const holdIds = rows.map(r => r.id).filter(id => Boolean(id));
736         if (holdIds.length > 0) {
737             this.cancelDialog.holdIds = holdIds;
738             this.cancelDialog.open({}).subscribe(
739                 rowsModified => {
740                     if (rowsModified) {
741                         this.holdsGrid.reload();
742                     }
743                 }
744             );
745         }
746     }
747
748     showUncancelDialog(rows: any[]) {
749         const holdIds = rows.map(r => r.id).filter(id => Boolean(id));
750         if (holdIds.length === 0) { return; }
751         this.uncancelHoldCount = holdIds.length;
752
753         this.uncancelDialog.open().subscribe(confirmed => {
754             if (!confirmed) { return; }
755             this.progressDialog.open();
756
757             from(holdIds).pipe(concatMap(holdId => {
758                 return this.net.request(
759                     'open-ils.circ',
760                     'open-ils.circ.hold.uncancel',
761                     this.auth.token(), holdId
762                 );
763             // eslint-disable-next-line rxjs/no-nested-subscribe
764             })).subscribe(
765                 resp => {
766                     if (Number(resp) !== 1) {
767                         console.error('Failed uncanceling hold', resp);
768                     }
769                 },
770                 null,
771                 () => {
772                     this.progressDialog.close();
773                     this.holdsGrid.reload();
774                 }
775             );
776         });
777     }
778
779     printHolds() {
780         // Request a page with no limit to get all of the wide holds for
781         // printing.  Call requestPage() directly instead of grid.reload()
782         // since we may already have the data.
783
784         const pager = new Pager();
785         pager.offset = 0;
786         pager.limit = null;
787
788         if (this.gridDataSource.sort.length === 0) {
789             this.gridDataSource.sort = this.defaultSort;
790         }
791
792         this.gridDataSource.requestPage(pager).then(() => {
793             if (this.gridDataSource.data.length > 0) {
794                 this.printer.print({
795                     templateName: this.printTemplate || 'holds_for_bib',
796                     contextData: this.gridDataSource.data,
797                     printContext: 'default'
798                 });
799             }
800         });
801     }
802
803     isCopyHold(holdData: any): boolean {
804         if (holdData && holdData.hold_type) {
805             return holdData.hold_type.match(/C|R|F/) !== null;
806         }
807         return false;
808     }
809 }
810
811
812
813