2020-11-11 15:43:13 +01:00
|
|
|
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
2021-03-17 10:21:37 +01:00
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
import {Session, User} from './utils/helper.class';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {RouterHelper} from '../utils/routerHelper.class';
|
2020-11-11 15:43:13 +01:00
|
|
|
import {Subscriber} from "rxjs";
|
2021-01-11 15:14:44 +01:00
|
|
|
import {MenuItem} from "../sharedComponents/menu";
|
2021-03-17 10:21:37 +01:00
|
|
|
import {UserManagementService} from "../services/user-management.service";
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2018-02-05 16:13:55 +01:00
|
|
|
// declare var logoutClicked;
|
2017-12-19 13:53:46 +01:00
|
|
|
@Component({
|
2020-05-06 18:31:54 +02:00
|
|
|
selector: 'user-mini',
|
|
|
|
template: `
|
|
|
|
<ng-container *ngIf="!dashboard">
|
2020-09-24 14:50:27 +02:00
|
|
|
|
2020-08-05 15:27:13 +02:00
|
|
|
<ul *ngIf="!mobileView" class="uk-navbar-nav" [class.uk-dark]="dark">
|
2020-05-06 18:31:54 +02:00
|
|
|
<li class="uk-parent">
|
|
|
|
<a *ngIf="loggedIn" class="login">
|
|
|
|
<svg height="60" width="60">
|
|
|
|
<circle cx="30" cy="30" r="20" stroke-width="2"></circle>
|
|
|
|
<text *ngIf="firstLetters" x="50%" y="50%" text-anchor="middle" dy=".4em"
|
|
|
|
font-size="16">
|
|
|
|
{{firstLetters}}
|
|
|
|
</text>
|
|
|
|
<svg *ngIf="!firstLetters" ratio="1" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" width="20"
|
|
|
|
x="20">
|
|
|
|
<circle cx="9.9" cy="6.4" r="4.4" stroke-width="1.1"></circle>
|
|
|
|
<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>
|
|
|
|
</svg>
|
|
|
|
</svg>
|
|
|
|
</a>
|
2021-01-11 15:14:44 +01:00
|
|
|
<a *ngIf="!loggedIn" class="loginLink" id="userMenu-parent" (click)="logIn()">Sign in <span
|
2020-05-06 18:31:54 +02:00
|
|
|
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>
|
|
|
|
</a>
|
2019-12-12 15:11:01 +01:00
|
|
|
|
|
|
|
|
2021-01-11 15:14:44 +01:00
|
|
|
<div *ngIf="loggedIn" class="uk-navbar-dropdown uk-navbar-dropdown-bottom-left" id="userMenu" uk-toggle>
|
2020-05-06 18:31:54 +02:00
|
|
|
<div class="uk-navbar-dropdown-grid uk-child-width-1-1 uk-grid uk-grid-stack" uk-grid="">
|
|
|
|
<div class="uk-first-column uk-height-max-medium uk-overflow-auto">
|
|
|
|
<ul class="uk-nav uk-navbar-dropdown-nav">
|
|
|
|
<!--li><a href="" >My profile</a></li>
|
|
|
|
<li><a routerLinkActive="uk-link" routerLink="/myclaims">My Claims</a></li>
|
|
|
|
<li *ngIf="isAuthorized"><a routerLinkActive="uk-link" routerLink="/claims">Manage all Claims</a></li-->
|
|
|
|
<ng-container *ngFor="let item of userMenuItems ">
|
2021-01-11 15:14:44 +01:00
|
|
|
<li *ngIf="item.needsAuthorization && isAuthorized || !item.needsAuthorization" [class.uk-active]="isTheActiveSubMenu(item)">
|
2020-05-06 18:31:54 +02:00
|
|
|
<a *ngIf="item.route.length > 0" routerLink="{{item.route}}"
|
|
|
|
[queryParams]=item.params>{{item.title}}</a>
|
|
|
|
<a *ngIf="item.route.length == 0 && item.url.length > 0" href="{{item.url}}"
|
|
|
|
target="_blank">{{item.title}}</a>
|
|
|
|
</li>
|
|
|
|
</ng-container>
|
|
|
|
<li *ngIf="userMenuItems.length > 0" class="uk-nav-divider"></li>
|
|
|
|
<li><a (click)="logOut()" id="logout">Log out</a></li>
|
|
|
|
</ul>
|
2019-12-15 13:44:20 +01:00
|
|
|
</div>
|
2020-05-06 18:31:54 +02:00
|
|
|
<div id="logout1"></div>
|
2019-12-15 13:44:20 +01:00
|
|
|
</div>
|
2020-05-06 18:31:54 +02:00
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</ng-container>
|
2019-12-12 15:11:01 +01:00
|
|
|
|
2020-05-06 18:31:54 +02:00
|
|
|
<ng-container *ngIf="!dashboard">
|
2019-12-12 15:11:01 +01:00
|
|
|
|
2020-05-06 18:31:54 +02:00
|
|
|
<li *ngIf="mobileView" class="uk-nav-header uk-parent ">
|
2020-02-06 14:34:37 +01:00
|
|
|
|
2020-05-06 18:31:54 +02:00
|
|
|
<span *ngIf="loggedIn" class="uk-flex uk-flex-middle">
|
|
|
|
<span>{{user.fullname + " "}}</span>
|
|
|
|
<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
|
2019-12-15 13:44:20 +01:00
|
|
|
fill="none" stroke="#000" stroke-width="1.1"
|
2020-05-06 18:31:54 +02:00
|
|
|
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>
|
2019-12-12 15:11:01 +01:00
|
|
|
</span>
|
2020-05-06 18:31:54 +02:00
|
|
|
<span *ngIf="!loggedIn">
|
2019-12-15 13:44:20 +01: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>
|
2019-12-12 15:11:01 +01:00
|
|
|
</a>
|
|
|
|
</span>
|
2019-12-15 13:44:20 +01:00
|
|
|
|
2020-05-06 18:31:54 +02:00
|
|
|
<ul *ngIf="loggedIn" class="uk-nav-sub">
|
|
|
|
<!--li><a href="" >My profile</a></li>
|
|
|
|
<li><a routerLinkActive="uk-link" routerLink="/myclaims">My Claims</a></li>
|
|
|
|
<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">
|
|
|
|
<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>
|
|
|
|
</li>
|
|
|
|
</ng-container>
|
|
|
|
<li *ngIf="userMenuItems.length > 0" class="uk-nav-divider"></li>
|
|
|
|
<li><a (click)="logOut()" id="logout">Log out</a></li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
</ng-container>
|
|
|
|
<ng-container *ngIf="dashboard">
|
2020-08-03 12:59:05 +02:00
|
|
|
<a *ngIf="!loggedIn" class="uk-flex" (click)="logIn()">
|
2020-07-10 10:37:17 +02:00
|
|
|
<span>Sign in</span>
|
|
|
|
<span class="uk-margin-small-left uk-margin-small-right uk-icon">
|
2019-12-13 16:40:13 +01:00
|
|
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1">
|
2020-01-14 20:49:17 +01:00
|
|
|
<circle cx="9.9" cy="6.4" r="4.4" stroke-width="1.1"></circle>
|
|
|
|
<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>
|
2020-07-10 10:37:17 +02:00
|
|
|
</svg>
|
|
|
|
</span>
|
2020-05-06 18:31:54 +02:00
|
|
|
</a>
|
2020-08-03 12:39:47 +02:00
|
|
|
<a *ngIf="loggedIn" class="login uk-icon">
|
2020-05-06 18:31:54 +02:00
|
|
|
<svg height="60" width="60">
|
|
|
|
<circle cx="30" cy="30" r="20" stroke-width="2"></circle>
|
|
|
|
<text *ngIf="firstLetters" x="50%" y="50%" text-anchor="middle" dy=".4em"
|
|
|
|
font-size="16">
|
|
|
|
{{firstLetters}}
|
|
|
|
</text>
|
|
|
|
<svg *ngIf="!firstLetters" ratio="1" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" width="20"
|
|
|
|
x="20">
|
|
|
|
<circle cx="9.9" cy="6.4" r="4.4" stroke-width="1.1"></circle>
|
|
|
|
<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>
|
2019-12-12 15:11:01 +01:00
|
|
|
</svg>
|
2020-05-06 18:31:54 +02:00
|
|
|
</svg>
|
|
|
|
</a>
|
|
|
|
<div *ngIf="loggedIn" uk-dropdown="mode: click; offset: -2; delay-hide: 0; flip: false; pos: bottom-right"
|
|
|
|
#userMenu
|
|
|
|
class="uk-padding-remove-horizontal">
|
|
|
|
<ul class="uk-nav uk-dropdown-nav">
|
|
|
|
<ng-container *ngFor="let item of userMenuItems ">
|
|
|
|
<li *ngIf="item.needsAuthorization && isAuthorized || !item.needsAuthorization">
|
|
|
|
<a *ngIf="item.route.length > 0" routerLink="{{item.route}}"
|
|
|
|
[queryParams]=item.params>{{item.title}}</a>
|
|
|
|
<a *ngIf="item.route.length == 0 && item.url.length > 0" href="{{item.url}}"
|
|
|
|
target="_blank">{{item.title}}</a>
|
|
|
|
</li>
|
|
|
|
</ng-container>
|
|
|
|
<li *ngIf="userMenuItems.length > 0" class="uk-nav-divider"></li>
|
|
|
|
<li><a (click)="logOut()" id="logout">Log out</a></li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</ng-container>
|
2019-12-15 13:44:20 +01:00
|
|
|
|
2020-05-06 18:31:54 +02:00
|
|
|
<div id="logout2"></div>
|
|
|
|
`
|
2017-12-19 13:53:46 +01:00
|
|
|
})
|
2019-12-15 13:44:20 +01:00
|
|
|
export class UserMiniComponent implements OnInit, OnChanges {
|
2020-05-06 18:31:54 +02:00
|
|
|
@Input() user: User;
|
|
|
|
public loggedIn: boolean = false;
|
|
|
|
public isAuthorized: boolean = false;
|
|
|
|
@Input() public mobileView: boolean = false;
|
|
|
|
public firstLetters: string = "";
|
|
|
|
@Input() public dashboard: boolean = false;
|
|
|
|
public server: boolean = true;
|
|
|
|
public routerHelper: RouterHelper = new RouterHelper();
|
|
|
|
@Input() userMenuItems;
|
|
|
|
@Input() logInUrl;
|
|
|
|
@Input() logOutUrl;
|
|
|
|
@Input() cookieDomain;
|
2020-08-05 15:27:13 +02:00
|
|
|
@Input() dark: boolean = false;
|
2020-11-11 15:43:13 +01:00
|
|
|
subscriptions = [];
|
2020-05-06 18:31:54 +02:00
|
|
|
|
2021-03-17 10:21:37 +01:00
|
|
|
constructor(private router: Router, private route: ActivatedRoute, private userManagementService: UserManagementService) {
|
2020-05-06 18:31:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
if (typeof document !== 'undefined') {
|
|
|
|
this.server = false;
|
2019-12-15 13:44:20 +01:00
|
|
|
}
|
2021-03-17 10:21:37 +01:00
|
|
|
this.initUser();
|
2020-05-06 18:31:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
|
|
if (changes.user) {
|
2021-03-17 10:21:37 +01:00
|
|
|
this.initUser();
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-05-06 18:31:54 +02:00
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
|
2020-05-06 18:31:54 +02:00
|
|
|
ngOnDestroy() {
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscriber) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
2020-05-06 18:31:54 +02:00
|
|
|
}
|
|
|
|
|
2021-03-17 10:21:37 +01:00
|
|
|
initUser() {
|
2020-05-06 18:31:54 +02:00
|
|
|
if (this.user) {
|
|
|
|
this.loggedIn = true;
|
|
|
|
this.parseName();
|
|
|
|
this.isAuthorized = Session.isClaimsCurator(this.user) || Session.isPortalAdministrator(this.user);
|
|
|
|
} else {
|
|
|
|
this.loggedIn = false;
|
|
|
|
this.isAuthorized = false;
|
|
|
|
this.user = null;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-05-06 18:31:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
logOut() {
|
|
|
|
if (this.user) {
|
2021-03-17 10:21:37 +01:00
|
|
|
this.userManagementService.logout();
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-05-06 18:31:54 +02:00
|
|
|
this.loggedIn = false;
|
|
|
|
this.isAuthorized = false;
|
|
|
|
this.user = new User();
|
|
|
|
}
|
|
|
|
|
|
|
|
logIn() {
|
2021-03-17 10:21:37 +01:00
|
|
|
this.userManagementService.login();
|
2020-05-06 18:31:54 +02:00
|
|
|
}
|
2021-01-11 15:14:44 +01:00
|
|
|
|
|
|
|
isTheActiveSubMenu(menuItem: MenuItem): boolean {
|
|
|
|
let currentRoute = this.router.url.split('?')[0];
|
|
|
|
if (menuItem.route == currentRoute || menuItem.route == (currentRoute + "/") ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2020-05-06 18:31:54 +02:00
|
|
|
}
|
|
|
|
parseName() {
|
|
|
|
this.firstLetters = "";
|
|
|
|
if (this.user && this.user.firstname) {
|
|
|
|
this.firstLetters += this.user.firstname.substr(0, 1);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-05-06 18:31:54 +02:00
|
|
|
if (this.user && this.user.lastname) {
|
|
|
|
this.firstLetters += this.user.lastname.substr(0, 1);
|
2019-12-12 15:11:01 +01:00
|
|
|
}
|
2020-05-06 18:31:54 +02:00
|
|
|
if (!this.firstLetters && this.user && this.user.fullname) {
|
|
|
|
let matches = this.user.fullname.match(/\b(\w)/g);
|
|
|
|
this.firstLetters += matches.join('');
|
2019-12-12 15:11:01 +01:00
|
|
|
}
|
2020-05-06 18:31:54 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|