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;
33 @ViewChild('navOpChange', {static: false}) opChange: OpChangeComponent;
34 permFailedSub: Subscription;
37 private router: Router,
38 private store: StoreService,
39 private net: NetService,
40 private org: OrgService,
41 private auth: AuthService,
42 private perm: PermService,
43 private pcrud: PcrudService,
44 private locale: LocaleService,
45 private printer: PrintService
52 this.locale.supportedLocales().subscribe(
53 l => this.locales.push(l),
56 this.currentLocale = this.locales.filter(
57 l => l.code() === this.locale.currentLocaleCode())[0];
61 // NOTE: this can eventually go away.
62 // Avoid attempts to fetch org settings if the user has not yet
63 // logged in (e.g. this is the login page).
65 // Note these are all pre-cached by our resolver.
66 // Batching not required.
67 this.org.settings('ui.staff.traditional_catalog.enabled')
68 .then(settings => this.showTraditionalCatalog =
69 Boolean(settings['ui.staff.traditional_catalog.enabled']));
71 this.org.settings('circ.curbside')
72 .then(settings => this.curbsideEnabled =
73 Boolean(settings['circ.curbside']));
75 // Do we show the angular circ menu?
76 // TODO remove these once Angular Circ takes over.
77 const angSet = 'ui.staff.angular_circ.enabled';
78 const angPerm = 'ACCESS_ANGULAR_CIRC';
80 this.org.settings(angSet).then(s => {
82 return this.perm.hasWorkPermHere([angPerm])
83 .then(perms => perms[angPerm]);
87 }).then(enable => this.showAngularCirc = enable);
90 // Wire up our op-change component as the general purpose
91 // permission failed handler.
92 this.net.permFailedHasHandler = true;
94 this.net.permFailed$.subscribe(
95 (req: NetRequest) => this.opChange.escalateRequest(req));
99 if (this.permFailedSub) {
100 this.permFailedSub.unsubscribe();
105 return this.auth.user() ? this.auth.user().usrname() : '';
109 return this.auth.user() ? this.auth.user().id() : '';
113 return this.auth.user() ? this.auth.workstation() : '';
117 return this.auth.user() ? this.auth.user().ws_ou() : '';
120 setLocale(locale: any) {
121 this.locale.setLocale(locale.code());
124 opChangeActive(): boolean {
125 return this.auth.opChangeIsActive();
128 // Broadcast to all tabs that we're logging out.
129 // Redirect to the login page, which performs the remaining
132 this.auth.broadcastLogout();
133 this.router.navigate(['/staff/login']);
137 this.printer.reprintLast();
140 retrieveLastRecord() {
141 const recId = this.store.getLocalItem('eg.cat.last_record_retrieved');
143 this.router.navigate(['/staff/catalog/record/' + recId]);