]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/nav.component.ts
LP1822414 Ang date select readOnly & fixes
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / nav.component.ts
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';
10
11 @Component({
12     selector: 'eg-staff-nav-bar',
13     styleUrls: ['nav.component.css'],
14     templateUrl: 'nav.component.html'
15 })
16
17 export class StaffNavComponent implements OnInit {
18
19     // Locales that have Angular staff translations
20     locales: any[];
21     currentLocale: any;
22
23     // When active, show a link to the experimental Angular staff catalog
24     showAngularCatalog: boolean;
25
26     constructor(
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
34     ) {
35         this.locales = [];
36     }
37
38     ngOnInit() {
39
40         this.locale.supportedLocales().subscribe(
41             l => this.locales.push(l),
42             err => {},
43             () => {
44                 this.currentLocale = this.locales.filter(
45                     l => l.code() === this.locale.currentLocaleCode())[0];
46             }
47         );
48
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).
52         if (this.user()) {
53             this.org.settings('ui.staff.angular_catalog.enabled')
54             .then(settings => this.showAngularCatalog =
55                 Boolean(settings['ui.staff.angular_catalog.enabled']));
56         }
57     }
58
59     user() {
60         return this.auth.user() ? this.auth.user().usrname() : '';
61     }
62
63     workstation() {
64         return this.auth.user() ? this.auth.workstation() : '';
65     }
66
67     setLocale(locale: any) {
68         this.locale.setLocale(locale.code());
69     }
70
71     opChangeActive(): boolean {
72         return this.auth.opChangeIsActive();
73     }
74
75     // Broadcast to all tabs that we're logging out.
76     // Redirect to the login page, which performs the remaining
77     // logout duties.
78     logout(): void {
79         this.auth.broadcastLogout();
80         this.router.navigate(['/staff/login']);
81     }
82
83     reprintLast() {
84         this.printer.reprintLast();
85     }
86
87     // TODO: Point to Angular catalog when the time comes
88     retrieveLastRecord() {
89         const recId = this.store.getLocalItem('eg.cat.last_record_retrieved');
90         if (recId) {
91             window.location.href = '/eg/staff/cat/catalog/record/' + recId;
92         }
93     }
94 }
95
96