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
|
import {SmoothScroll} from "./openaireLibrary/utils/smooth-scroll";
|
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
|
export class AppComponent {
|
44
|
isClient: boolean = false;
|
45
|
menuItems: RootMenuItem [] = [];
|
46
|
userMenuItems: MenuItem[] = [];
|
47
|
community = null;
|
48
|
id: string = null;
|
49
|
properties: EnvProperties = properties;
|
50
|
user: User;
|
51
|
loginCheck: boolean = false;
|
52
|
footer = portalProperties.sectionFooter;
|
53
|
header: Header;
|
54
|
agg: AggregatorInfo = null;
|
55
|
subscriptions = [];
|
56
|
|
57
|
constructor(private userManagementService: UserManagementService,
|
58
|
private configurationService: ConfigurationService, private smoothScroll: SmoothScroll,
|
59
|
@Inject(DOCUMENT) private document, private rendererFactory: RendererFactory2) {
|
60
|
this.id = ConnectHelper.getCommunityFromDomain(this.properties.domain);
|
61
|
this.agg = PortalAggregators.getFilterInfoByMenuId(this.id);
|
62
|
this.setStyles();
|
63
|
this.configurationService.initStaticCommunityInformation(PortalAggregators.getCommunityInfoByMenuId(this.id));
|
64
|
}
|
65
|
|
66
|
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
|
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
85
|
this.user = user;
|
86
|
this.loginCheck = true;
|
87
|
this.userMenuItems = [];
|
88
|
if (this.user) {
|
89
|
this.userMenuItems.push(new MenuItem("", "My links", "", "/myclaims", false, [], [], {}));
|
90
|
// this.userMenuItems.push(new MenuItem("", "User information", "", "/user-info", false, [], [], {}));
|
91
|
}
|
92
|
}));
|
93
|
}
|
94
|
|
95
|
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
|
private buildMenu() {
|
107
|
this.menuItems = [
|
108
|
{rootItem: new MenuItem("home", "Home", "", "/", false, [], null, {}), items: []},
|
109
|
{
|
110
|
rootItem: new MenuItem("search", "Search", "", "/search/find", false, [], ["/search/find"], {}),
|
111
|
items: []
|
112
|
},
|
113
|
{
|
114
|
rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], {}),
|
115
|
items: []
|
116
|
},
|
117
|
{
|
118
|
rootItem: new MenuItem("link", "Link", "", "/participate/claim", false, [], ["/participate/claim"], {}),
|
119
|
items: [new MenuItem("", "Start linking", "", "/participate/claim", false, [], ["/participate/claim"], {}),
|
120
|
new MenuItem("", "Learn more", this.properties.claimsInformationLink, "", false, [], [], {})]
|
121
|
},
|
122
|
{
|
123
|
rootItem: new MenuItem("develop", "Develop", "", "/develop", false, [], ["/develop"], {}),
|
124
|
items: []
|
125
|
}
|
126
|
];
|
127
|
let params = {};
|
128
|
// 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
|
|
134
|
}
|
135
|
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
|
}
|