Project

General

Profile

1 60133 argiro.kok
import {Component, Inject, RendererFactory2, ViewEncapsulation} from '@angular/core';
2 55689 argiro.kok
import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
3
import {MenuItem, RootMenuItem} from './openaireLibrary/sharedComponents/menu';
4 60133 argiro.kok
import {AggregatorInfo, PortalAggregators} from "./utils/aggregators";
5 57127 argiro.kok
import {UserManagementService} from "./openaireLibrary/services/user-management.service";
6
import {User} from "./openaireLibrary/login/utils/helper.class";
7 59900 argiro.kok
import {Header} from "./openaireLibrary/sharedComponents/navigationBar.component";
8
import {portalProperties} from "../environments/environment-aggregator";
9 59936 k.triantaf
import {properties} from "../environments/environment";
10
import {ConnectHelper} from "./openaireLibrary/connect/connectHelper";
11 59969 argiro.kok
import {ConfigurationService} from "./openaireLibrary/utils/configuration/configuration.service";
12
import {Subscriber} from "rxjs";
13 60133 argiro.kok
import {DOCUMENT} from "@angular/common";
14 55689 argiro.kok
15
@Component({
16
  selector: 'app-root',
17
  template: `
18 59936 k.triantaf
    <div *ngIf="agg">
19
      <navbar *ngIf="properties && loginCheck && header" portal="aggregator" [properties]=properties [onlyTop]=false
20
              [user]="user" [userMenuItems]="userMenuItems"
21
              [communityId]="properties.adminToolsCommunity" [menuItems]=menuItems
22
              [userMenu]="true" [header]="header"></navbar>
23
      <div class="custom-main-content">
24
        <main>
25
          <router-outlet></router-outlet>
26
        </main>
27
      </div>
28
      <cookie-law *ngIf="isClient" position="bottom">
29
        OpenAIRE uses cookies in order to function properly.<br>
30
        Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing
31
        experience possible.
32
        By using the OpenAIRE portal you accept our use of cookies. <a
33
          href="//ec.europa.eu/ipg/basics/legal/cookies/index_en.htm" target="_blank"> Read more <span class="uk-icon">
34 55689 argiro.kok
              <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right"
35
                   ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03" points="7 4 13 10 7 16"></polyline></svg>
36
              </span></a>
37 59936 k.triantaf
      </cookie-law>
38
      <bottom *ngIf="isClient && properties" [properties]=properties></bottom>
39
    </div>
40 55689 argiro.kok
  `
41
})
42
export class AppComponent {
43
  isClient: boolean = false;
44 59936 k.triantaf
  menuItems: RootMenuItem [] = [];
45
  userMenuItems: MenuItem[] = [];
46 56072 argiro.kok
  community = null;
47 57403 k.triantaf
  id: string = null;
48 59936 k.triantaf
  properties: EnvProperties = properties;
49 57127 argiro.kok
  user: User;
50
  loginCheck: boolean = false;
51 59936 k.triantaf
  footer = portalProperties.sectionFooter;
52
  header: Header;
53 60133 argiro.kok
  agg: AggregatorInfo = null;
54 59969 argiro.kok
  subscriptions = [];
55 60778 k.triantaf
56
  constructor(private userManagementService: UserManagementService,  private configurationService: ConfigurationService,  @Inject(DOCUMENT) private document, private rendererFactory: RendererFactory2) {
57 59969 argiro.kok
    this.id = ConnectHelper.getCommunityFromDomain(this.properties.domain);
58
    this.agg = PortalAggregators.getFilterInfoByMenuId(this.id);
59 60133 argiro.kok
    this.setStyles();
60 59969 argiro.kok
    this.configurationService.initStaticCommunityInformation(PortalAggregators.getCommunityInfoByMenuId(this.id));
61 59936 k.triantaf
  }
62 59969 argiro.kok
  ngOnDestroy() {
63
    this.subscriptions.forEach(subscription => {
64
      if (subscription instanceof Subscriber) {
65
        subscription.unsubscribe();
66
      }
67
    });
68
    this.configurationService.clearSubscriptions();
69
    this.userManagementService.clearSubscriptions();
70
  }
71 59936 k.triantaf
  ngOnInit() {
72
    if (typeof document !== 'undefined') {
73
        this.isClient = true;
74
    }
75
    this.id = ConnectHelper.getCommunityFromDomain(this.properties.domain);
76
    this.agg = PortalAggregators.getFilterInfoByMenuId(this.id);
77
    if (this.agg) {
78
      this.header = {
79
        route: '/',
80
        url: null,
81
        title: this.agg.title,
82
        logoUrl: this.agg.logoUrl,
83
        logoSmallUrl: this.agg.logoUrl,
84
        position: 'left',
85
        badge: true
86
      };
87
      this.buildMenu();
88
    }
89 59969 argiro.kok
    this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
90 59936 k.triantaf
      this.user = user;
91
      this.loginCheck = true;
92
      this.userMenuItems = [];
93
      if (this.user) {
94 60133 argiro.kok
        this.userMenuItems.push(new MenuItem("", "My links", "", "/myclaims", false, [], [], {}));
95
        // this.userMenuItems.push(new MenuItem("", "User information", "", "/user-info", false, [], [], {}));
96 55689 argiro.kok
      }
97 59969 argiro.kok
    }));
