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';
17 const PERMS = ['UPDATE_PATRON_ACTIVE_CARD', 'UPDATE_PATRON_PRIMARY_CARD'];
19 /* Add/Remove Secondary Groups */
22 selector: 'eg-patron-barcodes',
23 templateUrl: 'barcodes.component.html'
26 export class PatronBarcodesDialogComponent extends DialogComponent {
28 @Input() patron: IdlObject;
30 myPerms: {[name: string]: boolean} = {};
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
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();
53 this.perms.hasWorkPermAt(PERMS, true).then(perms => {
55 this.myPerms[p] = perms[p].includes(this.patron.home_ou());
59 return super.open(ops);
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);
71 activeChange(card: IdlObject, active: boolean) {
73 card.active(active ? 't' : 'f');