Project

General

Profile

1
import { Component, Input } from '@angular/core';
2
// import 'rxjs/Rx';
3
import {ActivatedRoute, Router} from '@angular/router';
4
import {Observable}       from 'rxjs';
5

    
6
import {Session} from '../login/utils/helper.class';
7
import { ConfigurationService } from '../utils/configuration/configuration.service';
8
import{MenuItem,RootMenuItem} from './menu';
9
@Component({
10
  selector: 'navbar',
11
  templateUrl: 'navigationBar.component.html'
12
})
13
export class NavigationBarComponent {
14
  @Input() portal:string = "connect";
15
  @Input() onlyTop:boolean ;
16
  @Input() logoPath:string = "assets/common-assets/";
17
  @Input() userMenu:boolean = true;
18
  @Input() logInUrl;
19
  @Input() logOutUrl;
20
  @Input() APIUrl;
21
  @Input() communityId;
22
  @Input() cookieDomain;
23
  @Input() userMenuItems:MenuItem[]  ;
24
  @Input() menuItems:RootMenuItem [] ;
25
  @Input() community: {id:string, name:string, logoUrl:string};
26
  @Input() showMenu:boolean = true;
27
  @Input() homeurl:boolean = true;
28
  @Input() environment:string = "beta";
29

    
30
  public isAuthorized: boolean = false;
31
  sub:any;
32
  isClient:boolean = false;
33
  showEntity ={};
34
  showPage ={};
35
  specialAnnouncementContent:string= null;
36

    
37

    
38
  constructor( private router: Router, private  route: ActivatedRoute, private config: ConfigurationService) {
39
  }
40

    
41
  ngOnInit() {
42
    //console.log(this.menuItems);
43
    if (typeof document !== 'undefined') {
44
      try{
45
        this.isClient = true;
46
      }catch (e) {
47
      }
48
    }
49
    this.sub =  this.route.queryParams.subscribe(params => {
50
      this.initialize();
51
    });
52

    
53
  }
54
  ngOnDestroy(){
55
    this.sub.unsubscribe();
56
  }
57
  initialize(){
58
     if(Session.isLoggedIn() && (Session.isClaimsCurator() || Session.isPortalAdministrator())){
59
      this.isAuthorized = true;
60
    }else {
61
          this.isAuthorized = false;
62
    }
63

    
64
if( this.APIUrl && this.communityId ){
65
    this.config.getCommunityInformation(this.APIUrl, this.communityId ).subscribe(data => {
66
        for(var i=0; i< data['entities'].length; i++){
67

    
68
          this.showEntity[""+data['entities'][i]["pid"]+""] = data['entities'][i]["isEnabled"];
69
        }
70
        for(var i=0; i< data['pages'].length; i++){
71
          this.showPage[data['pages'][i]["route"]] = data['pages'][i]["isEnabled"];
72

    
73
        }
74

    
75
      },
76
      error => {
77
        this.handleError("Error getting community information (e.g. pages,entities) for community with id: "+this.communityId, error);
78
      });
79
    }
80

    
81
  }
82
  onClick(id: string) {
83
        var el: HTMLElement = document.getElementById(id);
84
        el.classList.remove('uk-open');
85
  }
86
  isEnabled(required, enabled){
87
      if(!required ){
88
        return true;
89
      }
90

    
91

    
92
      for(let requiredEntity of required){
93
          if(typeof enabled[requiredEntity] === "undefined" || enabled[requiredEntity] == false){
94
            return false;
95
          }
96
      }
97
      return true;
98
    }
99
    isAtleastOneEnabled(required, enabled){
100
      if(!required ||required.length == 0){
101
        return true;
102
      }
103

    
104
      var count = required.length;
105
      for(let requiredEntity of required){
106
          if(typeof enabled[requiredEntity] === "undefined" || enabled[requiredEntity] == false){
107
            count --;
108
          }
109
      }
110
      return (count > 0)?true:false;
111
    }
112

    
113
    private handleError(message: string, error) {
114
        console.error("NavigationBar (component): "+message, error);
115
    }
116
}
(8-8/9)