]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/share/holdings/mark-missing-dialog.component.ts
LP1830973 Angular 8 updates
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / share / holdings / mark-missing-dialog.component.ts
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} from '@ng-bootstrap/ng-bootstrap';
8 import {StringComponent} from '@eg/share/string/string.component';
9
10
11 /**
12  * Dialog for marking items missing.
13  */
14
15 @Component({
16   selector: 'eg-mark-missing-dialog',
17   templateUrl: 'mark-missing-dialog.component.html'
18 })
19
20 export class MarkMissingDialogComponent
21     extends DialogComponent implements OnInit {
22
23     @Input() copyIds: number[];
24
25     numSucceeded: number;
26     numFailed: number;
27
28     @ViewChild('successMsg', { static: true })
29         private successMsg: StringComponent;
30
31     @ViewChild('errorMsg', { static: true })
32         private errorMsg: StringComponent;
33
34     constructor(
35         private modal: NgbModal, // required for passing to parent
36         private toast: ToastService,
37         private net: NetService,
38         private evt: EventService,
39         private auth: AuthService) {
40         super(modal); // required for subclassing
41     }
42
43     ngOnInit() {}
44
45     async markOneItemMissing(ids: number[]): Promise<any> {
46         if (ids.length === 0) {
47             return Promise.resolve();
48         }
49
50         const id = ids.pop();
51
52         return this.net.request(
53             'open-ils.circ',
54             'open-ils.circ.mark_item_missing',
55             this.auth.token(), id
56         ).toPromise().then(async(result) => {
57             if (Number(result) === 1) {
58                 this.numSucceeded++;
59                 this.toast.success(await this.successMsg.current());
60             } else {
61                 this.numFailed++;
62                 console.error('Mark missing failed ', this.evt.parse(result));
63                 this.toast.warning(await this.errorMsg.current());
64             }
65             return this.markOneItemMissing(ids);
66         });
67     }
68
69     async markItemsMissing(): Promise<any> {
70         this.numSucceeded = 0;
71         this.numFailed = 0;
72         const ids = [].concat(this.copyIds);
73         await this.markOneItemMissing(ids);
74         this.close(this.numSucceeded > 0);
75     }
76 }
77
78
79