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 {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
5
import {AggregatorInfo, PortalAggregators} from "./utils/aggregators";
6
import {UserManagementService} from "./openaireLibrary/services/user-management.service";
7
import {User} from "./openaireLibrary/login/utils/helper.class";
8
import {Header} from "./openaireLibrary/sharedComponents/navigationBar.component";
9
import {portalProperties} from "../environments/environment-aggregator";
10
import {properties} from "../environments/environment";
11
import {ConnectHelper} from "./openaireLibrary/connect/connectHelper";
12
import {ConfigurationService} from "./openaireLibrary/utils/configuration/configuration.service";
13
import {Subscriber} from "rxjs";
14
import {DOCUMENT} from "@angular/common";
15

    
16
@Component({
17
  selector: 'app-root',
18
  template: `
19
    <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
              <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
      </cookie-law>
39
      <bottom *ngIf="isClient && properties" [properties]=properties></bottom>
40
    </div>
41
  `
42
  
43
})
44
export class AppComponent {
45
  isClient: boolean = false;
46
  menuItems: RootMenuItem [] = [];
47
  userMenuItems: MenuItem[] = [];
48
  community = null;
49
  id: string = null;
50
  properties: EnvProperties = properties;
51
  user: User;
52
  loginCheck: boolean = false;
53
  footer = portalProperties.sectionFooter;
54
  header: Header;
55
  agg: AggregatorInfo = null;
56
  subscriptions = [];
57
  constructor(private propertiesService: EnvironmentSpecificService,
58
              private userManagementService: UserManagementService,  private configurationService: ConfigurationService,  @Inject(DOCUMENT) private document, private rendererFactory: RendererFactory2) {
59
    this.id = ConnectHelper.getCommunityFromDomain(this.properties.domain);
60
    this.agg = PortalAggregators.getFilterInfoByMenuId(this.id);
61
    this.setStyles();
62
    this.configurationService.initStaticCommunityInformation(PortalAggregators.getCommunityInfoByMenuId(this.id));
63
  }
64
  ngOnDestroy() {
65
    this.subscriptions.forEach(subscription => {
66
      if (subscription instanceof Subscriber) {
67
        subscription.unsubscribe();
68
      }
69
    });
70
    this.configurationService.clearSubscriptions();
71
    this.userManagementService.clearSubscriptions();
72
  }
73
  ngOnInit() {
74
    if (typeof document !== 'undefined') {
75
        this.isClient = true;
76
    }
77
    this.id = ConnectHelper.getCommunityFromDomain(this.properties.domain);
78
    this.agg = PortalAggregators.getFilterInfoByMenuId(this.id);
79
    if (this.agg) {
80
      this.header = {
81
        route: '/',
82
        url: null,
83
        title: this.agg.title,
84
        logoUrl: this.agg.logoUrl,
85
        logoSmallUrl: this.agg.logoUrl,
86
        position: 'left',
87
        badge: true
88
      };
89
      this.buildMenu();
90
    }
91
    this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
92
      this.user = user;
93
      this.loginCheck = true;
94
      this.userMenuItems = [];
95
      if (this.user) {
96
        this.userMenuItems.push(new MenuItem("", "My links", "", "/myclaims", false, [], [], {}));
97
        // this.userMenuItems.push(new MenuItem("", "User information", "", "/user-info", false, [], [], {}));
98
      }
99
    }));
100
  }
101
  
102
  private buildMenu() {
103
    this.menuItems = [
104
      {rootItem: new MenuItem("home", "Home", "", "/", false, [], null, {}), items: []},
105
      {
106
        rootItem: new MenuItem("search", "Search", "", "/search/find", false, [], ["/search/find"], {}),
107
        items: []
108
      },
109
      {
110
        rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], {}),
111
        items: []
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("develop", "Develop", "", "/develop", false, [], ["/develop"], {}),
120
        items: []
121
      }
122
    ];
123
    let params = {};
124
    // params[this.agg.queryFieldName] = this.agg.valueId;
125
    this.menuItems[1].items.push(new MenuItem("", "Research outcomes", "", "/search/find/research-outcomes", false, [], ["/search/find/research-outcomes"], params));
126
    this.menuItems[1].items.push(new MenuItem("", "Projects", "", "/search/find/projects", false, ["project"], ["/search/find/projects"], params));
127
    this.menuItems[1].items.push(new MenuItem("", "Content Providers", "", "/search/find/dataproviders", false, ["datasource"], ["/search/find/dataproviders"], params));
128
    this.menuItems[1].items.push(new MenuItem("", "Organizations", "", "/search/find/organizations", false, ["organization"], ["/search/find/organizations"], params));
129

    
130
  }
131
  setStyles(){
132
    let css:string =':root {\n';
133
    if(this.agg.mainColor){
134
      css = css.concat('--portal-main-color: ' + this.agg.mainColor + ';\n');
135
    }
136
    if(this.agg.darkColor){
137
      css = css.concat('--portal-dark-color: ' + this.agg.darkColor + ';\n');
138
    }
139
    if(this.agg.darkColor){
140
      css = css.concat("--graph-background:  url('" + this.agg.background + "\') no-repeat bottom;\n");
141
    }
142
    css = css.concat('}');
143

    
144
    try {
145
      if( this.document.getElementById('customStyle')){
146
        try {
147
          this.document.getElementById('customStyle').append(css);
148
        }catch(e){
149
          console.log("error with append style")
150
        }
151
      }else {
152
        const renderer = this.rendererFactory.createRenderer(this.document, {
153
          id: '-1',
154
          encapsulation: ViewEncapsulation.None,
155
          styles: [],
156
          data: {}
157
        });
158

    
159
        const head = this.document.head;
160
        if (head === null) {
161
          throw new Error('<head> not found within DOCUMENT.');
162
        }
163
        const style = renderer.createElement('style');
164
        renderer.setAttribute(style, "id", "customStyle");
165
        let CSSElement = renderer.createText(css);
166
        renderer.appendChild(head, style);
167
        renderer.appendChild(style, CSSElement);
168
      }
169
    } catch (e) {
170
      console.error('Renderrer Error to append style ', e);
171
    }
172
  }
173

    
174
}
(2-2/4)