]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/nav.component.ts
LP1889128 Staffcat hold form reset option
[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
14 @Component({
15     selector: 'eg-staff-nav-bar',
16     styleUrls: ['nav.component.css'],
17     templateUrl: 'nav.component.html'
18 })
19
20 export class StaffNavComponent implements OnInit, OnDestroy {
21
22     // Locales that have Angular staff translations
23     locales: any[];
24     currentLocale: any;
25
26     // When active, show a link to the experimental Angular staff catalog
27     showAngularCatalog: boolean;
28     curbsideEnabled: boolean;
29
30     @ViewChild('navOpChange', {static: false}) opChange: OpChangeComponent;
31     permFailedSub: Subscription;
32
33     constructor(
34         private router: Router,
35         private store: StoreService,
36         private net: NetService,
37         private org: OrgService,
38         private auth: AuthService,
39         private pcrud: PcrudService,
40         private locale: LocaleService,
41         private printer: PrintService
42     ) {
43         this.locales = [];
44     }
45
46     ngOnInit() {
47
48         this.locale.supportedLocales().subscribe(
49             l => this.locales.push(l),
50             err => {},
51             () => {
52                 this.currentLocale = this.locales.filter(
53                     l => l.code() === this.locale.currentLocaleCode())[0];
54             }
55         );
56
57         // NOTE: this can eventually go away.
58         // Avoid attempts to fetch org settings if the user has not yet
59         // logged in (e.g. this is the login page).
60         if (this.user()) {
61             this.org.settings('ui.staff.angular_catalog.enabled')
62             .then(settings => this.showAngularCatalog =
63                 Boolean(settings['ui.staff.angular_catalog.enabled']));
64             this.org.settings('circ.curbside')
65             .then(settings => this.curbsideEnabled =
66                 Boolean(settings['circ.curbside']));
67         }
68
69         // Wire up our op-change component as the general purpose
70         // permission failed handler.
71         this.net.permFailedHasHandler = true;
72         this.permFailedSub =
73             this.net.permFailed$.subscribe(
74                 (req: NetRequest) => this.opChange.escalateRequest(req));
75     }
76
77     ngOnDestroy() {
78         if (this.permFailedSub) {
79             this.permFailedSub.unsubscribe();
80         }
81     }
82
83     user() {
84         return this.auth.user() ? this.auth.user().usrname() : '';
85     }
86
87     user_id() {
88         return this.auth.user() ? this.auth.user().id() : '';
89     }
90
91     workstation() {
92         return this.auth.user() ? this.auth.workstation() : '';
93     }
94
95     ws_ou() {
96         return this.auth.user() ? this.auth.user().ws_ou() : '';
97     }
98
99     setLocale(locale: any) {
100         this.locale.setLocale(locale.code());
101     }
102
103     opChangeActive(): boolean {
104         return this.auth.opChangeIsActive();
105     }
106
107     // Broadcast to all tabs that we're logging out.
108     // Redirect to the login page, which performs the remaining
109     // logout duties.
110     logout(): void {
111         this.auth.broadcastLogout();
112         this.router.navigate(['/staff/login']);
113     }
114
115     reprintLast() {
116         this.printer.reprintLast();
117     }
118
119     retrieveLastRecord() {
120         const recId = this.store.getLocalItem('eg.cat.last_record_retrieved');
121         if (recId) {
122             this.router.navigate(['/staff/catalog/record/' + recId]);
123         }
124     }
125 }
126
127