Project

General

Profile

1
import {Component} from '@angular/core';
2
import {ActivatedRoute, NavigationStart, 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

    
8
import {Session, User} from './openaireLibrary/login/utils/helper.class';
9
import {HelperFunctions} from "./openaireLibrary/utils/HelperFunctions.class";
10
import {UserManagementService} from "./openaireLibrary/services/user-management.service";
11
import {ConfigurationService} from "./openaireLibrary/utils/configuration/configuration.service";
12
import {Header} from "./openaireLibrary/sharedComponents/navigationBar.component";
13
import {Subscriber} from "rxjs";
14
import {Meta} from "@angular/platform-browser";
15
import {properties} from "../environments/environment";
16
import {SmoothScroll} from "./openaireLibrary/utils/smooth-scroll";
17
import {SEOService} from "./openaireLibrary/sharedComponents/SEO/SEO.service";
18

    
19
@Component({
20
  //changeDetection: ChangeDetectionStrategy.Default,
21
  //encapsulation: ViewEncapsulation.Emulated,
22
  selector: 'app-root',
23
  template: `
24
    <navbar *ngIf="properties && header" [header]="header" [portal]="properties.dashboard" [properties]=properties
25
            [onlyTop]=false [user]="user"
26
            [communityId]="properties.adminToolsCommunity" [userMenuItems]=userMenuItems [menuItems]=menuItems></navbar>
27
    <schema2jsonld *ngIf="properties" [URL]="properties.domain+properties.baseLink"
28
                   [logoURL]="properties.domain+properties.baseLink+'/assets/common-assets/logo-small-explore.png'"
29
                   type="home"
30
                   name="OpenAIRE | Find and Share research"
31
                   description="OpenAIRE Explore: Over 100M of research deduplicated, 170K research software, 11M research data. One of the largest open scholarly records collection worldwide."></schema2jsonld>
32
    <div class="custom-main-content">
33
      <main>
34
        <router-outlet></router-outlet>
35
      </main>
36
    </div>
37
    <cookie-law *ngIf="isClient" position="bottom">
38
      <span class="uk-visible@m">OpenAIRE uses cookies in order to function properly.<br>
39
      Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing
40
        experience possible.</span>
41
      By using the OpenAIRE portal you accept our use of cookies. <a
42
        href="//ec.europa.eu/ipg/basics/legal/cookies/index_en.htm" target="_blank"> Read more <span class="uk-icon">
43
              <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right"
44
                   ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03" points="7 4 13 10 7 16"></polyline></svg>
45
              </span></a>
46
    </cookie-law>
47
    <bottom *ngIf="isClient && properties" [properties]="properties"></bottom>
48
  `
49
})
50
export class AppComponent {
51
  isClient: boolean = false;
52
  userMenuItems: MenuItem[] = [];
53
  menuItems: RootMenuItem [] = [];
54
  feedbackmail: string;
55
  properties: EnvProperties = properties;
56
  user: User;
57
  header: Header;
58
  logoPath: string = 'assets/common-assets/';
59
  subscriptions = [];
60
  
61
  constructor(private  route: ActivatedRoute, private propertiesService: EnvironmentSpecificService,
62
              private router: Router, private userManagementService: UserManagementService, private smoothScroll: SmoothScroll,
63
              private configurationService: ConfigurationService, private _meta: Meta, private seoService: SEOService,) {
64
    this.userMenuItems.push(new MenuItem("", "My profile", "", "", false, [], [], {}));
65
    this.userMenuItems.push(new MenuItem("", "My ORCID links", "", "/my-orcid-links", false, [], [""], {}));
66
    this.userMenuItems.push(new MenuItem("", "My links", "", "/myclaims", false, [], ["/myclaims"], {}));
67
    
68
    this.subscriptions.push(router.events.forEach((event) => {
69
      if (event instanceof NavigationStart) {
70
        HelperFunctions.scroll();
71
      }
72
    }));
73
  }
74
  
75
  ngOnInit() {
76
    if (typeof document !== 'undefined') {
77
      this.isClient = true;
78
    }
79
    this.configurationService.initCommunityInformation(this.properties, this.properties.adminToolsCommunity);
80
    this.feedbackmail = this.properties.feedbackmail;
81
    if (this.properties.environment == "production" || this.properties.environment == "development") {
82
      this.subscriptions.push(this.route.queryParams.subscribe(data => {
83
        this._meta.updateTag({content: 'all', name: 'robots'});
84
        this.seoService.removeLinkForPrevURL();
85
        this.seoService.removeLinkForNextURL();
86
      }));
87
    }
88
    this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
89
      this.user = user;
90
      this.buildMenu();
91
      this.header = {
92
        route: "/",
93
        url: null,
94
        title: 'explore',
95
        logoUrl: this.logoPath + 'logo-large-explore.png',
96
        logoSmallUrl: this.logoPath + 'logo-small-explore.png',
97
        position: 'left',
98
        badge: true
99
      };
100
    }));
