Project

General

Profile

1
import {Component, ElementRef, Input} from '@angular/core';
2
import {ActivatedRoute, Router} from '@angular/router';
3
import {Location} from '@angular/common';
4
import {User,Session} from './utils/helper.class';
5
import {RouterHelper} from '../utils/routerHelper.class';
6
import {StringUtils} from '../utils/string-utils.class';
7
import{EnvProperties} from '../utils/properties/env-properties';
8

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

    
16
      <a   *ngIf="loggedIn" >
17
             <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>
18
      </a>
19
      <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>
20
      </a>
21

    
22

    
23
  <div *ngIf="loggedIn" class="uk-navbar-dropdown uk-navbar-dropdown-bottom-left"   id="userMenu" (click)="onClick('userMenu')"  >
24
     <div class="uk-navbar-dropdown-grid uk-child-width-1-1 uk-grid uk-grid-stack" uk-grid="">
25
        <div class="uk-first-column">
26
           <ul class="uk-nav uk-navbar-dropdown-nav">
27
             <!--li><a href="" >My profile</a></li>
28
             <li><a   routerLinkActive="uk-link" routerLink="/myclaims">My Claims</a></li>
29
             <li *ngIf="isAuthorized"><a   routerLinkActive="uk-link" routerLink="/claims">Manage all Claims</a></li-->
30
             <ng-container *ngFor="let item of userMenuItems ">
31
              <li *ngIf="item.needsAuthorization && isAuthorized || !item.needsAuthorization">
32
                <a *ngIf="item.route.length > 0" routerLink="{{item.route}}" [queryParams]=item.params >{{item.title}}</a>
33
                <a *ngIf="item.route.length == 0 && item.url.length > 0" href="{{item.url}}" target="_blank"  >{{item.title}}</a>
34
              </li>
35
             </ng-container>
36
             <li *ngIf="userMenuItems.length > 0" class="uk-nav-divider"></li>
37
              <li><a (click)="logOut()" id="logout" >Log out</a></li>
38
           </ul>
39
        </div>
40
        <div id="logout1"></div>
41
     </div>
42
  </div>   </li>
43
  </ul>
44

    
45
<li *ngIf="mobileView" class="uk-nav-header uk-parent " >
46

    
47
    <span  *ngIf="loggedIn" >
48
      <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>
49
    </span>
50
    <span  *ngIf="!loggedIn">
51
        <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>
52
        </a>
53
   </span>
54

    
55
  <ul *ngIf="loggedIn" class="uk-nav-sub">
56
  <!--li><a href="" >My profile</a></li>
57
  <li><a   routerLinkActive="uk-link" routerLink="/myclaims">My Claims</a></li>
58
  <li *ngIf="isAuthorized"><a   routerLinkActive="uk-link" routerLink="/claims">Manage all Claims</a></li-->
59
  <ng-container *ngFor="let item of userMenuItems ">
60
   <li *ngIf="item.needsAuthorization && isAuthorized || !item.needsAuthorization">
61
     <a *ngIf="item.route.length > 0"   routerLink="{{item.route}}"  >{{item.title}}</a>
62
     <a *ngIf="item.route.length == 0 && item.url.length > 0"  href="{{item.url}}" >{{item.title}}</a>
63
   </li>
64
  </ng-container>
65
  <li *ngIf="userMenuItems.length > 0" class="uk-nav-divider"></li>
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
    sub:any;
86

    
87
    constructor( private router: Router, private  route: ActivatedRoute, private location: Location) {}
88

    
89
    ngOnInit() {
90

    
91
           if( typeof document !== 'undefined') {
92
             this.server = false;
93
           }
94
           this.initialize();
95
           this.sub =  this.route.queryParams.subscribe(params => {
96
             this.initialize();
97
           });
98

    
99

    
100
    }
101
    ngOnDestroy(){
102
      this.sub.unsubscribe();
103
    }
104

    
105
    initialize(){
106
      this.redirectUrl = this.location.path();
107
      if(Session.isLoggedIn()){
108
          this.loggedIn = true;
109
          this.user = Session.getUser();
110
          if(Session.isClaimsCurator() || Session.isPortalAdministrator()){
111
            this.isAuthorized = true;
112
           } else {
113
            this.isAuthorized = false;
114
           }
115

    
116
      }else {
117
        this.loggedIn = false;
118
        this.isAuthorized = false;
119
        this.user = null;
120
      }
121

    
122
    }
123

    
124
    logOut(){
125
      if(Session.isLoggedIn()){
126
        Session.removeUser();
127
        window.location.href = this.logOutUrl + StringUtils.URIEncode(location.href);
128

    
129
      }
130
      this.loggedIn = false;
131
      this.isAuthorized = false;
132
      this.user = new User();
133
    }
134

    
135
    logIn(){
136
      Session.setReloadUrl(location.protocol +"//"+location.host, location.pathname, location.search);
137
      window.location.href = this.logInUrl
138
    }
139

    
140
    onClick(id: string) {
141
          let el: HTMLElement = document.getElementById(id);
142
          el.classList.remove('uk-open');
143
      }
144

    
145
}
(9-9/9)