1
|
import {Component, ElementRef, Input} 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
|
<ul *ngIf="!mobileView" class="uk-navbar-nav">
|
14
|
<li class="uk-parent">
|
15
|
|
16
|
<a *ngIf="loggedIn" >
|
17
|
<span>{{user.fullname+" "}} <span class="uk-margin-small-right uk-icon" ><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"><circle fill="none" stroke="#000" stroke-width="1.1" cx="9.9" cy="6.4" r="4.4"></circle><path fill="none" stroke="#000" stroke-width="1.1" 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>
|
18
|
</a>
|
19
|
<a *ngIf="!loggedIn" class="loginLink" (click)="logIn()" >Sign in <span class=" uk-margin-small-left uk-margin-small-right uk-icon" ><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"><circle fill="none" stroke="#000" stroke-width="1.1" cx="9.9" cy="6.4" r="4.4"></circle><path fill="none" stroke="#000" stroke-width="1.1" 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>
|
20
|
</a>
|
21
|
|
22
|
|
23
|
<div *ngIf="loggedIn" class="uk-navbar-dropdown uk-navbar-dropdown-bottom-left" id="userMenu" (click)="onClick('userMenu')" >
|
24
|
<div class="uk-navbar-dropdown-grid uk-child-width-1-1 uk-grid uk-grid-stack" uk-grid="">
|
25
|
<div class="uk-first-column uk-height-max-medium uk-overflow-auto">
|
26
|
<ul class="uk-nav uk-navbar-dropdown-nav">
|
27
|
<!--li><a href="" >My profile</a></li>
|
28
|
<li><a routerLinkActive="uk-link" routerLink="/myclaims">My Claims</a></li>
|
29
|
<li *ngIf="isAuthorized"><a routerLinkActive="uk-link" routerLink="/claims">Manage all Claims</a></li-->
|
30
|
<ng-container *ngFor="let item of userMenuItems ">
|
31
|
<li *ngIf="item.needsAuthorization && isAuthorized || !item.needsAuthorization">
|
32
|
<a *ngIf="item.route.length > 0" routerLink="{{item.route}}" [queryParams]=item.params >{{item.title}}</a>
|
33
|
<a *ngIf="item.route.length == 0 && item.url.length > 0" href="{{item.url}}" target="_blank" >{{item.title}}</a>
|
34
|
</li>
|
35
|
</ng-container>
|
36
|
<li *ngIf="userMenuItems.length > 0" class="uk-nav-divider"></li>
|
37
|
<li><a (click)="logOut()" id="logout" >Log out</a></li>
|
38
|
</ul>
|
39
|
</div>
|
40
|
<div id="logout1"></div>
|
41
|
</div>
|
42
|
</div> </li>
|
43
|
</ul>
|
44
|
|
45
|
<li *ngIf="mobileView" class="uk-nav-header uk-parent " >
|
46
|
|
47
|
<span *ngIf="loggedIn" >
|
48
|
<span>{{user.fullname+" "}}<span class="uk-margin-small-right uk-icon" ><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"><circle fill="none" stroke="#000" stroke-width="1.1" cx="9.9" cy="6.4" r="4.4"></circle><path fill="none" stroke="#000" stroke-width="1.1" 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>
|
49
|
</span>
|
50
|
<span *ngIf="!loggedIn">
|
51
|
<a class="loginLink" (click)="logIn()" >Sign in <span class="uk-margin-small-right uk-icon" ><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"><circle fill="none" stroke="#000" stroke-width="1.1" cx="9.9" cy="6.4" r="4.4"></circle><path fill="none" stroke="#000" stroke-width="1.1" 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>
|
52
|
</a>
|
53
|
</span>
|
54
|
|
55
|
<ul *ngIf="loggedIn" class="uk-nav-sub">
|
56
|
<!--li><a href="" >My profile</a></li>
|
57
|
<li><a routerLinkActive="uk-link" routerLink="/myclaims">My Claims</a></li>
|
58
|
<li *ngIf="isAuthorized"><a routerLinkActive="uk-link" routerLink="/claims">Manage all Claims</a></li-->
|
59
|
<ng-container *ngFor="let item of userMenuItems ">
|
60
|
<li *ngIf="item.needsAuthorization && isAuthorized || !item.needsAuthorization">
|
61
|
<a *ngIf="item.route.length > 0" routerLink="{{item.route}}" >{{item.title}}</a>
|
62
|
<a *ngIf="item.route.length == 0 && item.url.length > 0" href="{{item.url}}" >{{item.title}}</a>
|
63
|
</li>
|
64
|
</ng-container>
|
65
|
<li *ngIf="userMenuItems.length > 0" class="uk-nav-divider"></li>
|
66
|
<li><a (click)="logOut()" id="logout" >Log out</a></li>
|
67
|
</ul>
|
68
|
</li>
|
69
|
<div id="logout2"></div>
|
70
|
`
|
71
|
})
|
72
|
|
73
|
export class UserMiniComponent {
|
74
|
public user: User;
|
75
|
public loggedIn: boolean = false;
|
76
|
public isAuthorized: boolean = false;
|
77
|
@Input() public mobileView:boolean = false ;
|
78
|
public server: boolean = true;
|
79
|
public routerHelper:RouterHelper = new RouterHelper();
|
80
|
@Input() userMenuItems;
|
81
|
@Input() logInUrl;
|
82
|
@Input() logOutUrl;
|
83
|
@Input() cookieDomain;
|
84
|
@Input() redirectUrl: string;
|
85
|
sub:any;
|
86
|
|
87
|
constructor( private router: Router, private route: ActivatedRoute, private location: Location) {}
|
88
|
|
89
|
ngOnInit() {
|
90
|
|
91
|
if( typeof document !== 'undefined') {
|
92
|
this.server = false;
|
93
|
}
|
94
|
this.initialize();
|
95
|
this.sub = this.route.queryParams.subscribe(params => {
|
96
|
this.initialize();
|
97
|
});
|
98
|
|
99
|
|
100
|
}
|
101
|
ngOnDestroy(){
|
102
|
if(this.sub) {
|
103
|
this.sub.unsubscribe();
|
104
|
}
|
105
|
}
|
106
|
|
107
|
initialize(){
|
108
|
if(!this.redirectUrl && location) {
|
109
|
this.redirectUrl = location.pathname;
|
110
|
}
|
111
|
if(Session.isLoggedIn()){
|
112
|
this.loggedIn = true;
|
113
|
this.user = Session.getUser();
|
114
|
if(Session.isClaimsCurator() || Session.isPortalAdministrator()){
|
115
|
this.isAuthorized = true;
|
116
|
} else {
|
117
|
this.isAuthorized = false;
|
118
|
}
|
119
|
|
120
|
}else {
|
121
|
this.loggedIn = false;
|
122
|
this.isAuthorized = false;
|
123
|
this.user = null;
|
124
|
}
|
125
|
|
126
|
}
|
127
|
|
128
|
logOut(){
|
129
|
if(Session.isLoggedIn()){
|
130
|
Session.removeUser();
|
131
|
window.location.href = this.logOutUrl + StringUtils.URIEncode(location.href);
|
132
|
|
133
|
}
|
134
|
this.loggedIn = false;
|
135
|
this.isAuthorized = false;
|
136
|
this.user = new User();
|
137
|
}
|
138
|
|
139
|
logIn(){
|
140
|
Session.setReloadUrl(location.protocol +"//"+location.host, this.redirectUrl, location.search);
|
141
|
window.location.href = this.logInUrl;
|
142
|
}
|
143
|
|
144
|
onClick(id: string) {
|
145
|
let el: HTMLElement = document.getElementById(id);
|
146
|
el.classList.remove('uk-open');
|
147
|
}
|
148
|
|
149
|
}
|