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

    
12
@Component({
13
  //changeDetection: ChangeDetectionStrategy.Default,
14
  //encapsulation: ViewEncapsulation.Emulated,
15
  selector: 'app-root',
16
  styles: [`
17
  `],
18
  template: `
19

    
20
    <navbar *ngIf="properties" [portal]="properties.dashboard" [properties]=properties [onlyTop]=false [user]="user"
21
            [communityId]="properties.adminToolsCommunity" [userMenuItems]=userMenuItems [menuItems]=menuItems></navbar>
22
    <div class="custom-main-content">
23
      <main>
24
        <router-outlet></router-outlet>
25
      </main>
26
    </div>
27
    <cookie-law *ngIf="isClient" position="bottom">
28
      OpenAIRE uses cookies in order to function properly.<br>
29
      Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing
30
      experience possible.
31
      By using the OpenAIRE portal you accept our use of cookies. <a
32
      href="//ec.europa.eu/ipg/basics/legal/cookies/index_en.htm" target="_blank"> Read more <span class="uk-icon">
33
              <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right"
34
                   ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03" points="7 4 13 10 7 16"></polyline></svg>
35
              </span></a>
36
    </cookie-law>
37
    <bottom *ngIf="isClient && properties" [properties]="properties"></bottom>
38

    
39
  `
40

    
41
})
42
export class AppComponent {
43
  isClient: boolean = false;
44
  clientLoad = 0;
45

    
46
  userMenuItems: MenuItem[] = [new MenuItem("", "My profile", "", "", false, [], [], {}),
47
    new MenuItem("", "My links", "", "/myclaims", false, [], ["/myclaims"], {})]
48

    
49

    
50
  menuItems: RootMenuItem [] = [];
51

    
52
  feedbackmail: string;
53
  properties: EnvProperties;
54
  user: User;
55

    
56
  constructor(private  route: ActivatedRoute, private propertiesService: EnvironmentSpecificService,
57
              private router: Router, private userManagementService: UserManagementService) {
58
    router.events.forEach((event) => {
59
      if (event instanceof NavigationStart) {
60
        console.log(event.url);
61
        HelperFunctions.scroll();
62
      }
63
    });
64
  }
65

    
66
  ngOnInit() {
67

    
68
    if (typeof document !== 'undefined') {
69
      try {
70
        this.isClient = true;
71

    
72
      } catch (e) {
73
      }
74

    
75
    }
76
    this.propertiesService.loadEnvironment()
77
      .then(es => {
78
        this.propertiesService.setEnvProperties(es);
79
        this.properties = this.propertiesService.envSpecific;
80
        this.feedbackmail = this.properties.feedbackmail;
81
        this.userManagementService.getUserInfo().subscribe(user => {
82
          this.user = user;
83
          this.buildMenu();
84
        });
85
        //console.log(this.properties.loginUrl);
86
      }, error => {
87
        console.log("App couldn't fetch properties");
88
        console.log(error);
89

    
90
      });
91
  }
92

    
93
  buildMenu() {
94
     //TODO add check for research results route
95
    this.menuItems = [
96
      {
97
        rootItem: new MenuItem("search", "Search", "", "/search/find", false, [], ["/search/find"], {}),
98
        items: [
99
          new MenuItem("", "Research Outcomes", "", "/search/find/research-outcomes", false, [], ["/search/find/research-outcomes"], {}),
100
          new MenuItem("", "Projects", "", "/search/find/projects/", false, ["project"], ["/search/find/projects"], {}),
101
          new MenuItem("", "Content Providers", "", "/search/find/dataproviders", false, ["datasource"], ["/search/find/dataproviders"], {}),
102
          new MenuItem("", "Organizations", "", "/search/find/organizations/", false, ["organization"], ["/search/find/organizations"], {})
103
        ]
104
      },
105
      {
106
        rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], {}),
107
        //rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], {}),
108
        items: []
109
        //rootItem: new MenuItem("share", "Share", "", "", false, [], ["/participate/deposit-publications", "/participate/deposit-datasets"], {}),
110
        //items: [new MenuItem("", "Publications", "", "/participate/deposit-publications", false, ["publication"], ["/participate/deposit-publications"], {}),
111
        //  new MenuItem("", "Research Data", "", "/participate/deposit-datasets", false, ["dataset"], ["/participate/deposit-datasets"], {})]
112
      },
113
      {
114
        rootItem: new MenuItem("link", "Link", "", "/participate/claim", false, [], ["/participate/claim"], {}),
115
        items: [new MenuItem("", "Start linking", "", "/participate/claim", false, [], ["/participate/claim"], {}),
116
          new MenuItem("", "Learn more", this.properties.claimsInformationLink, "", false, [], [], {})]
117
      },
118
      {
119
        rootItem: new MenuItem("datasources", "Content Providers", "", "", false, ["datasource"], [], {}),
120
        items: [new MenuItem("", "Data Policies", "https://beta.openaire.eu/oa-policies-mandates", "", false, ["datasource"], [""], {}),
121
          new MenuItem("", "Repositories", "", "/search/content-providers", false, ["datasource"], ["/search/content-providers"], {}),
122
          new MenuItem("", "Journals", "", "/search/journals", false, ["datasource"], ["/search/journals"], {}),
123
          new MenuItem("", "Registries", "", "/search/entity-registries", false, ["datasource"], ["/search/entity-registries"], {}),
124
          new MenuItem("", "Browse all", "", "/search/find/dataproviders", false, ["datasource"], ["/search/find/dataproviders"], {})]
125
      }
126
    ];
127
    if (Session.isPortalAdministrator(this.user)) {
128
      this.userMenuItems.push(new MenuItem("", "Manage all links", "", "/claims", false, [], ["/claims"], {}));
129
      this.userMenuItems.push(new MenuItem("", "Manage helptexts",
130
        ((this.properties.environment == "beta") ? "https://beta.admin.connect.openaire.eu" : "https://admin.explore.openaire.eu") + "/dashboard?communityId=openaire", "", true, [], [], {}))
131

    
132
    } else if (Session.isClaimsCurator(this.user)) {
133
      this.userMenuItems.push(new MenuItem("", "Manage all links", "", "/claims", false, [], ["/claims"], {}));
134

    
135
    }
136
    if(this.user) {
137
      this.userMenuItems.push(new MenuItem("", "User information", "", "/user-info", false, [], [], {}));
138
    }
139
  }
140
}
141

    
(2-2/4)