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