1 |
50169
|
argiro.kok
|
import {Component, ElementRef, Input} from '@angular/core';
|
2 |
|
|
import {Observable} from 'rxjs/Observable';
|
3 |
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
4 |
|
|
import {Location} from '@angular/common';
|
5 |
|
|
// import {LoginService} from './login.service';
|
6 |
|
|
import {User,Session} from './utils/helper.class';
|
7 |
|
|
import {RouterHelper} from '../utils/routerHelper.class';
|
8 |
|
|
import {StringUtils} from '../utils/string-utils.class';
|
9 |
50586
|
argiro.kok
|
import{EnvProperties} from '../utils/properties/env-properties';
|
10 |
|
|
|
11 |
50591
|
argiro.kok
|
// declare var logoutClicked;
|
12 |
50169
|
argiro.kok
|
@Component({
|
13 |
|
|
selector: 'user-mini',
|
14 |
|
|
template: `
|
15 |
|
|
<ul *ngIf="!mobileView" class="uk-navbar-nav">
|
16 |
|
|
<li class="uk-parent">
|
17 |
|
|
|
18 |
50286
|
argiro.kok
|
<a *ngIf="loggedIn" >
|
19 |
|
|
<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>
|
20 |
|
|
</a>
|
21 |
52431
|
argiro.kok
|
<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>
|
22 |
50286
|
argiro.kok
|
</a>
|
23 |
50169
|
argiro.kok
|
|
24 |
|
|
|
25 |
|
|
<div *ngIf="loggedIn" class="uk-navbar-dropdown uk-navbar-dropdown-bottom-left" id="userMenu" (click)="onClick('userMenu')" >
|
26 |
|
|
<div class="uk-navbar-dropdown-grid uk-child-width-1-1 uk-grid uk-grid-stack" uk-grid="">
|
27 |
|
|
<div class="uk-first-column">
|
28 |
|
|
<ul class="uk-nav uk-navbar-dropdown-nav">
|
29 |
50286
|
argiro.kok
|
<!--li><a href="" >My profile</a></li>
|
30 |
50169
|
argiro.kok
|
<li><a routerLinkActive="uk-link" routerLink="/myclaims">My Claims</a></li>
|
31 |
50286
|
argiro.kok
|
<li *ngIf="isAuthorized"><a routerLinkActive="uk-link" routerLink="/claims">Manage all Claims</a></li-->
|
32 |
|
|
<ng-container *ngFor="let item of userMenuItems ">
|
33 |
|
|
<li *ngIf="item.needsAuthorization && isAuthorized || !item.needsAuthorization">
|
34 |
51506
|
argiro.kok
|
<a *ngIf="item.route.length > 0" routerLink="{{item.route}}" [queryParams]=item.params >{{item.title}}</a>
|
35 |
|
|
<a *ngIf="item.route.length == 0 && item.url.length > 0" href="{{item.url}}" >{{item.title}}</a>
|
36 |
50286
|
argiro.kok
|
</li>
|
37 |
|
|
</ng-container>
|
38 |
50169
|
argiro.kok
|
<li><a (click)="logOut()" id="logout" >Log out</a></li>
|
39 |
|
|
</ul>
|
40 |
|
|
</div>
|
41 |
|
|
<div id="logout1"></div>
|
42 |
|
|
</div>
|
43 |
|
|
</div> </li>
|
44 |
|
|
</ul>
|
45 |
|
|
|
46 |
|
|
<li *ngIf="mobileView" class="uk-nav-header uk-parent " >
|
47 |
|
|
|
48 |
|
|
<span *ngIf="loggedIn" >
|
49 |
|
|
<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>
|
50 |
|
|
</span>
|
51 |
|
|
<span *ngIf="!loggedIn">
|
52 |
52426
|
argiro.kok
|
<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>
|
53 |
50169
|
argiro.kok
|
</a>
|
54 |
|
|
</span>
|
55 |
|
|
|
56 |
|
|
<ul *ngIf="loggedIn" class="uk-nav-sub">
|
57 |
50286
|
argiro.kok
|
<!--li><a href="" >My profile</a></li>
|
58 |
50169
|
argiro.kok
|
<li><a routerLinkActive="uk-link" routerLink="/myclaims">My Claims</a></li>
|
59 |
50286
|
argiro.kok
|
<li *ngIf="isAuthorized"><a routerLinkActive="uk-link" routerLink="/claims">Manage all Claims</a></li-->
|
60 |
|
|
<ng-container *ngFor="let item of userMenuItems ">
|
61 |
|
|
<li *ngIf="item.needsAuthorization && isAuthorized || !item.needsAuthorization">
|
62 |
51506
|
argiro.kok
|
<a *ngIf="item.route.length > 0" routerLink="{{item.route}}" >{{item.title}}</a>
|
63 |
|
|
<a *ngIf="item.route.length == 0 && item.url.length > 0" href="{{item.url}}" >{{item.title}}</a>
|
64 |
50286
|
argiro.kok
|
</li>
|
65 |
|
|
</ng-container>
|
66 |
50169
|
argiro.kok
|
<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 |
50286
|
argiro.kok
|
@Input() userMenuItems;
|
81 |
|
|
@Input() logInUrl;
|
82 |
|
|
@Input() logOutUrl;
|
83 |
50586
|
argiro.kok
|
@Input() cookieDomain;
|
84 |
50169
|
argiro.kok
|
public redirectUrl: string = "";
|
85 |
|
|
private baseUrl = "user-info";
|
86 |
|
|
sub:any;
|
87 |
50586
|
argiro.kok
|
// public properties:EnvProperties;
|
88 |
50169
|
argiro.kok
|
|
89 |
50586
|
argiro.kok
|
constructor( private router: Router, private route: ActivatedRoute, private location: Location) {}
|
90 |
|
|
|
91 |
50169
|
argiro.kok
|
ngOnInit() {
|
92 |
50586
|
argiro.kok
|
|
93 |
|
|
if( typeof document !== 'undefined') {
|
94 |
|
|
this.server = false;
|
95 |
|
|
}
|
96 |
|
|
this.initialize();
|
97 |
|
|
this.sub = this.route.queryParams.subscribe(params => {
|
98 |
|
|
this.initialize();
|
99 |
|
|
});
|
100 |
|
|
|
101 |
|
|
|
102 |
50169
|
argiro.kok
|
}
|
103 |
|
|
ngOnDestroy(){
|
104 |
|
|
this.sub.unsubscribe();
|
105 |
|
|
}
|
106 |
|
|
initialize(){
|
107 |
|
|
this.redirectUrl = this.location.path();
|
108 |
|
|
if(Session.isLoggedIn()){
|
109 |
|
|
this.loggedIn = Session.isLoggedIn();
|
110 |
|
|
this.user = Session.getUser();
|
111 |
51526
|
argiro.kok
|
if(Session.isClaimsCurator() || Session.isPortalAdministrator()){
|
112 |
50169
|
argiro.kok
|
this.isAuthorized = true;
|
113 |
|
|
}else {
|
114 |
|
|
this.isAuthorized = false;
|
115 |
|
|
}
|
116 |
52451
|
argiro.kok
|
|
117 |
50169
|
argiro.kok
|
}else {
|
118 |
|
|
this.loggedIn = false;
|
119 |
|
|
this.isAuthorized = false;
|
120 |
|
|
this.user = null;
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
}
|
124 |
|
|
gotoUserPage(){
|
125 |
|
|
this.redirectUrl = this.location.path();
|
126 |
|
|
if(this.redirectUrl && this.redirectUrl != null && this.redirectUrl != "" && this.redirectUrl !="user-info"){
|
127 |
|
|
this.router.navigate([this.baseUrl], { queryParams: this.routerHelper.createQueryParam("redirectUrl",this.redirectUrl )});
|
128 |
|
|
}else{
|
129 |
|
|
this.router.navigate([this.baseUrl]);
|
130 |
|
|
}
|
131 |
|
|
}
|
132 |
|
|
logOut(){
|
133 |
|
|
if(Session.isLoggedIn()){
|
134 |
|
|
Session.removeUser();
|
135 |
52426
|
argiro.kok
|
console.log("Try to Logout!");
|
136 |
52177
|
argiro.kok
|
// console.log("Redirect to "+location.href);
|
137 |
50586
|
argiro.kok
|
window.location.href = this.logOutUrl + StringUtils.URIEncode(location.href);
|
138 |
50169
|
argiro.kok
|
|
139 |
|
|
}
|
140 |
|
|
this.loggedIn = false;
|
141 |
|
|
this.isAuthorized = false;
|
142 |
|
|
this.user = new User();
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
logIn(){
|
146 |
52177
|
argiro.kok
|
// console.log("LOgin is clicked " + this.logInUrl);
|
147 |
|
|
Session.setReloadUrl(location.protocol +"//"+location.host, location.pathname, location.search);
|
148 |
50586
|
argiro.kok
|
window.location.href = this.logInUrl
|
149 |
50169
|
argiro.kok
|
}
|
150 |
|
|
|
151 |
|
|
onClick(id: string) {
|
152 |
|
|
var el: HTMLElement = document.getElementById(id);
|
153 |
|
|
el.classList.remove('uk-open');
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
}
|