Project

General

Profile

1
import {Component, Inject, RendererFactory2, ViewEncapsulation} from '@angular/core';
2
import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
3
import {MenuItem, RootMenuItem} from './openaireLibrary/sharedComponents/menu';
4
import {AggregatorInfo, PortalAggregators} from "./utils/aggregators";
5
import {UserManagementService} from "./openaireLibrary/services/user-management.service";
6
import {User} from "./openaireLibrary/login/utils/helper.class";
7
import {Header} from "./openaireLibrary/sharedComponents/navigationBar.component";
8
import {portalProperties} from "../environments/environment-aggregator";
9
import {properties} from "../environments/environment";
10
import {ConnectHelper} from "./openaireLibrary/connect/connectHelper";
11
import {ConfigurationService} from "./openaireLibrary/utils/configuration/configuration.service";
12
import {Subscriber} from "rxjs";
13
import {DOCUMENT} from "@angular/common";
14

    
15
@Component({
16
  selector: 'app-root',
17
  template: `
18
    <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
              <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
      </cookie-law>
38
      <bottom *ngIf="isClient && properties" [properties]=properties></bottom>
39
    </div>
40
  `
41
})
42
export class AppComponent {
43
  isClient: boolean = false;
44
  menuItems: RootMenuItem [] = [];
45
  userMenuItems: MenuItem[] = [];
46
  community = null;
47
  id: string = null;
48
  properties: EnvProperties = properties;
49
  user: User;
50
  loginCheck: boolean = false;
51
  footer = portalProperties.sectionFooter;
52
  header: Header;
53
  agg: AggregatorInfo = null;
54
  subscriptions = [];
55
  
56
  constructor(private userManagementService: UserManagementService,  private configurationService: ConfigurationService,  @Inject(DOCUMENT) private document, private rendererFactory: RendererFactory2) {
57
    this.id = ConnectHelper.getCommunityFromDomain(this.properties.domain);
58
    this.agg = PortalAggregators.getFilterInfoByMenuId(this.id);
59
    this.setStyles();
60
    this.configurationService.initStaticCommunityInformation(PortalAggregators.getCommunityInfoByMenuId(this.id));
61
  }
62
  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
  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
    this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
90
      this.user = user;
91
      this.loginCheck = true;
92
      this.userMenuItems = [];
93
      if (this.user) {
94
        this.userMenuItems.push(new MenuItem("", "My links", "", "/myclaims", false, [], [], {}));
95
        // this.userMenuItems.push(new MenuItem("", "User information", "", "/user-info", false, [], [], {}));
96
      }
97
    }));
98
  }
99
  
100
  private buildMenu() {
101
    this.menuItems = [
102
      {rootItem: new MenuItem("home", "Home", "", "/", false, [], null, {}), items: []},
103
      {
104
        rootItem: new MenuItem("search", "Search", "", "/search/find", false, [], ["/search/find"], {}),
105
        items: []
106
      },
107
      {
108
        rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], {}),
109
        items: []
110
      },
111
      {
112
        rootItem: new MenuItem("link", "Link", "", "/participate/claim", false, [], ["/participate/claim"], {}),
113
        items: [new MenuItem("", "Start linking", "", "/participate/claim", false, [], ["/participate/claim"], {}),
114
          new MenuItem("", "Learn more", this.properties.claimsInformationLink, "", false, [], [], {})]
115
      },
116
      {
117
        rootItem: new MenuItem("develop", "Develop", "", "/develop", false, [], ["/develop"], {}),
118
        items: []
119
      }
120
    ];
121
    let params = {};
122
    // 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

    
128
  }
129
  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
}
(2-2/4)