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