-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathuser-menu.component.ts
More file actions
106 lines (99 loc) · 3.63 KB
/
Copy pathuser-menu.component.ts
File metadata and controls
106 lines (99 loc) · 3.63 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { Component, OnInit, Inject } from '@angular/core'
import { UserService } from 'src/app/core'
import { UserInfo } from 'src/app/types'
import { PlatformInfoService, PlatformInfo } from 'src/app/cdk/platform-info'
import { WINDOW } from 'src/app/cdk/window'
import { Router } from '@angular/router'
import { ApplicationRoutes } from 'src/app/constants'
import { TogglzService } from 'src/app/core/togglz/togglz.service'
import { InboxService } from '../../core/inbox/inbox.service'
import { first } from 'rxjs/operators'
import { CustomEventService } from 'src/app/core/observability-events/observability-events.service'
@Component({
selector: 'app-user-menu',
templateUrl: './user-menu.component.html',
styleUrls: [
'./user-menu.component.scss-theme.scss',
'./user-menu.component.scss',
],
})
export class UserMenuComponent implements OnInit {
state = false
userInfo: UserInfo
displayName: string
platform: PlatformInfo
labelSigninRegister = $localize`:@@layout.ariaLabelSigninRegister:Sign in to ORCID or register for your ORCID iD`
labelUserMenu = $localize`:@@layout.ariaLabelUserMenu:User menu`
notificationTooltipActive = $localize`:@@layout.notificationTooltip:You have unread notifications`
notificationTooltip = $localize`:@@layout.notificationTooltipInactive:Notifications inbox`
isAccountDelegate: boolean
inboxUnread = 0
userJourney!: 'orcid_with_notifications' | 'orcid_without_notifications'
constructor(
private _router: Router,
private _userInfo: UserService,
@Inject(WINDOW) private window: Window,
_platform: PlatformInfoService,
private _inboxService: InboxService,
private _togglz: TogglzService,
private observabilityEventService: CustomEventService
) {
_userInfo.getUserSession().subscribe((data) => {
if (data.loggedIn) {
this.userInfo = data.userInfo
this.displayName = data.displayName
this.isAccountDelegate =
data.userInfo.REAL_USER_ORCID === data.userInfo.EFFECTIVE_USER_ORCID
} else {
this.userInfo = null
this.displayName = null
}
})
_platform.get().subscribe((data) => {
this.platform = data
})
}
ngOnInit() {
this._inboxService
.retrieveUnreadCount()
.pipe(first())
.subscribe((inboxUnread) => {
;(this.userJourney =
inboxUnread > 0
? 'orcid_with_notifications'
: 'orcid_without_notifications'),
this.observabilityEventService.startJourney(
this.userJourney,
{ inboxUnread }
)
this.inboxUnread = inboxUnread
})
}
goto(url, from?: string) {
if (url === 'my-orcid') {
this._router.navigate([ApplicationRoutes.myOrcid])
} else if (url === 'signin') {
this._router.navigate([ApplicationRoutes.signin])
} else if (url === 'inbox') {
this.observabilityEventService.recordEvent(this.userJourney, from)
this._router.navigate([ApplicationRoutes.inbox])
} else if (url === 'account') {
this._router.navigate([ApplicationRoutes.account])
} else if (url === 'trusted-parties') {
this._router.navigate([ApplicationRoutes.trustedParties])
} else if (url === 'trusted-parties') {
this._router.navigate([ApplicationRoutes.trustedParties])
} else if (url === 'developer-tools') {
this._router.navigate([ApplicationRoutes.developerTools])
} else {
this.window.location.href = runtimeEnvironment.BASE_URL + url
}
}
navigateTo(val) {
if (val === '/signout' && runtimeEnvironment.proxyMode) {
this._userInfo.noRedirectLogout().subscribe()
} else {
this.window.location.href = val
}
}
}