-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathapp-header.component.ts
61 lines (55 loc) · 1.98 KB
/
app-header.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { DOCUMENT } from "@angular/common";
import { Component, OnInit, Inject } from "@angular/core";
import { APP_CONFIG, AppConfig } from "app-config.module";
import { Store } from "@ngrx/store";
import {
fetchCurrentUserAction,
logoutAction,
} from "state-management/actions/user.actions";
import {
selectIsLoggedIn,
selectCurrentUserName,
selectThumbnailPhoto,
} from "state-management/selectors/user.selectors";
import { selectDatasetsInBatchIndicator } from "state-management/selectors/datasets.selectors";
import { AppConfigService, OAuth2Endpoint } from "app-config.service";
import { Router } from "@angular/router";
@Component({
selector: "app-app-header",
templateUrl: "./app-header.component.html",
styleUrls: ["./app-header.component.scss"],
})
export class AppHeaderComponent implements OnInit {
config = this.appConfigService.getConfig();
facility = this.config.facility ?? "";
status = this.appConfig.production ? "" : "test";
siteHeaderLogo = this.config.siteHeaderLogo ?? "site-header-logo.png";
oAuth2Endpoints: OAuth2Endpoint[] = [];
username$ = this.store.select(selectCurrentUserName);
profileImage$ = this.store.select(selectThumbnailPhoto);
inBatchIndicator$ = this.store.select(selectDatasetsInBatchIndicator);
loggedIn$ = this.store.select(selectIsLoggedIn);
constructor(
public appConfigService: AppConfigService,
private router: Router,
@Inject(APP_CONFIG) public appConfig: AppConfig,
private store: Store,
@Inject(DOCUMENT) public document: Document,
) {}
logout(): void {
this.store.dispatch(logoutAction());
}
login(): void {
if (this.config.skipSciCatLoginPageEnabled) {
for (const endpoint of this.oAuth2Endpoints) {
this.document.location.href = `${this.config.lbBaseURL}/${endpoint.authURL}`;
}
} else {
this.router.navigateByUrl("/login");
}
}
ngOnInit() {
this.store.dispatch(fetchCurrentUserAction());
this.oAuth2Endpoints = this.config.oAuth2Endpoints;
}
}