]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/nav.component.ts
LP1860460 Copy delete override repairs, perm failed handler
[working/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
29     @ViewChild('navOpChange', {static: false}) opChange: OpChangeComponent;
30     permFailedSub: Subscription;
31
32     constructor(
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
41     ) {
42         this.locales = [];
43     }
44
45     ngOnInit() {
46
47         this.locale.supportedLocales().subscribe(
48             l => this.locales.push(l),
49             err => {},
50             () => {
51                 this.currentLocale = this.locales.filter(
52                     l => l.code() === this.locale.currentLocaleCode())[0];
53             }
54         );
55
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).
59         if (this.user()) {
60             this.org.settings('ui.staff.angular_catalog.enabled')
61             .then(settings => this.showAngularCatalog =
62                 Boolean(settings['ui.staff.angular_catalog.enabled']));
63         }
64
65         // Wire up our op-change component as the general purpose
66         // permission failed handler.
67         this.net.permFailedHasHandler = true;
68         this.permFailedSub =
69             this.net.permFailed$.subscribe(
70                 (req: NetRequest) => this.opChange.escalateRequest(req));
71     }
72
73     ngOnDestroy() {
74         if (this.permFailedSub) {
75             this.permFailedSub.unsubscribe();
76         }
77     }
78
79     user() {
80         return this.auth.user() ? this.auth.user().usrname() : '';
81     }
82
83     workstation() {
84         return this.auth.user() ? this.auth.workstation() : '';
85     }
86
87     setLocale(locale: any) {
88         this.locale.setLocale(locale.code());
89     }
90
91     opChangeActive(): boolean {
92         return this.auth.opChangeIsActive();
93     }
94
95     // Broadcast to all tabs that we're logging out.
96     // Redirect to the login page, which performs the remaining
97     // logout duties.
98     logout(): void {
99         this.auth.broadcastLogout();
100         this.router.navigate(['/staff/login']);
101     }
102
103     reprintLast() {
104         this.printer.reprintLast();
105     }
106
107     // TODO: Point to Angular catalog when the time comes
108     retrieveLastRecord() {
109         const recId = this.store.getLocalItem('eg.cat.last_record_retrieved');
110         if (recId) {
111             window.location.href = '/eg/staff/cat/catalog/record/' + recId;
112         }
113     }
114 }
115
116