Project

General

Profile

1 58903 k.triantaf
import {Component, OnInit} from '@angular/core';
2
import {MenuItem, RootMenuItem, SideMenuItem} from './openaireLibrary/sharedComponents/menu';
3 58921 k.triantaf
import {ActivatedRoute, NavigationStart, Router} from '@angular/router';
4 58903 k.triantaf
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 58942 k.triantaf
import {BehaviorSubject} from "rxjs";
9 58903 k.triantaf
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 58942 k.triantaf
  isHome: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(true);
27 58903 k.triantaf
28
  constructor(private route: ActivatedRoute,
29 58942 k.triantaf
              private router: Router) {
30 58921 k.triantaf
    this.router.events.subscribe(event => {
31 58942 k.triantaf
      if (event instanceof NavigationStart) {
32 58945 k.triantaf
        let path = event.url.split('?')[0];
33
        this.isHome.next(path === '/');
34 58921 k.triantaf
      }
35
    })
36 58903 k.triantaf
  }
37
38
  ngOnInit() {
39
    this.logInUrl = this.properties.loginUrl;
40
    this.logOutUrl = this.properties.logoutUrl;
41
    this.showMenu = true;
42 58942 k.triantaf
    this.isHome.asObservable().subscribe(isHome => {
43
      this.buildMenu(isHome);
44 58903 k.triantaf
    });
45
  }
46 58942 k.triantaf
47
  buildMenu(isHome) {
48
    if(!isHome) {
49
      this.menuItems = [
50
        {
51 58945 k.triantaf
          rootItem: new MenuItem("home", "Home", "", "/", false, [], null, {}),
52 58942 k.triantaf
          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 58903 k.triantaf
}