Project

General

Profile

1
import {Component} from '@angular/core';
2
import {ActivatedRoute, NavigationEnd, NavigationStart, Params, Router} from '@angular/router';
3

    
4
import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
5
import {MenuItem, RootMenuItem} from './openaireLibrary/sharedComponents/menu';
6
import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
7
import {Session, User} from './openaireLibrary/login/utils/helper.class';
8
import {HelperFunctions} from "./openaireLibrary/utils/HelperFunctions.class";
9
import {UserManagementService} from "./openaireLibrary/services/user-management.service";
10
import {properties} from "../environments/environment";
11
import {BehaviorSubject, Subscriber} from "rxjs";
12
import {StakeholderService} from "./openaireLibrary/monitor/services/stakeholder.service";
13
import {Header} from "./openaireLibrary/sharedComponents/navigationBar.component";
14
import {SmoothScroll} from "./openaireLibrary/utils/smooth-scroll";
15

    
16
@Component({
17
  selector: 'app-root',
18
  template: `
19
    <div class="monitorApp">
20
      <navbar *ngIf="properties && showMenu && header" portal="monitor" [header]="header" [onlyTop]="false"
21
              [userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user"
22
              [showMenu]=showMenu [properties]="properties"></navbar>
23
      <schema2jsonld *ngIf="properties " [URL]="properties.domain + properties.baseLink"
24
                     [logoURL]="properties.domain + properties.baseLink+'/assets/common-assets/logo-small-monitor.png'"
25
                     type="home" 
26
                     description="OpenAIRE - Monitor, A new era of monitoring research. Open data. Open methodologies. Work together with us to view, understand and visualize research statistics and indicators. "
27
                     name="OpenAIRE Monitor" [searchAction]="true" [searchActionRoute]="properties.domain + properties.baseLink + '/browse'">
28
      </schema2jsonld>
29
      <div class="custom-main-content">
30
        <main>
31
          <router-outlet></router-outlet>
32
        </main>
33
      </div>
34
      <cookie-law position="bottom">
35
        OpenAIRE uses cookies in order to function properly.<br>
36
        Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing
37
        experience possible.
38
        By using the OpenAIRE portal you accept our use of cookies. <a
39
          href="//ec.europa.eu/ipg/basics/legal/cookies/index_en.htm" target="_blank"> Read more <span class="uk-icon">
40
            <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right"
41
                 ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03"
42
                                     points="7 4 13 10 7 16"></polyline></svg>
43
            </span></a>
44
      </cookie-law>
45
      <bottom *ngIf="properties && showMenu" [grantAdvance]="false"
46
              [properties]="properties"></bottom>
47
    </div>
48
  `
49
  
50
})
51
export class AppComponent {
52
  userMenuItems: MenuItem[] = [];
53
  menuItems: RootMenuItem [] = [];
54
  bottomMenuItems: MenuItem[] = [];
55
  properties: EnvProperties = properties;
56
  showMenu: boolean = false;
57
  user: User;
58
  params: BehaviorSubject<Params> = new BehaviorSubject<Params>(null);
59
  url: string;
60
  header: Header;
61
  logoPath: string = 'assets/common-assets/';
62
  private subscriptions: any[] = [];
63
  
64
  constructor(private  route: ActivatedRoute, private propertiesService: EnvironmentSpecificService,
65
              private router: Router, private stakeholderService: StakeholderService, private smoothScroll: SmoothScroll,
66
              private userManagementService: UserManagementService) {
67
    this.subscriptions.push(router.events.forEach((event) => {
68
      if (event instanceof NavigationStart) {
69
        HelperFunctions.scroll();
70
      } else if (event instanceof NavigationEnd) {
71
        this.url = event.url;
72
        let r = this.route;
73
        while (r.firstChild) {
74
          r = r.firstChild;
75
        }
76
        let params = r.snapshot.params;
77
        this.params.next(params);
78
      }
79
    }));
80
  }
81
  
82
  ngOnInit() {
83
    this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
84
      this.user = user;
85
      this.setUserMenu();
86
      this.header = {
87
        route: "/",
88
        url: null,
89
        title: 'monitor',
90
        logoUrl: this.logoPath + 'logo-large-monitor.png',
91
        logoSmallUrl:this.logoPath + 'logo-small-monitor.png',
92
        position:'left',
93
        badge:true
94
      };
95
      this.buildMenu();
96
    }));
97
  }
98
  
99
  public ngOnDestroy() {
100
    this.subscriptions.forEach(value => {
101
      if (value instanceof Subscriber) {
102
        value.unsubscribe();
103
      }
104
    });
105
    this.userManagementService.clearSubscriptions();
106
    this.stakeholderService.clearSubscriptions();
107
    this.smoothScroll.clearSubscriptions();
108
  }
109
  
110
  public buildMenu() {
111
    this.menuItems = [];
112
    this.menuItems.push({
113
      rootItem: new MenuItem("about", "About", "", "/about/learn-how", false, [], null, {}),
114
      items: []
115
    });
116
    this.menuItems.push({
117
      rootItem: new MenuItem("stakeholders", "Browse", "", "browse", false, [], null, {}),
118
      items: []
119
    });
120
    this.menuItems.push({
121
      rootItem: new MenuItem("contact-us", "Contact us", "", "/contact-us", false, [], null, {}),
122
      items: []
123
    });
124
    this.bottomMenuItems = [
125
      new MenuItem("", "About", "https://beta.openaire.eu/project-factsheets", "", false, [], [], {}),
126
      new MenuItem("", "News - Events", "https://beta.openaire.eu/news-events", "", false, [], [], {}),
127
      new MenuItem("", "Blog", "https://blogs.openaire.eu/", "", false, [], [], {}),
128
      new MenuItem("", "Contact us", "https://beta.openaire.eu/contact-us", "", false, [], [], {})
129
    ];
130
    this.showMenu = true;
131
  }
132
  
133
  public setUserMenu() {
134
    this.userMenuItems = [];
135
    if (this.user) {
136
      if (Session.isPortalAdministrator(this.user) || Session.isMonitorCurator(this.user) || Session.isKindOfMonitorManager(this.user)) {
137
        this.userMenuItems.push(new MenuItem("", "Manage profiles",
138
          this.properties.domain + properties.baseLink + "/dashboard/admin", "", false, [], [], {}))
139
      }
140
      this.userMenuItems.push(new MenuItem("", "User information", "", "/user-info", false, [], [], {}));
141
    }
142
  }
143
}
(2-2/4)