101
  }
102
  
103
  ngOnDestroy() {
104
    this.subscriptions.forEach(subscription => {
105
      if (subscription instanceof Subscriber) {
106
        subscription.unsubscribe();
107
      }
108
    });
109
    this.configurationService.clearSubscriptions();
110
    this.userManagementService.clearSubscriptions();
111
    this.smoothScroll.clearSubscriptions();
112
  }
113
  
114
  buildMenu() {
115
    //TODO add check for research results route
116
    this.menuItems = [
117
      {
118
        rootItem: new MenuItem("search", "Search", "", "/search/find", false, [], ["/search/find"], {qf: true}),
119
        items: [
120
          new MenuItem("", "Research Outcomes", "", "/search/find/research-outcomes", false, [], ["/search/find/research-outcomes"], {resultbestaccessright: '"' + encodeURIComponent("Open Access") + '"'}),
121
          new MenuItem("", "Projects", "", "/search/find/projects/", false, ["project"], ["/search/find/projects"], {}),
122
          new MenuItem("", "Content Providers", "", "/search/find/dataproviders", false, ["datasource"], ["/search/find/dataproviders"], {}),
123
          new MenuItem("", "Organizations", "", "/search/find/organizations/", false, ["organization"], ["/search/find/organizations"], {})
124
        ]
125
      },
126
      {
127
        rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], {}),
128
        //rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], {}),
129
        items: []
130
        //rootItem: new MenuItem("share", "Share", "", "", false, [], ["/participate/deposit-publications", "/participate/deposit-datasets"], {}),
131
        //items: [new MenuItem("", "Publications", "", "/participate/deposit-publications", false, ["publication"], ["/participate/deposit-publications"], {}),
132
        //  new MenuItem("", "Research Data", "", "/participate/deposit-datasets", false, ["dataset"], ["/participate/deposit-datasets"], {})]
133
      },
134
      {
135
        rootItem: new MenuItem("link", "Link", "", "/participate/claim", false, [], ["/participate/claim"], {}),
136
        items: [new MenuItem("", "Start linking", "", "/participate/claim", false, [], ["/participate/claim"], {}),
137
          new MenuItem("", "Learn more", this.properties.claimsInformationLink, "", false, [], [], {})]
138
      },
139
      {
140
        rootItem: new MenuItem("datasources", "Content Providers", "", "", false, ["datasource"], [], {}),
141
        items: [new MenuItem("", "Data Policies", "https://beta.openaire.eu/oa-policies-mandates", "", false, ["datasource"], [""], {}),
142
          new MenuItem("", "Repositories", "", "/search/content-providers", false, ["datasource"], ["/search/content-providers"], {}),
143
          new MenuItem("", "Journals", "", "/search/journals", false, ["datasource"], ["/search/journals"], {}),
144
          new MenuItem("", "Registries", "", "/search/entity-registries", false, ["datasource"], ["/search/entity-registries"], {}),
145
          new MenuItem("", "Browse all", "", "/search/find/dataproviders", false, ["datasource"], ["/search/find/dataproviders"], {})]
146
      }
147
    ];
148
    if (Session.isPortalAdministrator(this.user)) {
149
      this.userMenuItems.push(new MenuItem("", "Manage all links", "", "/claims", false, [], ["/claims"], {}));
150
      this.userMenuItems.push(new MenuItem("", "Manage helptexts", this.properties.adminPortalURL + "/openaire/admin-tools/pages", "", true, [], [], {}));
151
    } else if (Session.isClaimsCurator(this.user)) {
152
      this.userMenuItems.push(new MenuItem("", "Manage all links", "", "/claims", false, [], ["/claims"], {}));
153
      
154
    }
155
    if (this.user) {
156
      this.userMenuItems.push(new MenuItem("", "User information", "", "/user-info", false, [], [], {}));
157
    }
158
  }
159
}
160

    
(2-2/4)