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