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;
29 @ViewChild('navOpChange', {static: false}) opChange: OpChangeComponent;
30 permFailedSub: Subscription;
33 private router: Router,
34 private store: StoreService,
35 private net: NetService,
36 private org: OrgService,
37 private auth: AuthService,
38 private pcrud: PcrudService,
39 private locale: LocaleService,
40 private printer: PrintService
47 this.locale.supportedLocales().subscribe(
48 l => this.locales.push(l),
51 this.currentLocale = this.locales.filter(
52 l => l.code() === this.locale.currentLocaleCode())[0];
56 // NOTE: this can eventually go away.
57 // Avoid attempts to fetch org settings if the user has not yet
58 // logged in (e.g. this is the login page).
60 this.org.settings('ui.staff.angular_catalog.enabled')
61 .then(settings => this.showAngularCatalog =
62 Boolean(settings['ui.staff.angular_catalog.enabled']));
65 // Wire up our op-change component as the general purpose
66 // permission failed handler.
67 this.net.permFailedHasHandler = true;
69 this.net.permFailed$.subscribe(
70 (req: NetRequest) => this.opChange.escalateRequest(req));
74 if (this.permFailedSub) {
75 this.permFailedSub.unsubscribe();
80 return this.auth.user() ? this.auth.user().usrname() : '';
84 return this.auth.user() ? this.auth.workstation() : '';
87 setLocale(locale: any) {
88 this.locale.setLocale(locale.code());
91 opChangeActive(): boolean {
92 return this.auth.opChangeIsActive();
95 // Broadcast to all tabs that we're logging out.
96 // Redirect to the login page, which performs the remaining
99 this.auth.broadcastLogout();
100 this.router.navigate(['/staff/login']);
104 this.printer.reprintLast();
107 // TODO: Point to Angular catalog when the time comes
108 retrieveLastRecord() {
109 const recId = this.store.getLocalItem('eg.cat.last_record_retrieved');
111 window.location.href = '/eg/staff/cat/catalog/record/' + recId;