1
|
import {Component, ElementRef, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
2
|
import {ActivatedRoute, NavigationStart, Router} from '@angular/router';
|
3
|
import {Location} from '@angular/common';
|
4
|
import {User, Session} from './utils/helper.class';
|
5
|
import {RouterHelper} from '../utils/routerHelper.class';
|
6
|
import {StringUtils} from '../utils/string-utils.class';
|
7
|
import {EnvProperties} from '../utils/properties/env-properties';
|
8
|
import {properties} from "../../../environments/environment";
|
9
|
|
10
|
// declare var logoutClicked;
|
11
|
@Component({
|
12
|
selector: 'user-mini',
|
13
|
template: `
|
14
|
<ng-container *ngIf="!dashboard">
|
15
|
|
16
|
<ul *ngIf="!mobileView" class="uk-navbar-nav" [class.uk-dark]="dark">
|
17
|
<li class="uk-parent">
|
18
|
<a *ngIf="loggedIn" class="login">
|
19
|
<svg height="60" width="60">
|
20
|
<circle cx="30" cy="30" r="20" stroke-width="2"></circle>
|
21
|
<text *ngIf="firstLetters" x="50%" y="50%" text-anchor="middle" dy=".4em"
|
22
|
font-size="16">
|
23
|
{{firstLetters}}
|
24
|
</text>
|
25
|
<svg *ngIf="!firstLetters" ratio="1" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" width="20"
|
26
|
x="20">
|
27
|
<circle cx="9.9" cy="6.4" r="4.4" stroke-width="1.1"></circle>
|
28
|
<path d="M1.5,19 C2.3,14.5 5.8,11.2 10,11.2 C14.2,11.2 17.7,14.6 18.5,19.2" stroke-width="1.1"></path>
|
29
|
</svg>
|
30
|
</svg>
|
31
|
</a>
|
32
|
<a *ngIf="!loggedIn" class="loginLink" (click)="logIn()">Sign in <span
|
33
|
class=" uk-margin-small-left uk-margin-small-right uk-icon"><svg width="20" height="20"
|
34
|
viewBox="0 0 20 20"
|
35
|
xmlns="http://www.w3.org/2000/svg"
|
36
|
ratio="1"><circle fill="none"
|
37
|
stroke="#000"
|
38
|
stroke-width="1.1"
|
39
|
cx="9.9" cy="6.4"
|
40
|
r="4.4"></circle><path
|
41
|
fill="none" stroke="#000" stroke-width="1.1"
|
42
|
d="M1.5,19 C2.3,14.5 5.8,11.2 10,11.2 C14.2,11.2 17.7,14.6 18.5,19.2"></path></svg> </span>
|
43
|
</a>
|
44
|
|
45
|
|
46
|
<div *ngIf="loggedIn" class="uk-navbar-dropdown uk-navbar-dropdown-bottom-left" id="userMenu"
|
47
|
(click)="onClick('userMenu')">
|
48
|
<div class="uk-navbar-dropdown-grid uk-child-width-1-1 uk-grid uk-grid-stack" uk-grid="">
|
49
|
<div class="uk-first-column uk-height-max-medium uk-overflow-auto">
|
50
|
<ul class="uk-nav uk-navbar-dropdown-nav">
|
51
|
<!--li><a href="" >My profile</a></li>
|
52
|
<li><a routerLinkActive="uk-link" routerLink="/myclaims">My Claims</a></li>
|
53
|
<li *ngIf="isAuthorized"><a routerLinkActive="uk-link" routerLink="/claims">Manage all Claims</a></li-->
|
54
|
<ng-container *ngFor="let item of userMenuItems ">
|
55
|
<li *ngIf="item.needsAuthorization && isAuthorized || !item.needsAuthorization">
|
56
|
<a *ngIf="item.route.length > 0" routerLink="{{item.route}}"
|
57
|
[queryParams]=item.params>{{item.title}}</a>
|
58
|
<a *ngIf="item.route.length == 0 && item.url.length > 0" href="{{item.url}}"
|
59
|
target="_blank">{{item.title}}</a>
|
60
|
</li>
|
61
|
</ng-container>
|
62
|
<li *ngIf="userMenuItems.length > 0" class="uk-nav-divider"></li>
|
63
|
<li><a (click)="logOut()" id="logout">Log out</a></li>
|
64
|
</ul>
|
65
|
</div>
|
66
|
<div id="logout1"></div>
|
67
|
</div>
|
68
|
</div>
|
69
|
</li>
|
70
|
</ul>
|
71
|
</ng-container>
|
72
|
|
73
|
<ng-container *ngIf="!dashboard">
|
74
|
|
75
|
<li *ngIf="mobileView" class="uk-nav-header uk-parent ">
|
76
|
|
77
|
<span *ngIf="loggedIn" class="uk-flex uk-flex-middle">
|
78
|
<span>{{user.fullname + " "}}</span>
|
79
|
<span class="uk-margin-small-right uk-icon"><svg width="20" height="20"
|
80
|
viewBox="0 0 20 20"
|
81
|
xmlns="http://www.w3.org/2000/svg"
|
82
|
ratio="1"><circle fill="none"
|
83
|
stroke="#000"
|
84
|
stroke-width="1.1"
|
85
|
cx="9.9"
|
86
|
cy="6.4"
|
87
|
r="4.4"></circle><path
|
88
|
fill="none" stroke="#000" stroke-width="1.1"
|
89
|
d="M1.5,19 C2.3,14.5 5.8,11.2 10,11.2 C14.2,11.2 17.7,14.6 18.5,19.2"></path></svg>
|
90
|
</span>
|
91
|
</span>
|
92
|
<span *ngIf="!loggedIn">
|
93
|
<a class="loginLink" (click)="logIn()">Sign in <span class="uk-margin-small-right uk-icon"><svg width="20"
|
94
|
height="20"
|
95
|
viewBox="0 0 20 20"
|
96
|
xmlns="http://www.w3.org/2000/svg"
|
97
|
ratio="1"><circle
|
98
|
fill="none" stroke="#000" stroke-width="1.1" cx="9.9" cy="6.4" r="4.4"></circle><path fill="none"
|
99
|
stroke="#000"
|
100
|
stroke-width="1.1"
|
101
|
d="M1.5,19 C2.3,14.5 5.8,11.2 10,11.2 C14.2,11.2 17.7,14.6 18.5,19.2"></path></svg></span>
|
102
|
</a>
|
103
|
</span>
|
104
|
|
105
|
<ul *ngIf="loggedIn" class="uk-nav-sub">
|
106
|
<!--li><a href="" >My profile</a></li>
|
107
|
<li><a routerLinkActive="uk-link" routerLink="/myclaims">My Claims</a></li>
|
108
|
<li *ngIf="isAuthorized"><a routerLinkActive="uk-link" routerLink="/claims">Manage all Claims</a></li-->
|
109
|
<ng-container *ngFor="let item of userMenuItems ">
|
110
|
<li *ngIf="item.needsAuthorization && isAuthorized || !item.needsAuthorization">
|
111
|
<a *ngIf="item.route.length > 0" routerLink="{{item.route}}">{{item.title}}</a>
|
112
|
<a *ngIf="item.route.length == 0 && item.url.length > 0" href="{{item.url}}">{{item.title}}</a>
|
113
|
</li>
|
114
|
</ng-container>
|
115
|
<li *ngIf="userMenuItems.length > 0" class="uk-nav-divider"></li>
|
116
|
<li><a (click)="logOut()" id="logout">Log out</a></li>
|
117
|
</ul>
|
118
|
</li>
|
119
|
</ng-container>
|
120
|
<ng-container *ngIf="dashboard">
|
121
|
<a *ngIf="!loggedIn" class="uk-flex" (click)="logIn()">
|
122
|
<span>Sign in</span>
|
123
|
<span class="uk-margin-small-left uk-margin-small-right uk-icon">
|
124
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1">
|
125
|
<circle cx="9.9" cy="6.4" r="4.4" stroke-width="1.1"></circle>
|
126
|
<path d="M1.5,19 C2.3,14.5 5.8,11.2 10,11.2 C14.2,11.2 17.7,14.6 18.5,19.2" stroke-width="1.1"></path>
|
127
|
</svg>
|
128
|
</span>
|
129
|
</a>
|
130
|
<a *ngIf="loggedIn" class="login uk-icon">
|
131
|
<svg height="60" width="60">
|
132
|
<circle cx="30" cy="30" r="20" stroke-width="2"></circle>
|
133
|
<text *ngIf="firstLetters" x="50%" y="50%" text-anchor="middle" dy=".4em"
|
134
|
font-size="16">
|
135
|
{{firstLetters}}
|
136
|
</text>
|
137
|
<svg *ngIf="!firstLetters" ratio="1" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" width="20"
|
138
|
x="20">
|
139
|
<circle cx="9.9" cy="6.4" r="4.4" stroke-width="1.1"></circle>
|
140
|
<path d="M1.5,19 C2.3,14.5 5.8,11.2 10,11.2 C14.2,11.2 17.7,14.6 18.5,19.2" stroke-width="1.1"></path>
|
141
|
</svg>
|
142
|
</svg>
|
143
|
</a>
|
144
|
<div *ngIf="loggedIn" uk-dropdown="mode: click; offset: -2; delay-hide: 0; flip: false; pos: bottom-right"
|
145
|
#userMenu
|
146
|
class="uk-padding-remove-horizontal">
|
147
|
<ul class="uk-nav uk-dropdown-nav">
|
148
|
<ng-container *ngFor="let item of userMenuItems ">
|
149
|
<li *ngIf="item.needsAuthorization && isAuthorized || !item.needsAuthorization">
|
150
|
<a *ngIf="item.route.length > 0" routerLink="{{item.route}}"
|
151
|
[queryParams]=item.params>{{item.title}}</a>
|
152
|
<a *ngIf="item.route.length == 0 && item.url.length > 0" href="{{item.url}}"
|
153
|
target="_blank">{{item.title}}</a>
|
154
|
</li>
|
155
|
</ng-container>
|
156
|
<li *ngIf="userMenuItems.length > 0" class="uk-nav-divider"></li>
|
157
|
<li><a (click)="logOut()" id="logout">Log out</a></li>
|
158
|
</ul>
|
159
|
</div>
|
160
|
</ng-container>
|
161
|
|
162
|
<div id="logout2"></div>
|
163
|
`
|
164
|
})
|
165
|
|
166
|
export class UserMiniComponent implements OnInit, OnChanges {
|
167
|
@Input() user: User;
|
168
|
public loggedIn: boolean = false;
|
169
|
public isAuthorized: boolean = false;
|
170
|
@Input() public mobileView: boolean = false;
|
171
|
public firstLetters: string = "";
|
172
|
@Input() public dashboard: boolean = false;
|
173
|
public server: boolean = true;
|
174
|
public routerHelper: RouterHelper = new RouterHelper();
|
175
|
@Input() userMenuItems;
|
176
|
@Input() logInUrl;
|
177
|
@Input() logOutUrl;
|
178
|
@Input() cookieDomain;
|
179
|
@Input() fixRedirectUrl: string;
|
180
|
@Input() redirectUrl: string;
|
181
|
@Input() dark: boolean = false;
|
182
|
search: string = '';
|
183
|
sub: any;
|
184
|
|
185
|
constructor(private router: Router, private route: ActivatedRoute) {
|
186
|
this.router.events.forEach(event => {
|
187
|
if(event instanceof NavigationStart) {
|
188
|
this.initialize(event.url);
|
189
|
}
|
190
|
});
|
191
|
}
|
192
|
|
193
|
ngOnInit() {
|
194
|
if (typeof document !== 'undefined') {
|
195
|
this.server = false;
|
196
|
}
|
197
|
this.sub = this.route.queryParams.subscribe(params => {
|
198
|
this.initialize();
|
199
|
});
|
200
|
}
|
201
|
|
202
|
ngOnChanges(changes: SimpleChanges): void {
|
203
|
if (changes.user) {
|
204
|
this.initialize();
|
205
|
}
|
206
|
}
|
207
|
|
208
|
ngOnDestroy() {
|
209
|
if (this.sub) {
|
210
|
this.sub.unsubscribe();
|
211
|
}
|
212
|
}
|
213
|
|
214
|
initialize(url: string = null) {
|
215
|
if (typeof location !== 'undefined') {
|
216
|
if(url) {
|
217
|
let parts = StringUtils.split(url, ['?']);
|
218
|
this.redirectUrl = properties.baseLink + parts[0];
|
219
|
if(parts.length == 2) {
|
220
|
this.search = parts[1];
|
221
|
} else {
|
222
|
this.search = null;
|
223
|
}
|
224
|
} else {
|
225
|
this.redirectUrl = location.pathname;
|
226
|
this.search = location.search;
|
227
|
}
|
228
|
}
|
229
|
if (this.user) {
|
230
|
this.loggedIn = true;
|
231
|
this.parseName();
|
232
|
this.isAuthorized = Session.isClaimsCurator(this.user) || Session.isPortalAdministrator(this.user);
|
233
|
|
234
|
} else {
|
235
|
this.loggedIn = false;
|
236
|
this.isAuthorized = false;
|
237
|
this.user = null;
|
238
|
}
|
239
|
|
240
|
}
|
241
|
|
242
|
logOut() {
|
243
|
if (this.user) {
|
244
|
Session.removeUser();
|
245
|
// New method
|
246
|
if(properties.logoutUrl.includes('openid_logout')) {
|
247
|
Session.setReloadUrl(location.protocol + "//" + location.host, this.redirectUrl, this.search);
|
248
|
window.location.href = this.logOutUrl;
|
249
|
} else {
|
250
|
window.location.href = this.logOutUrl + StringUtils.URIEncode(location.href);
|
251
|
}
|
252
|
}
|
253
|
this.loggedIn = false;
|
254
|
this.isAuthorized = false;
|
255
|
this.user = new User();
|
256
|
}
|
257
|
|
258
|
logIn() {
|
259
|
Session.setReloadUrl(location.protocol + "//" + location.host,
|
260
|
this.fixRedirectUrl?(properties.baseLink + this.fixRedirectUrl):this.redirectUrl, this.search);
|
261
|
window.location.href = this.logInUrl;
|
262
|
}
|
263
|
|
264
|
onClick(id: string) {
|
265
|
let el: HTMLElement = document.getElementById(id);
|
266
|
el.classList.remove('uk-open');
|
267
|
}
|
268
|
|
269
|
parseName() {
|
270
|
this.firstLetters = "";
|
271
|
if (this.user && this.user.firstname) {
|
272
|
this.firstLetters += this.user.firstname.substr(0, 1);
|
273
|
}
|
274
|
if (this.user && this.user.lastname) {
|
275
|
this.firstLetters += this.user.lastname.substr(0, 1);
|
276
|
}
|
277
|
if (!this.firstLetters && this.user && this.user.fullname) {
|
278
|
let matches = this.user.fullname.match(/\b(\w)/g);
|
279
|
this.firstLetters += matches.join('');
|
280
|
}
|
281
|
}
|
282
|
}
|