1
|
import {Component, Inject, Input, RendererFactory2, ViewEncapsulation} from '@angular/core';
|
2
|
import {ActivatedRoute, Router} from '@angular/router';
|
3
|
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
4
|
import {LayoutService} from "../../openaireLibrary/services/layout.service";
|
5
|
import {CustomizationOptions} from "../../openaireLibrary/connect/community/CustomizationOptions";
|
6
|
import {DOCUMENT} from "@angular/common";
|
7
|
|
8
|
@Component({
|
9
|
selector: 'customization',
|
10
|
template: ``
|
11
|
})
|
12
|
|
13
|
export class CustomizationComponent {
|
14
|
@Input() communityId;
|
15
|
@Input() layout: CustomizationOptions;
|
16
|
@Input() properties:EnvProperties;
|
17
|
customizationCss:string = "";
|
18
|
|
19
|
|
20
|
constructor(private route: ActivatedRoute,private router: Router, private _layoutService: LayoutService, @Inject(DOCUMENT) private document, private rendererFactory: RendererFactory2) {
|
21
|
}
|
22
|
|
23
|
public ngOnInit() {
|
24
|
|
25
|
this.buildCss();
|
26
|
try {
|
27
|
const head = this.document.getElementsByTagName('head')[0];
|
28
|
|
29
|
let customizationCssFile = this.document.getElementById('customCssfile' ) as HTMLLinkElement;
|
30
|
if (customizationCssFile) {
|
31
|
customizationCssFile.href = "/assets/customization.css";
|
32
|
} else {
|
33
|
const style = this.document.createElement('link');
|
34
|
style.id = 'customCssfile';
|
35
|
style.rel = 'stylesheet';
|
36
|
style.href = "/assets/customization.css";
|
37
|
head.appendChild(style);
|
38
|
}
|
39
|
let customCss = this.document.getElementById('customStyle' ) as HTMLLinkElement;
|
40
|
if (customCss) {
|
41
|
customCss.append(this.customizationCss);
|
42
|
} else {
|
43
|
const style = this.document.createElement('style');
|
44
|
style.id = 'customStyle';
|
45
|
head.appendChild(style);
|
46
|
const renderer = this.rendererFactory.createRenderer(this.document, {
|
47
|
id: '-1',
|
48
|
encapsulation: ViewEncapsulation.None,
|
49
|
styles: [],
|
50
|
data: {}
|
51
|
});
|
52
|
let CSSElement = renderer.createText(this.customizationCss);
|
53
|
renderer.appendChild(style,CSSElement);
|
54
|
}
|
55
|
} catch (e) {
|
56
|
console.error('Renderrer Error to append style ', e);
|
57
|
}
|
58
|
}
|
59
|
private buildCss() {
|
60
|
|
61
|
this.customizationCss = `
|
62
|
:root {
|
63
|
--portal-main-color: ` + this.layout.identity.mainColor+`;
|
64
|
--portal-dark-color: ` + this.layout.identity.secondaryColor+`;
|
65
|
}
|
66
|
`;
|
67
|
//Search SVG
|
68
|
let search = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2000 532"><defs><style>.cls-1{isolation:isolate;}.cls-2{fill:{{color}};mix-blend-mode:multiply;}</style></defs><title>Asset 3</title><g class="cls-1"><g id="Layer_2" data-name="Layer 2"><g id="Layer_1-2" data-name="Layer 1"><path class="cls-2" d="M0,431s362,109,841,62,632,68,1159-9V0H0Z"/><path class="cls-2" d="M0,514s1401,71,2000-69V0H0Z"/></g></g></g></svg>`;;
|
69
|
let svg = 'data:image/svg+xml,' + encodeURIComponent(search.replace('{{color}}', this.layout.backgrounds.form.color));
|
70
|
this.customizationCss = this.customizationCss.concat('.generalSearchForm,.publicationsSearchForm,.projectsSearchForm, .projectsTableSearchForm,.organizationsSearchForm,.datasourcesSearchForm {');
|
71
|
this.customizationCss = this.customizationCss.concat(' background: ' + "url('" + svg + "') transparent no-repeat center bottom; ");
|
72
|
this.customizationCss = this.customizationCss.concat(" background-size: cover !important; ");
|
73
|
this.customizationCss = this.customizationCss.concat(" height: inherit; }");
|
74
|
|
75
|
//Button link SVG
|
76
|
let arrow = `<svg width="23" height="11" viewBox="0 0 23 11" xmlns="http://www.w3.org/2000/svg"><polyline fill="none" stroke="{{color}}" points="17 1 22 5.5 17 10 " /><line fill="none" stroke="{{color}}" x1="0" y1="5.5" x2="22.4" y2="5.5" /></svg>`;;
|
77
|
let svg_arrow = 'data:image/svg+xml,' + encodeURIComponent(arrow.split('{{color}}').join(this.layout.identity.mainColor));
|
78
|
this.customizationCss = this.customizationCss.concat('.uk-button-text::before {');
|
79
|
this.customizationCss = this.customizationCss.concat(' background-image: ' + "url('" + svg_arrow + "') !important}");
|
80
|
|
81
|
this.customizationCss = this.customizationCss.concat(' .communityPanelBackground, .communityPanelBackground .uk-section-primary {');
|
82
|
this.customizationCss = this.customizationCss.concat(' background-color: ' + this.layout.backgrounds.dark.color + ';}');
|
83
|
this.customizationCss = this.customizationCss.concat(' .uk-button:not(.uk-button-text){');
|
84
|
this.customizationCss = this.customizationCss.concat(' border-radius:' + (this.layout.buttons.lightBackground.borderRadius != null ? this.layout.buttons.lightBackground.borderRadius : '4') + 'px;');
|
85
|
this.customizationCss = this.customizationCss.concat(' }');
|
86
|
|
87
|
|
88
|
this.customizationCss = this.customizationCss.concat(' .uk-button:not(.uk-button-text):not(.uk-button-default):not(.uk-button-primary):not(.uk-disabled), .portal-button:not(.uk-disabled) {');
|
89
|
this.customizationCss = this.customizationCss.concat(' background-color:' + (this.layout.buttons.lightBackground.backgroundColor != null ? this.layout.buttons.lightBackground.backgroundColor : `#003052`) + ';');
|
90
|
this.customizationCss = this.customizationCss.concat(' color: ' + (this.layout.buttons.lightBackground.color != null ? this.layout.buttons.lightBackground.color : `white`) + ';');
|
91
|
this.customizationCss = this.customizationCss.concat('border-color: ' + (this.layout.buttons.lightBackground.borderColor != null ? this.layout.buttons.lightBackground.borderColor : `transparent`) + ';');
|
92
|
this.customizationCss = this.customizationCss.concat(' border-style: ' + (this.layout.buttons.lightBackground.borderStyle != null ? this.layout.buttons.lightBackground.borderStyle : `solid`) + ';');
|
93
|
this.customizationCss = this.customizationCss.concat(' border-width: ' + (this.layout.buttons.lightBackground.borderWidth != null ? this.layout.buttons.lightBackground.borderWidth : `1`) + 'px;');
|
94
|
this.customizationCss = this.customizationCss.concat(' }');
|
95
|
|
96
|
|
97
|
this.customizationCss = this.customizationCss.concat(' .uk-button:not(.uk-button-text):not(.uk-button-default):not(.uk-button-primary):hover, .portal-button:hover {');
|
98
|
this.customizationCss = this.customizationCss.concat(' background-color:' + (this.layout.buttons.lightBackground.onHover.backgroundColor != null ? this.layout.buttons.lightBackground.onHover.backgroundColor : '#154B71') + ';');
|
99
|
this.customizationCss = this.customizationCss.concat(' color: '+ (this.layout.buttons.lightBackground.onHover.color != null ? this.layout.buttons.lightBackground.onHover.color : 'white') + ';');
|
100
|
this.customizationCss = this.customizationCss.concat(' border-color: ' + (this.layout.buttons.lightBackground.onHover.borderColor != null ? this.layout.buttons.lightBackground.onHover.borderColor : 'transparent') + ';');
|
101
|
this.customizationCss = this.customizationCss.concat(' }');
|
102
|
/*Buttons*/
|
103
|
this.customizationCss = this.customizationCss.concat(' .communityPanelBackground .uk-button:not(.ignoreCommunityPanelBackground) {');
|
104
|
this.customizationCss = this.customizationCss.concat( 'background-color: ' + this.layout.buttons.darkBackground.backgroundColor + ' !important;');
|
105
|
this.customizationCss = this.customizationCss.concat(' color: ' + this.layout.buttons.darkBackground.color + ' !important;');
|
106
|
this.customizationCss = this.customizationCss.concat(' border-color: ' + this.layout.buttons.darkBackground.borderColor + ' !important;');
|
107
|
this.customizationCss = this.customizationCss.concat(' border-style: ' + this.layout.buttons.darkBackground.borderStyle + ' !important;');
|
108
|
this.customizationCss = this.customizationCss.concat( 'border-width: ' + this.layout.buttons.darkBackground.borderWidth + 'px !important;');
|
109
|
this.customizationCss = this.customizationCss.concat( 'border-radius:' + this.layout.buttons.darkBackground.borderRadius + 'px !important;');
|
110
|
|
111
|
this.customizationCss = this.customizationCss.concat(' }');
|
112
|
|
113
|
|
114
|
this.customizationCss = this.customizationCss.concat(' .communityPanelBackground .uk-button:not(.ignoreCommunityPanelBackground):hover {');
|
115
|
this.customizationCss = this.customizationCss.concat(' background-color: ' + this.layout.buttons.darkBackground.onHover.backgroundColor + ' !important;');
|
116
|
this.customizationCss = this.customizationCss.concat( 'color: ' + this.layout.buttons.darkBackground.onHover.color + ' !important;');
|
117
|
this.customizationCss = this.customizationCss.concat( 'border-color:' + this.layout.buttons.darkBackground.onHover.borderColor + ' !important;');
|
118
|
this.customizationCss = this.customizationCss.concat(' }');
|
119
|
// console.debug(this.customizationCss)
|
120
|
|
121
|
}
|
122
|
}
|