1 import {Component, OnInit, Input, ViewChild} from '@angular/core';
2 import {NetService} from '@eg/core/net.service';
3 import {EventService} from '@eg/core/event.service';
4 import {ToastService} from '@eg/share/toast/toast.service';
5 import {AuthService} from '@eg/core/auth.service';
6 import {DialogComponent} from '@eg/share/dialog/dialog.component';
7 import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
8 import {StringComponent} from '@eg/share/string/string.component';
12 * Dialog for retargeting holds.
16 selector: 'eg-hold-retarget-dialog',
17 templateUrl: 'retarget-dialog.component.html'
20 export class HoldRetargetDialogComponent
21 extends DialogComponent implements OnInit {
23 @Input() holdIds: number | number[];
24 @ViewChild('successMsg') private successMsg: StringComponent;
25 @ViewChild('errorMsg') private errorMsg: StringComponent;
27 changesApplied: boolean;
32 private modal: NgbModal, // required for passing to parent
33 private toast: ToastService,
34 private net: NetService,
35 private evt: EventService,
36 private auth: AuthService) {
37 super(modal); // required for subclassing
42 open(args: NgbModalOptions): Promise<boolean> {
43 this.holdIds = [].concat(this.holdIds); // array-ify ints
44 return super.open(args);
47 async retargetNext(ids: number[]): Promise<any> {
48 if (ids.length === 0) {
49 return Promise.resolve();
52 return this.net.request(
53 'open-ils.circ', 'open-ils.circ.hold.reset',
54 this.auth.token(), ids.pop()
57 if (Number(result) === 1) {
59 this.toast.success(await this.successMsg.current());
62 console.error(this.evt.parse(result));
63 this.toast.warning(await this.errorMsg.current());
65 this.retargetNext(ids);
70 async retargetBatch(): Promise<any> {
71 this.numSucceeded = 0;
73 const ids = [].concat(this.holdIds);
74 await this.retargetNext(ids);
75 this.close(this.numSucceeded > 0);