Project

General

Profile

1 56300 argiro.kok
import {Component, Input} from '@angular/core';
2 50169 argiro.kok
import {ActivatedRoute, Router} from '@angular/router';
3 57058 k.triantaf
import {Session, User} from '../login/utils/helper.class';
4 56300 argiro.kok
import {ConfigurationService} from '../utils/configuration/configuration.service';
5
import {MenuItem, RootMenuItem} from './menu';
6
import {EnvProperties} from '../utils/properties/env-properties';
7 59007 k.triantaf
import {Stakeholder} from "../monitor/entities/stakeholder";
8 59074 konstantin
import {Subscription} from "rxjs";
9 50169 argiro.kok
10
@Component({
11
  selector: 'navbar',
12
  templateUrl: 'navigationBar.component.html'
13
})
14
export class NavigationBarComponent {
15 57058 k.triantaf
  @Input() portal: string = "connect";
16
  @Input() onlyTop: boolean;
17
  @Input() logoPath: string = "assets/common-assets/";
18
  @Input() userMenu: boolean = true;
19
  @Input() showHomeMenuItem: boolean = false;
20 50586 argiro.kok
  @Input() communityId;
21 59007 k.triantaf
  @Input() stakeholder: Stakeholder;
22 57058 k.triantaf
  @Input() showCommunityName: boolean = false;
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() properties: EnvProperties;
29
  @Input() user: User;
30
  @Input() enableSearch: boolean = false;
31
  @Input() searchRoute: string = "/search/find";
32
  @Input() searchPlaceHolder: string = "Search for research results";
33 58944 k.triantaf
  @Input() showLogo: boolean = true;
34 57058 k.triantaf
  keyword: string = "";
35 50286 argiro.kok
36 58582 argiro.kok
  logosrc: string = "";
37
  logoUrl:string;
38
  logoRoute:string;
39
  logoName:string;
40 56137 argiro.kok
41 58582 argiro.kok
42 50169 argiro.kok
  public isAuthorized: boolean = false;
43 59074 konstantin
  subs: Subscription[] = [];
44
45 57058 k.triantaf
  showEntity = {};
46
  showPage = {};
47
  specialAnnouncementContent: string = null;
48 56199 argiro.kok
  activeRouteEnabled = false;
49 50169 argiro.kok
50
51 57058 k.triantaf
  constructor(private router: Router,
52
              private  route: ActivatedRoute,
53
              private config: ConfigurationService) {
54 50586 argiro.kok
  }
55 50169 argiro.kok
56
  ngOnInit() {
57 56199 argiro.kok
    this.activeRouteEnabled = false;
58 58874 konstantin
    //this.sub = this.route.queryParams.subscribe(params => {
59
      //console.log("params: ",params);
60 50169 argiro.kok
      this.initialize();
61 58874 konstantin
    //});
62 50169 argiro.kok
  }
63 57058 k.triantaf
64
  ngOnDestroy() {
65 59074 konstantin
    for (let sub of this.subs) {
66
      sub.unsubscribe();
67 58874 konstantin
    }
68 50169 argiro.kok
  }
69 57058 k.triantaf
70
  initialize() {
71 56199 argiro.kok
    this.activeRouteEnabled = false;
72 57058 k.triantaf
    this.isAuthorized = Session.isClaimsCurator(this.user) || Session.isPortalAdministrator(this.user);
73
    if (this.properties.adminToolsAPIURL && this.communityId) {
74 59074 konstantin
      //this.config.getCommunityInformation(this.properties, this.communityId).subscribe(data => {
75
      this.subs.push(this.config.communityInformationState.subscribe(data => {
76
        if(data) {
77 57058 k.triantaf
          for (var i = 0; i < data['entities'].length; i++) {
78 50169 argiro.kok
79 57058 k.triantaf
            this.showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
80
          }
81
          for (var i = 0; i < data['pages'].length; i++) {
82
            this.showPage[data['pages'][i]["route"]] = data['pages'][i]["isEnabled"];
83 50586 argiro.kok
84 57058 k.triantaf
          }
85 59074 konstantin
        }
86
      },
87
      error => {
88
        this.handleError("Error getting community information (e.g. pages,entities) for community with id: " + this.communityId, error);
89
      }));
90 50591 argiro.kok
    }
91 58582 argiro.kok
    if(!this.community){
92
      this.logosrc = this.logoPath + "logo-large-"+this.portal+".png";
93
      this.logoRoute = "/";
94
      this.logoName = "OpenAIRE";
95 50586 argiro.kok
96 58582 argiro.kok
    }else if( this.community){
97
      this.logosrc = this.community.logoUrl;
98
      if(this.homeurl){
99
        this.logoRoute = "/";
100
      }else{
101
        this.logoUrl = 'https://'+(this.properties.environment =='beta'?'beta.':'')+this.community.id+'.openaire.eu';
102
      }
103
      this.logoName = this.community.name;
104
    }
105
106 50169 argiro.kok
  }
107 57058 k.triantaf
108 50169 argiro.kok
  onClick(id: string) {
109 57058 k.triantaf
    var el: HTMLElement = document.getElementById(id);
110
    el.classList.remove('uk-open');
111 54206 argiro.kok
  }
112 50169 argiro.kok
113 57058 k.triantaf
  isEnabled(required, enabled) {
114
    if (!required) {
115
      return true;
116
    }
117 50586 argiro.kok
118 57058 k.triantaf
119
    for (let requiredEntity of required) {
120
      if (typeof enabled[requiredEntity] === "undefined" || enabled[requiredEntity] == false) {
121
        return false;
122 50586 argiro.kok
      }
123 57058 k.triantaf
    }
124
    return true;
125
  }
126
127
  isAtleastOneEnabled(required, enabled) {
128
    if (!required || required.length == 0) {
129 50586 argiro.kok
      return true;
130
    }
131
132 57058 k.triantaf
    var count = required.length;
133
    for (let requiredEntity of required) {
134
      if (typeof enabled[requiredEntity] === "undefined" || enabled[requiredEntity] == false) {
135
        count--;
136 54206 argiro.kok
      }
137
    }
138 57058 k.triantaf
    return (count > 0) ? true : false;
139
  }
140 54848 konstantin
141 57058 k.triantaf
  private handleError(message: string, error) {
142
    console.error("NavigationBar (component): " + message, error);
143
  }
144
145
  getCurrentRoute() {
146 56137 argiro.kok
    return this.router.url.split('?')[0];
147 57058 k.triantaf
  }
148
149
  isTheActiveMenu(menu: RootMenuItem): boolean {
150
    let currentRoute = this.getCurrentRoute();
151
    if (!menu.rootItem.markAsActive) {
152
      return false;
153 56137 argiro.kok
    }
154 57058 k.triantaf
    if (currentRoute == menu.rootItem.route) {
155
      this.activeRouteEnabled = true;
156
      return true;
157
    } else if (menu.items.length > 0) {
158
      for (let menuItem of menu.items) {
159
        if (menuItem.route == currentRoute) {
160
          this.activeRouteEnabled = true;
161
          return true;
162 56199 argiro.kok
        }
163
      }
164
    }
165 57058 k.triantaf
    return false;
166
  }
167 50169 argiro.kok
}