LP1904036 ng lint continued
[evergreen-equinox.git] / Open-ILS / src / eg2 / src / app / staff / circ / patron / barcodes.component.ts
1 import {Component, OnInit, Input, ViewChild} from '@angular/core';
2 import {Observable, from, empty} from 'rxjs';
3 import {switchMap, tap} from 'rxjs/operators';
4 import {IdlObject, IdlService} from '@eg/core/idl.service';
5 import {NetService} from '@eg/core/net.service';
6 import {EventService} from '@eg/core/event.service';
7 import {ToastService} from '@eg/share/toast/toast.service';
8 import {PcrudService} from '@eg/core/pcrud.service';
9 import {AuthService} from '@eg/core/auth.service';
10 import {OrgService} from '@eg/core/org.service';
11 import {DialogComponent} from '@eg/share/dialog/dialog.component';
12 import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
13 import {StringComponent} from '@eg/share/string/string.component';
14 import {PatronContextService} from './patron.service';
15 import {PermService} from '@eg/core/perm.service';
16
17 const PERMS = ['UPDATE_PATRON_ACTIVE_CARD', 'UPDATE_PATRON_PRIMARY_CARD'];
18
19 /* Add/Remove Secondary Groups */
20
21 @Component({
22   selector: 'eg-patron-barcodes',
23   templateUrl: 'barcodes.component.html'
24 })
25
26 export class PatronBarcodesDialogComponent extends DialogComponent {
27
28     @Input() patron: IdlObject;
29     primaryCard: number;
30     myPerms: {[name: string]: boolean} = {};
31
32     constructor(
33         private modal: NgbModal,
34         private toast: ToastService,
35         private net: NetService,
36         private idl: IdlService,
37         private evt: EventService,
38         private pcrud: PcrudService,
39         private org: OrgService,
40         private auth: AuthService,
41         private perms: PermService,
42         private context: PatronContextService
43     ) { super(modal); }
44
45     open(ops: NgbModalOptions): Observable<any> {
46         this.patron.cards().some(card => {
47             if (card.id() === this.patron.card().id()) {
48                 this.primaryCard = card.id();
49                 return true;
50             }
51         });
52
53         this.perms.hasWorkPermAt(PERMS, true).then(perms => {
54             PERMS.forEach(p => {
55                 this.myPerms[p] = perms[p].includes(this.patron.home_ou());
56             });
57         });
58
59         return super.open(ops);
60     }
61
62     applyChanges() {
63         if (this.primaryCard !== this.patron.card().id()) {
64             const card = this.patron.cards()
65                 .filter(c => c.id() === this.primaryCard)[0];
66             this.patron.card(card);
67         }
68         this.close(true);
69     }
70
71     activeChange(card: IdlObject, active: boolean) {
72         card.ischanged(true);
73         card.active(active ? 't' : 'f');
74     }
75 }
76