import {Component, ElementRef, Input} from '@angular/core'; import {Observable} from 'rxjs/Observable'; import {ActivatedRoute, Router} from '@angular/router'; import {Location} from '@angular/common'; // import {LoginService} from './login.service'; import {User,Session} from './utils/helper.class'; import {RouterHelper} from '../utils/routerHelper.class'; import {StringUtils} from '../utils/string-utils.class'; import{EnvProperties} from '../utils/properties/env-properties'; // declare var logoutClicked; @Component({ selector: 'user-mini', template: `
  • {{user.fullname+" "}} Sign in | Register
  • ` }) 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(); @Input() userMenuItems; @Input() logInUrl; @Input() logOutUrl; @Input() cookieDomain; public redirectUrl: string = ""; private baseUrl = "user-info"; sub:any; // public properties:EnvProperties; constructor( private router: Router, private route: ActivatedRoute, private location: Location) {} ngOnInit() { if( typeof document !== 'undefined') { this.server = false; } this.initialize(); this.sub = this.route.queryParams.subscribe(params => { this.initialize(); }); } ngOnDestroy(){ this.sub.unsubscribe(); } initialize(){ this.redirectUrl = this.location.path(); if(Session.isLoggedIn()){ if(Session.isUserValid()){ this.loggedIn = Session.isLoggedIn(); this.user = Session.getUser(); if(Session.isClaimsCurator() || Session.isPortalAdministrator()){ this.isAuthorized = true; }else { this.isAuthorized = false; } }else{ Session.removeUser(); this.loggedIn = false; this.isAuthorized = false; this.user = null; } }else { this.loggedIn = false; this.isAuthorized = false; this.user = null; } } gotoUserPage(){ this.redirectUrl = this.location.path(); if(this.redirectUrl && this.redirectUrl != null && this.redirectUrl != "" && this.redirectUrl !="user-info"){ this.router.navigate([this.baseUrl], { queryParams: this.routerHelper.createQueryParam("redirectUrl",this.redirectUrl )}); }else{ this.router.navigate([this.baseUrl]); } } logOut(){ if(Session.isLoggedIn()){ Session.removeUser(); console.log("Try to Logout!"); // this.logoutOpenaire.logout().subscribe(params => { // console.log("Logout!"); // }); // logoutClicked(); console.log("Redirect to "+location.href); window.location.href = this.logOutUrl + StringUtils.URIEncode(location.href); } this.loggedIn = false; this.isAuthorized = false; this.user = new User(); } logIn(){ console.log("LOgin is clicked " + this.logInUrl); Session.setCurrentUrl(location.pathname); Session.setCurrentParameters(location.search); window.location.href = this.logInUrl } onClick(id: string) { var el: HTMLElement = document.getElementById(id); el.classList.remove('uk-open'); } }