1 import {Component, OnInit, OnDestroy, ViewChild} from '@angular/core';
2 import {ActivatedRoute, Router} from '@angular/router';
3 import {Location} from '@angular/common';
4 import {Subscription} from 'rxjs';
5 import {OrgService} from '@eg/core/org.service';
6 import {AuthService} from '@eg/core/auth.service';
7 import {PcrudService} from '@eg/core/pcrud.service';
8 import {LocaleService} from '@eg/core/locale.service';
9 import {PrintService} from '@eg/share/print/print.service';
10 import {StoreService} from '@eg/core/store.service';
11 import {NetRequest, NetService} from '@eg/core/net.service';
12 import {OpChangeComponent} from '@eg/staff/share/op-change/op-change.component';
13 import {PermService} from '@eg/core/perm.service';
16 selector: 'eg-staff-nav-bar',
17 styleUrls: ['nav.component.css'],
18 templateUrl: 'nav.component.html'
21 export class StaffNavComponent implements OnInit, OnDestroy {
23 // Locales that have Angular staff translations
27 // When active, show a link to the traditional staff catalog
28 showTraditionalCatalog = true;
29 showAngularAcq: boolean;
30 curbsideEnabled: boolean;
31 showAngularCirc = false;
32 maxRecentPatrons: number = 1;
34 @ViewChild('navOpChange', {static: false}) opChange: OpChangeComponent;
35 permFailedSub: Subscription;
38 private router: Router,
39 private store: StoreService,
40 private net: NetService,
41 private org: OrgService,
42 private auth: AuthService,
43 private perm: PermService,
44 private pcrud: PcrudService,
45 private locale: LocaleService,
46 private printer: PrintService
53 this.locale.supportedLocales().subscribe(
54 l => this.locales.push(l),
57 this.currentLocale = this.locales.filter(
58 l => l.code() === this.locale.currentLocaleCode())[0];
62 // NOTE: this can eventually go away.
63 // Avoid attempts to fetch org settings if the user has not yet
64 // logged in (e.g. this is the login page).
66 // Note these are all pre-cached by our resolver.
67 // Batching not required.
68 this.org.settings('ui.staff.traditional_catalog.enabled')
69 .then(settings => this.showTraditionalCatalog =
70 Boolean(settings['ui.staff.traditional_catalog.enabled']));
72 this.org.settings('circ.curbside')
73 .then(settings => this.curbsideEnabled =
74 Boolean(settings['circ.curbside']));
76 this.org.settings('ui.staff.max_recent_patrons')
77 .then(settings => this.maxRecentPatrons =
78 settings['ui.staff.max_recent_patrons'] ?? 1)
80 // Do we show the angular circ menu?
81 // TODO remove these once Angular Circ takes over.
82 const angSet = 'ui.staff.angular_circ.enabled';
83 const angPerm = 'ACCESS_ANGULAR_CIRC';
85 this.org.settings(angSet).then(s => {
87 return this.perm.hasWorkPermHere([angPerm])
88 .then(perms => perms[angPerm]);
92 }).then(enable => this.showAngularCirc = enable);
95 // Wire up our op-change component as the general purpose
96 // permission failed handler.
97 this.net.permFailedHasHandler = true;
99 this.net.permFailed$.subscribe(
100 (req: NetRequest) => this.opChange.escalateRequest(req));
104 if (this.permFailedSub) {
105 this.permFailedSub.unsubscribe();
110 return this.auth.user() ? this.auth.user().usrname() : '';
114 return this.auth.user() ? this.auth.user().id() : '';
118 return this.auth.user() ? this.auth.workstation() : '';
122 return this.auth.user() ? this.auth.user().ws_ou() : '';
125 setLocale(locale: any) {
126 this.locale.setLocale(locale.code());
129 opChangeActive(): boolean {
130 return this.auth.opChangeIsActive();
133 // Broadcast to all tabs that we're logging out.
134 // Redirect to the login page, which performs the remaining
137 this.auth.broadcastLogout();
138 this.router.navigate(['/staff/login']);
142 this.printer.reprintLast();
145 retrieveLastRecord() {
146 const recId = this.store.getLocalItem('eg.cat.last_record_retrieved');
148 this.router.navigate(['/staff/catalog/record/' + recId]);