Project

General

Profile

1
import {Component, OnInit} from '@angular/core';
2
import {MenuItem, RootMenuItem, SideMenuItem} from './openaireLibrary/sharedComponents/menu';
3
import {ActivatedRoute, NavigationStart, Router} from '@angular/router';
4
import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
5
import {User} from './openaireLibrary/login/utils/helper.class';
6
import {UserManagementService} from './openaireLibrary/services/user-management.service';
7
import {properties} from "../environments/environment";
8
import {BehaviorSubject} from "rxjs";
9

    
10
declare var UIkit: any;
11

    
12
@Component({
13
  selector: 'app',
14
  templateUrl: './app.component.html',
15
})
16

    
17
export class AppComponent implements OnInit {
18
  title = 'Metadata Registry Service';
19
  userMenuItems: MenuItem[] = [];
20
  menuItems: RootMenuItem [] = [];
21
  logInUrl = null;
22
  logOutUrl = null;
23
  properties: EnvProperties = properties;
24
  showMenu: boolean = false;
25
  user: User;
26
  isHome: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(true);
27
  
28
  constructor(private route: ActivatedRoute,
29
              private router: Router) {
30
    this.router.events.subscribe(event => {
31
      if (event instanceof NavigationStart) {
32
        let path = event.url.split('?')[0];
33
        this.isHome.next(path === '/');
34
      }
35
    })
36
  }
37
  
38
  ngOnInit() {
39
    this.logInUrl = this.properties.loginUrl;
40
    this.logOutUrl = this.properties.logoutUrl;
41
    this.showMenu = true;
42
    this.isHome.asObservable().subscribe(isHome => {
43
      this.buildMenu(isHome);
44
    });
45
  }
46
  
47
  buildMenu(isHome) {
48
    if(!isHome) {
49
      this.menuItems = [
50
        {
51
          rootItem: new MenuItem("home", "Home", "", "/", false, [], null, {}),
52
          items: [
53
            new MenuItem("intro", "Usage Statistics Intro", "", "/", false, [], null, {}),
54
            new MenuItem("countries", "Track Countries Usage Activity", "", "/", false, [], null, {slide: 2}),
55
            new MenuItem("chart", "Monthly Usage Events", "", "/", false, [], null, {slide: 3})
56
          ]
57
        },
58
        {
59
          rootItem: new MenuItem("about", "About", "", "/about", false, [], null, {}),
60
          items: []
61
        },
62
        {
63
          rootItem: new MenuItem("resources", "Resources", "", "/resources", false, [], null, {}),
64
          items: []
65
        }
66
      ];
67
    } else {
68
      this.menuItems = [
69
        {
70
          rootItem: new MenuItem("about", "About", "", "/about", false, [], null, {}),
71
          items: []
72
        },
73
        {
74
          rootItem: new MenuItem("resources", "Resources", "", "/resources", false, [], null, {}),
75
          items: []
76
        }
77
      ];
78
    }
79
  }
80
}
(4-4/8)