1 import {Component, OnInit, OnDestroy, QueryList, ViewChild, ViewChildren} 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';
14 import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
15 import {NgbCollapseModule, NgbDropdown} from '@ng-bootstrap/ng-bootstrap';
18 selector: 'eg-staff-nav-bar',
19 styleUrls: ['nav.component.css'],
20 templateUrl: 'nav.component.html'
23 export class StaffNavComponent implements OnInit, OnDestroy {
25 // Locales that have Angular staff translations
29 // When active, show a link to the traditional staff catalog
30 showTraditionalCatalog = true;
31 showAngularAcq: boolean;
32 curbsideEnabled: boolean;
33 showAngularCirc = false;
37 isMenuCollapsed = true;
39 @ViewChild('navOpChange', {static: false}) opChange: OpChangeComponent;
40 @ViewChild('confirmLogout', { static: true }) confirmLogout: ConfirmDialogComponent;
41 @ViewChildren(NgbDropdown) dropdowns: QueryList<NgbDropdown>;
42 permFailedSub: Subscription;
45 private router: Router,
46 private store: StoreService,
47 private net: NetService,
48 private org: OrgService,
49 private auth: AuthService,
50 private perm: PermService,
51 private pcrud: PcrudService,
52 private locale: LocaleService,
53 private printer: PrintService
60 this.locale.supportedLocales().subscribe(
61 l => this.locales.push(l),
64 this.currentLocale = this.locales.filter(
65 l => l.code() === this.locale.currentLocaleCode())[0];
69 // NOTE: this can eventually go away.
70 // Avoid attempts to fetch org settings if the user has not yet
71 // logged in (e.g. this is the login page).
73 // Note these are all pre-cached by our resolver.
74 // Batching not required.
75 this.org.settings('ui.staff.traditional_catalog.enabled')
76 .then(settings => this.showTraditionalCatalog =
77 Boolean(settings['ui.staff.traditional_catalog.enabled']));
79 this.org.settings('circ.curbside')
80 .then(settings => this.curbsideEnabled =
81 Boolean(settings['circ.curbside']));
83 this.org.settings('ui.staff.max_recent_patrons')
84 .then(settings => this.maxRecentPatrons =
85 settings['ui.staff.max_recent_patrons'] ?? 1);
87 // Do we show the angular circ menu?
88 // TODO remove these once Angular Circ takes over.
89 const angSet = 'ui.staff.angular_circ.enabled';
90 const angPerm = 'ACCESS_ANGULAR_CIRC';
92 this.org.settings(angSet).then(s => {
94 return this.perm.hasWorkPermHere([angPerm])
95 .then(perms => perms[angPerm]);
99 }).then(enable => this.showAngularCirc = enable);
102 // Wire up our op-change component as the general purpose
103 // permission failed handler.
104 this.net.permFailedHasHandler = true;
106 this.net.permFailed$.subscribe(
107 (req: NetRequest) => this.opChange.escalateRequest(req));
111 if (this.permFailedSub) {
112 this.permFailedSub.unsubscribe();
117 return this.auth.user() ? this.auth.user().usrname() : '';
121 return this.auth.user() ? this.auth.user().id() : '';
125 return this.auth.user() ? this.auth.workstation() : '';
129 return this.auth.user() ? this.auth.user().ws_ou() : '';
132 setLocale(locale: any) {
133 this.locale.setLocale(locale.code());
136 opChangeActive(): boolean {
137 return this.auth.opChangeIsActive();
141 this.confirmLogout.open().subscribe(confirmed => {
142 if (!confirmed) { return; }
148 // Broadcast to all tabs that we're logging out.
149 // Redirect to the login page, which performs the remaining
152 this.auth.broadcastLogout();
153 this.router.navigate(['/staff/login']);
157 this.printer.reprintLast();
160 retrieveLastRecord() {
161 const recId = this.store.getLocalItem('eg.cat.last_record_retrieved');
163 this.router.navigate(['/staff/catalog/record/' + recId]);
168 this.dropdowns?.forEach(x => x.close());