1 import {Component, OnInit, ViewChild} from '@angular/core';
2 import {ActivatedRoute, Router} from '@angular/router';
3 import {Location} from '@angular/common';
4 import {OrgService} from '@eg/core/org.service';
5 import {AuthService} from '@eg/core/auth.service';
6 import {PcrudService} from '@eg/core/pcrud.service';
7 import {LocaleService} from '@eg/core/locale.service';
8 import {PrintService} from '@eg/share/print/print.service';
9 import {StoreService} from '@eg/core/store.service';
12 selector: 'eg-staff-nav-bar',
13 styleUrls: ['nav.component.css'],
14 templateUrl: 'nav.component.html'
17 export class StaffNavComponent implements OnInit {
19 // Locales that have Angular staff translations
23 // When active, show a link to the experimental Angular staff catalog
24 showAngularCatalog: boolean;
27 private router: Router,
28 private store: StoreService,
29 private org: OrgService,
30 private auth: AuthService,
31 private pcrud: PcrudService,
32 private locale: LocaleService,
33 private printer: PrintService
40 this.locale.supportedLocales().subscribe(
41 l => this.locales.push(l),
44 this.currentLocale = this.locales.filter(
45 l => l.code() === this.locale.currentLocaleCode())[0];
49 // NOTE: this can eventually go away.
50 // Avoid attempts to fetch org settings if the user has not yet
51 // logged in (e.g. this is the login page).
53 this.org.settings('ui.staff.angular_catalog.enabled')
54 .then(settings => this.showAngularCatalog =
55 Boolean(settings['ui.staff.angular_catalog.enabled']));
60 return this.auth.user() ? this.auth.user().usrname() : '';
64 return this.auth.user() ? this.auth.workstation() : '';
67 setLocale(locale: any) {
68 this.locale.setLocale(locale.code());
71 opChangeActive(): boolean {
72 return this.auth.opChangeIsActive();
75 // Broadcast to all tabs that we're logging out.
76 // Redirect to the login page, which performs the remaining
79 this.auth.broadcastLogout();
80 this.router.navigate(['/staff/login']);
84 this.printer.reprintLast();
87 // TODO: Point to Angular catalog when the time comes
88 retrieveLastRecord() {
89 const recId = this.store.getLocalItem('eg.cat.last_record_retrieved');
91 window.location.href = '/eg/staff/cat/catalog/record/' + recId;