]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/nav.component.ts
LP2045292 Color contrast for AngularJS patron bills
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / nav.component.ts
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';
13 import {PermService} from '@eg/core/perm.service';
14
15 @Component({
16     selector: 'eg-staff-nav-bar',
17     styleUrls: ['nav.component.css'],
18     templateUrl: 'nav.component.html'
19 })
20
21 export class StaffNavComponent implements OnInit, OnDestroy {
22
23     // Locales that have Angular staff translations
24     locales: any[];
25     currentLocale: any;
26
27     // When active, show a link to the traditional staff catalog
28     showTraditionalCatalog = true;
29     showAngularAcq: boolean;
30     curbsideEnabled: boolean;
31     showAngularCirc = false;
32
33     @ViewChild('navOpChange', {static: false}) opChange: OpChangeComponent;
34     permFailedSub: Subscription;
35
36     constructor(
37         private router: Router,
38         private store: StoreService,
39         private net: NetService,
40         private org: OrgService,
41         private auth: AuthService,
42         private perm: PermService,
43         private pcrud: PcrudService,
44         private locale: LocaleService,
45         private printer: PrintService
46     ) {
47         this.locales = [];
48     }
49
50     ngOnInit() {
51
52         this.locale.supportedLocales().subscribe(
53             l => this.locales.push(l),
54             err => {},
55             () => {
56                 this.currentLocale = this.locales.filter(
57                     l => l.code() === this.locale.currentLocaleCode())[0];
58             }
59         );
60
61         // NOTE: this can eventually go away.
62         // Avoid attempts to fetch org settings if the user has not yet
63         // logged in (e.g. this is the login page).
64         if (this.user()) {
65             // Note these are all pre-cached by our resolver.
66             // Batching not required.
67             this.org.settings('ui.staff.traditional_catalog.enabled')
68             .then(settings => this.showTraditionalCatalog =
69                 Boolean(settings['ui.staff.traditional_catalog.enabled']));
70
71             this.org.settings('circ.curbside')
72             .then(settings => this.curbsideEnabled =
73                 Boolean(settings['circ.curbside']));
74
75             // Do we show the angular circ menu?
76             // TODO remove these once Angular Circ takes over.
77             const angSet = 'ui.staff.angular_circ.enabled';
78             const angPerm = 'ACCESS_ANGULAR_CIRC';
79
80             this.org.settings(angSet).then(s => {
81                 if (s[angSet]) {
82                     return this.perm.hasWorkPermHere([angPerm])
83                     .then(perms => perms[angPerm]);
84                 } else {
85                     return false;
86                 }
87             }).then(enable => this.showAngularCirc = enable);
88         }
89
90         // Wire up our op-change component as the general purpose
91         // permission failed handler.
92         this.net.permFailedHasHandler = true;
93         this.permFailedSub =
94             this.net.permFailed$.subscribe(
95                 (req: NetRequest) => this.opChange.escalateRequest(req));
96     }
97
98     ngOnDestroy() {
99         if (this.permFailedSub) {
100             this.permFailedSub.unsubscribe();
101         }
102     }
103
104     user() {
105         return this.auth.user() ? this.auth.user().usrname() : '';
106     }
107
108     user_id() {
109         return this.auth.user() ? this.auth.user().id() : '';
110     }
111
112     workstation() {
113         return this.auth.user() ? this.auth.workstation() : '';
114     }
115
116     ws_ou() {
117         return this.auth.user() ? this.auth.user().ws_ou() : '';
118     }
119
120     setLocale(locale: any) {
121         this.locale.setLocale(locale.code());
122     }
123
124     opChangeActive(): boolean {
125         return this.auth.opChangeIsActive();
126     }
127
128     // Broadcast to all tabs that we're logging out.
129     // Redirect to the login page, which performs the remaining
130     // logout duties.
131     logout(): void {
132         this.auth.broadcastLogout();
133         this.router.navigate(['/staff/login']);
134     }
135
136     reprintLast() {
137         this.printer.reprintLast();
138     }
139
140     retrieveLastRecord() {
141         const recId = this.store.getLocalItem('eg.cat.last_record_retrieved');
142         if (recId) {
143             this.router.navigate(['/staff/catalog/record/' + recId]);
144         }
145     }
146 }
147
148