98 55689 argiro.kok
  }
99 59936 k.triantaf
100 57403 k.triantaf
  private buildMenu() {
101
    this.menuItems = [
102 59936 k.triantaf
      {rootItem: new MenuItem("home", "Home", "", "/", false, [], null, {}), items: []},
103 57403 k.triantaf
      {
104 59969 argiro.kok
        rootItem: new MenuItem("search", "Search", "", "/search/find", false, [], ["/search/find"], {}),
105 59900 argiro.kok
        items: []
106 59936 k.triantaf
      },
107
      {
108 59969 argiro.kok
        rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], {}),
109 59936 k.triantaf
        items: []
110
      },
111
      {
112 59969 argiro.kok
        rootItem: new MenuItem("link", "Link", "", "/participate/claim", false, [], ["/participate/claim"], {}),
113
        items: [new MenuItem("", "Start linking", "", "/participate/claim", false, [], ["/participate/claim"], {}),
114 59936 k.triantaf
          new MenuItem("", "Learn more", this.properties.claimsInformationLink, "", false, [], [], {})]
115 60186 argiro.kok
      },
116
      {
117
        rootItem: new MenuItem("develop", "Develop", "", "/develop", false, [], ["/develop"], {}),
118
        items: []
119 57403 k.triantaf
      }
120
    ];
121 59936 k.triantaf
    let params = {};
122 59973 argiro.kok
    // params[this.agg.queryFieldName] = this.agg.valueId;
123
    this.menuItems[1].items.push(new MenuItem("", "Research outcomes", "", "/search/find/research-outcomes", false, [], ["/search/find/research-outcomes"], params));
124
    this.menuItems[1].items.push(new MenuItem("", "Projects", "", "/search/find/projects", false, ["project"], ["/search/find/projects"], params));
125
    this.menuItems[1].items.push(new MenuItem("", "Content Providers", "", "/search/find/dataproviders", false, ["datasource"], ["/search/find/dataproviders"], params));
126
    this.menuItems[1].items.push(new MenuItem("", "Organizations", "", "/search/find/organizations", false, ["organization"], ["/search/find/organizations"], params));
127 59969 argiro.kok
128 57403 k.triantaf
  }
129 60133 argiro.kok
  setStyles(){
130
    let css:string =':root {\n';
131
    if(this.agg.mainColor){
132
      css = css.concat('--portal-main-color: ' + this.agg.mainColor + ';\n');
133
    }
134
    if(this.agg.darkColor){
135
      css = css.concat('--portal-dark-color: ' + this.agg.darkColor + ';\n');
136
    }
137
    if(this.agg.darkColor){
138
      css = css.concat("--graph-background:  url('" + this.agg.background + "\') no-repeat bottom;\n");
139
    }
140
    css = css.concat('}');
141
142
    try {
143
      if( this.document.getElementById('customStyle')){
144
        try {
145
          this.document.getElementById('customStyle').append(css);
146
        }catch(e){
147
          console.log("error with append style")
148
        }
149
      }else {
150
        const renderer = this.rendererFactory.createRenderer(this.document, {
151
          id: '-1',
152
          encapsulation: ViewEncapsulation.None,
153
          styles: [],
154
          data: {}
155
        });
156
157
        const head = this.document.head;
158
        if (head === null) {
159
          throw new Error('<head> not found within DOCUMENT.');
160
        }
161
        const style = renderer.createElement('style');
162
        renderer.setAttribute(style, "id", "customStyle");
163
        let CSSElement = renderer.createText(css);
164
        renderer.appendChild(head, style);
165
        renderer.appendChild(style, CSSElement);
166
      }
167
    } catch (e) {
168
      console.error('Renderrer Error to append style ', e);
169
    }
170
  }
171
172 55689 argiro.kok
}