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';
15 selector: 'eg-staff-nav-bar',
16 styleUrls: ['nav.component.css'],
17 templateUrl: 'nav.component.html'
20 export class StaffNavComponent implements OnInit, OnDestroy {
22 // Locales that have Angular staff translations
26 // When active, show a link to the experimental Angular staff catalog
27 showAngularCatalog: boolean;
28 curbsideEnabled: boolean;
30 @ViewChild('navOpChange', {static: false}) opChange: OpChangeComponent;
31 permFailedSub: Subscription;
34 private router: Router,
35 private store: StoreService,
36 private net: NetService,
37 private org: OrgService,
38 private auth: AuthService,
39 private pcrud: PcrudService,
40 private locale: LocaleService,
41 private printer: PrintService
48 this.locale.supportedLocales().subscribe(
49 l => this.locales.push(l),
52 this.currentLocale = this.locales.filter(
53 l => l.code() === this.locale.currentLocaleCode())[0];
57 // NOTE: this can eventually go away.
58 // Avoid attempts to fetch org settings if the user has not yet
59 // logged in (e.g. this is the login page).
61 this.org.settings('ui.staff.angular_catalog.enabled')
62 .then(settings => this.showAngularCatalog =
63 Boolean(settings['ui.staff.angular_catalog.enabled']));
64 this.org.settings('circ.curbside')
65 .then(settings => this.curbsideEnabled =
66 Boolean(settings['circ.curbside']));
69 // Wire up our op-change component as the general purpose
70 // permission failed handler.
71 this.net.permFailedHasHandler = true;
73 this.net.permFailed$.subscribe(
74 (req: NetRequest) => this.opChange.escalateRequest(req));
78 if (this.permFailedSub) {
79 this.permFailedSub.unsubscribe();
84 return this.auth.user() ? this.auth.user().usrname() : '';
88 return this.auth.user() ? this.auth.user().id() : '';
92 return this.auth.user() ? this.auth.workstation() : '';
96 return this.auth.user() ? this.auth.user().ws_ou() : '';
99 setLocale(locale: any) {
100 this.locale.setLocale(locale.code());
103 opChangeActive(): boolean {
104 return this.auth.opChangeIsActive();
107 // Broadcast to all tabs that we're logging out.
108 // Redirect to the login page, which performs the remaining
111 this.auth.broadcastLogout();
112 this.router.navigate(['/staff/login']);
116 this.printer.reprintLast();
119 retrieveLastRecord() {
120 const recId = this.store.getLocalItem('eg.cat.last_record_retrieved');
122 this.router.navigate(['/staff/catalog/record/' + recId]);