1 import {Component, Input, ViewChild} from '@angular/core';
2 import {from, Observable} from 'rxjs';
3 import {tap, concatMap} from 'rxjs/operators';
4 import {NetService} from '@eg/core/net.service';
5 import {EventService} from '@eg/core/event.service';
6 import {ToastService} from '@eg/share/toast/toast.service';
7 import {AuthService} from '@eg/core/auth.service';
8 import {DialogComponent} from '@eg/share/dialog/dialog.component';
9 import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
10 import {StringComponent} from '@eg/share/string/string.component';
14 * Dialog for marking items discard.
18 selector: 'eg-mark-discard-dialog',
19 templateUrl: 'mark-discard-dialog.component.html'
22 export class MarkDiscardDialogComponent
23 extends DialogComponent {
25 @Input() copyIds: number[];
30 @ViewChild('successMsg') private successMsg: StringComponent;
31 @ViewChild('errorMsg') private errorMsg: StringComponent;
34 private modal: NgbModal, // required for passing to parent
35 private toast: ToastService,
36 private net: NetService,
37 private evt: EventService,
38 private auth: AuthService) {
39 super(modal); // required for subclassing
42 open(args: NgbModalOptions): Observable<boolean> {
43 this.numSucceeded = 0;
45 return super.open(args);
48 markOneItemDiscard(id: number): Observable<any> {
50 return this.net.request(
52 'open-ils.circ.mark_item_discard',
54 ).pipe(tap(result => {
55 if (Number(result) === 1) {
57 this.successMsg.current().then(str => this.toast.success(str));
60 console.error('Mark discard failed ', this.evt.parse(result));
61 this.errorMsg.current().then(str => this.toast.warning(str));
66 markItemsDiscard(): Promise<any> {
67 this.numSucceeded = 0;
70 return from(this.copyIds)
71 .pipe(concatMap(copyId => this.markOneItemDiscard(copyId)))
72 .toPromise().then(_ => this.close(this.numSucceeded > 0));