Project

General

Profile

1
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
import{EnvProperties} from '../utils/properties/env-properties';
10

    
11
// declare var logoutClicked;
12
@Component({
13
    selector: 'user-mini',
14
    template: `
15
<ul *ngIf="!mobileView"  class="uk-navbar-nav">
16
   <li class="uk-parent">
17

    
18
      <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
      <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
      </a>
23

    
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
             <!--li><a href="" >My profile</a></li>
30
             <li><a   routerLinkActive="uk-link" routerLink="/myclaims">My Claims</a></li>
31
             <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
                <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
              </li>
37
             </ng-container>
38
              <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
        <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
        </a>
54
   </span>
55

    
56
  <ul *ngIf="loggedIn" class="uk-nav-sub">
57
  <!--li><a href="" >My profile</a></li>
58
  <li><a   routerLinkActive="uk-link" routerLink="/myclaims">My Claims</a></li>
59
  <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
     <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
   </li>
65
  </ng-container>
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
    public redirectUrl: string = "";
85
    private baseUrl = "user-info";
86
    sub:any;
87
    // public properties:EnvProperties;
88

    
89
    constructor( private router: Router, private  route: ActivatedRoute, private location: Location) {}
90

    
91
    ngOnInit() {
92

    
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
    }
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
          if(Session.isClaimsCurator() || Session.isPortalAdministrator()){
112
           this.isAuthorized = true;
113
           }else {
114
                 this.isAuthorized = false;
115
           }
116
      
117
      }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
        console.log("Try to Logout!");
136
        // console.log("Redirect to "+location.href);
137
        window.location.href = this.logOutUrl + StringUtils.URIEncode(location.href);
138

    
139
      }
140
      this.loggedIn = false;
141
       this.isAuthorized = false;
142
      this.user = new User();
143
    }
144

    
145
    logIn(){
146
      // console.log("LOgin is clicked " + this.logInUrl);
147
      Session.setReloadUrl(location.protocol +"//"+location.host, location.pathname, location.search);
148
      window.location.href = this.logInUrl
149
    }
150

    
151
    onClick(id: string) {
152
          var el: HTMLElement = document.getElementById(id);
153
          el.classList.remove('uk-open');
154
      }
155

    
156
}
(9-9/9)