2017-12-19 13:53:46 +01:00
|
|
|
import {Component, ElementRef, Input} from '@angular/core';
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
import {Location} from '@angular/common';
|
|
|
|
import {User,Session} from './utils/helper.class';
|
|
|
|
import {RouterHelper} from '../utils/routerHelper.class';
|
|
|
|
import {StringUtils} from '../utils/string-utils.class';
|
2018-02-05 14:14:59 +01:00
|
|
|
import{EnvProperties} from '../utils/properties/env-properties';
|
|
|
|
|
2018-02-05 16:13:55 +01:00
|
|
|
// declare var logoutClicked;
|
2017-12-19 13:53:46 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'user-mini',
|
|
|
|
template: `
|
|
|
|
<ul *ngIf="!mobileView" class="uk-navbar-nav">
|
|
|
|
<li class="uk-parent">
|
|
|
|
|
2018-01-11 16:20:43 +01:00
|
|
|
<a *ngIf="loggedIn" >
|
|
|
|
<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>
|
|
|
|
</a>
|
2018-06-11 11:46:59 +02:00
|
|
|
<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>
|
2018-01-11 16:20:43 +01:00
|
|
|
</a>
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
<div *ngIf="loggedIn" class="uk-navbar-dropdown uk-navbar-dropdown-bottom-left" id="userMenu" (click)="onClick('userMenu')" >
|
|
|
|
<div class="uk-navbar-dropdown-grid uk-child-width-1-1 uk-grid uk-grid-stack" uk-grid="">
|
2019-05-24 17:08:44 +02:00
|
|
|
<div class="uk-first-column uk-height-max-medium uk-overflow-auto">
|
2017-12-19 13:53:46 +01:00
|
|
|
<ul class="uk-nav uk-navbar-dropdown-nav">
|
2018-01-11 16:20:43 +01:00
|
|
|
<!--li><a href="" >My profile</a></li>
|
2017-12-19 13:53:46 +01:00
|
|
|
<li><a routerLinkActive="uk-link" routerLink="/myclaims">My Claims</a></li>
|
2018-01-11 16:20:43 +01:00
|
|
|
<li *ngIf="isAuthorized"><a routerLinkActive="uk-link" routerLink="/claims">Manage all Claims</a></li-->
|
|
|
|
<ng-container *ngFor="let item of userMenuItems ">
|
|
|
|
<li *ngIf="item.needsAuthorization && isAuthorized || !item.needsAuthorization">
|
2018-03-26 10:54:29 +02:00
|
|
|
<a *ngIf="item.route.length > 0" routerLink="{{item.route}}" [queryParams]=item.params >{{item.title}}</a>
|
2018-07-30 16:22:19 +02:00
|
|
|
<a *ngIf="item.route.length == 0 && item.url.length > 0" href="{{item.url}}" target="_blank" >{{item.title}}</a>
|
2018-01-11 16:20:43 +01:00
|
|
|
</li>
|
|
|
|
</ng-container>
|
2019-04-16 12:37:31 +02:00
|
|
|
<li *ngIf="userMenuItems.length > 0" class="uk-nav-divider"></li>
|
2017-12-19 13:53:46 +01:00
|
|
|
<li><a (click)="logOut()" id="logout" >Log out</a></li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div id="logout1"></div>
|
|
|
|
</div>
|
|
|
|
</div> </li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<li *ngIf="mobileView" class="uk-nav-header uk-parent " >
|
|
|
|
|
|
|
|
<span *ngIf="loggedIn" >
|
|
|
|
<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>
|
|
|
|
</span>
|
|
|
|
<span *ngIf="!loggedIn">
|
2018-06-11 10:20:32 +02:00
|
|
|
<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>
|
2017-12-19 13:53:46 +01:00
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<ul *ngIf="loggedIn" class="uk-nav-sub">
|
2018-01-11 16:20:43 +01:00
|
|
|
<!--li><a href="" >My profile</a></li>
|
2017-12-19 13:53:46 +01:00
|
|
|
<li><a routerLinkActive="uk-link" routerLink="/myclaims">My Claims</a></li>
|
2018-01-11 16:20:43 +01:00
|
|
|
<li *ngIf="isAuthorized"><a routerLinkActive="uk-link" routerLink="/claims">Manage all Claims</a></li-->
|
|
|
|
<ng-container *ngFor="let item of userMenuItems ">
|
|
|
|
<li *ngIf="item.needsAuthorization && isAuthorized || !item.needsAuthorization">
|
2018-03-26 10:54:29 +02:00
|
|
|
<a *ngIf="item.route.length > 0" routerLink="{{item.route}}" >{{item.title}}</a>
|
|
|
|
<a *ngIf="item.route.length == 0 && item.url.length > 0" href="{{item.url}}" >{{item.title}}</a>
|
2018-01-11 16:20:43 +01:00
|
|
|
</li>
|
|
|
|
</ng-container>
|
2019-04-16 12:37:31 +02:00
|
|
|
<li *ngIf="userMenuItems.length > 0" class="uk-nav-divider"></li>
|
2017-12-19 13:53:46 +01:00
|
|
|
<li><a (click)="logOut()" id="logout" >Log out</a></li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
<div id="logout2"></div>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
|
|
|
|
export class UserMiniComponent {
|
|
|
|
public user: User;
|
|
|
|
public loggedIn: boolean = false;
|
|
|
|
public isAuthorized: boolean = false;
|
|
|
|
@Input() public mobileView:boolean = false ;
|
|
|
|
public server: boolean = true;
|
|
|
|
public routerHelper:RouterHelper = new RouterHelper();
|
2018-01-11 16:20:43 +01:00
|
|
|
@Input() userMenuItems;
|
|
|
|
@Input() logInUrl;
|
|
|
|
@Input() logOutUrl;
|
2018-02-05 14:14:59 +01:00
|
|
|
@Input() cookieDomain;
|
2019-08-28 14:55:55 +02:00
|
|
|
@Input() communityId = null;
|
2017-12-19 13:53:46 +01:00
|
|
|
public redirectUrl: string = "";
|
|
|
|
sub:any;
|
2018-02-05 14:14:59 +01:00
|
|
|
|
|
|
|
constructor( private router: Router, private route: ActivatedRoute, private location: Location) {}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
ngOnInit() {
|
2018-02-05 14:14:59 +01:00
|
|
|
|
|
|
|
if( typeof document !== 'undefined') {
|
|
|
|
this.server = false;
|
|
|
|
}
|
|
|
|
this.initialize();
|
|
|
|
this.sub = this.route.queryParams.subscribe(params => {
|
|
|
|
this.initialize();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
ngOnDestroy(){
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
2019-02-25 16:28:14 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
initialize(){
|
|
|
|
this.redirectUrl = this.location.path();
|
|
|
|
if(Session.isLoggedIn()){
|
2019-02-25 16:28:14 +01:00
|
|
|
this.loggedIn = true;
|
2017-12-19 13:53:46 +01:00
|
|
|
this.user = Session.getUser();
|
2018-03-27 10:22:55 +02:00
|
|
|
if(Session.isClaimsCurator() || Session.isPortalAdministrator()){
|
2019-02-25 16:28:14 +01:00
|
|
|
this.isAuthorized = true;
|
|
|
|
} else {
|
|
|
|
this.isAuthorized = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2018-07-02 15:42:20 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}else {
|
2019-02-25 16:28:14 +01:00
|
|
|
this.loggedIn = false;
|
|
|
|
this.isAuthorized = false;
|
|
|
|
this.user = null;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-02-25 16:28:14 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
logOut(){
|
|
|
|
if(Session.isLoggedIn()){
|
|
|
|
Session.removeUser();
|
2018-02-05 14:14:59 +01:00
|
|
|
window.location.href = this.logOutUrl + StringUtils.URIEncode(location.href);
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
this.loggedIn = false;
|
2019-02-25 16:28:14 +01:00
|
|
|
this.isAuthorized = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
this.user = new User();
|
|
|
|
}
|
|
|
|
|
|
|
|
logIn(){
|
2019-08-28 14:55:55 +02:00
|
|
|
if(this.communityId && this.communityId === 'connect') {
|
|
|
|
Session.setReloadUrl(location.protocol +"//"+location.host, '/myCommunities', null);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Session.setReloadUrl(location.protocol +"//"+location.host, location.pathname, location.search);
|
|
|
|
}
|
|
|
|
window.location.href = this.logInUrl;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onClick(id: string) {
|
2019-02-25 16:28:14 +01:00
|
|
|
let el: HTMLElement = document.getElementById(id);
|
2017-12-19 13:53:46 +01:00
|
|
|
el.classList.remove('uk-open');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|