Project

General

Profile

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
declare var appendCss: any;
9

    
10
@Component({
11
  selector: 'customization',
12
  template: `
13

    
14
<!--    <p>This is customizing layout component</p>-->
15
  `,
16
})
17

    
18
export class CustomizationComponent {
19
  @Input() communityId;
20
  layout: CustomizationOptions;
21
  @Input() properties:EnvProperties;
22

    
23
  constructor(private route: ActivatedRoute,
24
              private router: Router, private _layoutService: LayoutService, @Inject(DOCUMENT) private document, private rendererFactory: RendererFactory2
25
  ) {
26
  }
27

    
28
  public ngOnInit() {
29

    
30
       /* this.route.queryParams.subscribe(params => {
31

    
32
          if(params['layout']) {
33
            this.layout = JSON.parse(StringUtils.URIDecode(params['layout']));
34
            this.buildCss();
35
          }else{
36
            this._layoutService.getLayout(this.properties, this.communityId).subscribe(
37
              layout => {
38
                this.layout = layout;
39
                if(!layout){
40
                  this.layout = new CustomizationOptions();
41
                }
42
                this.buildCss();
43
              },
44
              error => {
45
                console.log(" Layout not found - use default");
46
                this.layout = new CustomizationOptions();
47
                this.buildCss();
48
              }
49
            );
50
          }
51

    
52

    
53

    
54

    
55
      });*/
56
//connect default colors
57
    let mainColor = "#FECA1D";
58
    let secondaryColor = "#FFC400";
59

    
60
     // TODO When customization is updated remove the following and build the css
61
    this.document.getElementById('customCss').setAttribute('href', "/assets/customization.css?v=0");
62

    
63
    if(this.communityId === 'covid-19') {
64
      mainColor = "#03ADEE";
65
      secondaryColor = "#F15157";
66
    } else {
67
      mainColor = "#4687E6";
68
      secondaryColor = "#2D72D6";
69
    }
70
    let css = `
71
    :root {
72
      --portal-main-color: `+mainColor+`;
73
      --portal-dark-color: `+secondaryColor+`;
74
    }
75
    `;
76

    
77
    try {
78
      if( this.document.getElementById('customStyle')){
79
        try {
80
          this.document.getElementById('customStyle').append(css);
81
        }catch(e){
82
          console.log("error with append style")
83
        }
84
      }else {
85
        const renderer = this.rendererFactory.createRenderer(this.document, {
86
          id: '-1',
87
          encapsulation: ViewEncapsulation.None,
88
          styles: [],
89
          data: {}
90
        });
91

    
92
        const head = this.document.head;
93
        if (head === null) {
94
          throw new Error('<head> not found within DOCUMENT.');
95
        }
96
        const style = renderer.createElement('style');
97
        renderer.setAttribute(style, "id", "customStyle");
98
        let CSSElement = renderer.createText(css);
99
        renderer.appendChild(head, style);
100
        renderer.appendChild(style, CSSElement);
101
      }
102
    } catch (e) {
103
      console.error('Renderrer Error to append style ', e);
104
    }
105
  }
106

    
107
  /*private buildCss() {
108
    if(typeof document === 'undefined') {
109
      return;
110
    }
111

    
112
    document.documentElement.style.setProperty('--portal-main-color', this.layout.mainColor);
113
    document.documentElement.style.setProperty('--portal-dark-color', this.layout.secondaryColor);
114
    let css:string = "";
115
    //Panel background
116
    css = css.concat('  .communityPanelBackground:not(bottom)  {   ');
117
    css = css.concat(' border-style: ' + (this.layout.panel.background.borderStyle != null ? this.layout.panel.background.borderStyle : 'solid') + ';');
118
    css = css.concat(' border-color: ' + (this.layout.panel.background.borderColor != null ? this.layout.panel.background.borderColor : 'transparent') + ';');
119
    css = css.concat(' border-width: ' + (this.layout.panel.background.borderWidth != null ? this.layout.panel.background.borderWidth : '1') + 'px;');
120
    css = css.concat(' }');
121
    css = css.concat('  .communityPanelBackground, .communityPanelBackground .uk-section-primary {');
122
    css = css.concat(' background-color:  '+ (this.layout.panel.background.color?this.layout.panel.background.color:this.layout.mainColor) + ';}')
123
//PAnel fonts
124
    css = css.concat('  .communityPanelBackground  {');
125
    css = css.concat('  color:' + (this.layout.panel.fonts.color != null ? this.layout.panel.fonts.color : 'white') + ' !important;');
126

    
127
    css = css.concat(this.layout.panel.fonts.family != null ? ('font-family: ' + this.layout.panel.fonts.family + ' !important;') : '');
128
    css = css.concat((this.layout.panel.fonts.size != null ? ('font-size: ' + this.layout.panel.fonts.size + 'px !important;') : ''));
129
    css = css.concat(this.layout.panel.fonts.weight != null ? ('font-weight: ' + this.layout.panel.fonts.weight + '!important;') : '');
130
    css = css.concat(' }');
131

    
132
    css = css.concat('  .communityPanelBackground svg .stroke_line {');
133
    css = css.concat('  stroke:' + (this.layout.panel.fonts.color != null ? this.layout.panel.fonts.color : 'white') + ' !important;');
134
    css = css.concat(' }');
135

    
136
    css = css.concat('   .communityPanelBackground  svg .fill_text {');
137
    css = css.concat('  fill:' + (this.layout.panel.fonts.color != null ? this.layout.panel.fonts.color : 'white') + ' !important;');
138
    css = css.concat(' }');
139

    
140

    
141
    css = css.concat('  .communityPanelBackground div.uk-modal{color:#666 !important;}');
142

    
143
    css = css.concat('  .communityPanelBackground .uk-h6:not(.ignoreCommunityPanelBackground),.communityPanelBackground .uk-h5:not(.ignoreCommunityPanelBackground),.communityPanelBackground .uk-h4:not(.ignoreCommunityPanelBackground),.communityPanelBackground .uk-h3:not(.ignoreCommunityPanelBackground), .communityPanelBackground .uk-h2:not(.ignoreCommunityPanelBackground),.communityPanelBackground .uk-h1:not(.ignoreCommunityPanelBackground) {')
144
    css = css.concat(' color: ' + (this.layout.panel.title.color != null ? this.layout.panel.title.color : 'white') + ' !important;' );
145
    css = css.concat(' }');
146

    
147
    css = css.concat('  .communityPanelBackground .uk-h5:not(.ignoreCommunityPanelBackground){');
148
    css = css.concat((this.layout.panel.title.family != null ? ('font-family: ' + this.layout.panel.title.family + ' !important;') : ''));
149
    css = css.concat((this.layout.panel.title.size != null ? ('font-size: ' + this.layout.panel.title.size + 'px !important;') : ''));
150
    css = css.concat((this.layout.panel.title.weight != null ? ('font-weight: ' + this.layout.panel.title.weight + '!important;') : ''));
151
    css = css.concat(' }');
152

    
153
    //Panel links
154

    
155
    css = css.concat('  .communityPanelBackground .uk-link:not(.ignoreCommunityPanelBackground), .communityPanelBackground a:not(.uk-button):not(.uk-button-text):not(.ignoreCommunityPanelBackground), .portal-card a {');
156
    css = css.concat(' color:'+(this.layout.panel.onDarkBackground ? (this.layout.links.darkBackground.color?this.layout.links.darkBackground.color:'white') :(this.layout.links.lightBackground.color?this.layout.links.lightBackground.color:'var(--portal-main-color)') ) + ' !important;');
157
    css = css.concat((this.layout.panel.onDarkBackground ? (this.layout.links.darkBackground.family?('font-family: ' + this.layout.links.darkBackground.family + ' !important;') : '') :'' ));
158
    css = css.concat((this.layout.panel.onDarkBackground ? (this.layout.links.darkBackground.size?('font-size: ' + this.layout.links.darkBackground.size + 'px !important;') : '') :'' ));
159
    css = css.concat(' }');
160

    
161
//Panel links - hover
162
    css = css.concat('  .communityPanelBackground .uk-link:not(.ignoreCommunityPanelBackground):hover, .communityPanelBackground a:not(.uk-button):not(.uk-button-text):not(.ignoreCommunityPanelBackground):hover, .portal-card a:hover {');
163
    css = css.concat(' color:'+(this.layout.panel.onDarkBackground ? (this.layout.links.darkBackground.onHover.color?this.layout.links.darkBackground.onHover.color:`rgba(255, 255, 255, 0.5)`) :(this.layout.links.lightBackground.onHover.color?this.layout.links.lightBackground.onHover.color:'var(--portal-dark-color)') ) + ' !important;');
164
    css = css.concat();
165
    css = css.concat(' }');
166

    
167

    
168

    
169
    css = css.concat('  .uk-link, a:not(.uk-button), .uk-navbar-dropdown-nav > li > a, .uk-navbar-nav > li > a, .loginLink, .uk-tab > .uk-active > a, .uk-tab > * > a:focus, .uk-tab > * > a:hover{');
170
    css = css.concat(' color:' + (this.layout.links.lightBackground.color != null ? this.layout.links.lightBackground.color : `var(--portal-main-color)`)+';');
171
    css = css.concat(' }');
172

    
173
    css = css.concat('  .uk-link:hover, a:not(.uk-button):hover,.uk-navbar-dropdown-nav > li > a:focus, .uk-navbar-dropdown-nav > li > a:hover, .uk-navbar-nav > li > a:hover, .uk-navbar-nav > li > a:focus, .uk-navbar-nav > li > a:active, .uk-navbar-nav > li:hover > a,.uk-navbar-dropdown-nav > li.uk-active > a, .uk-tab > .uk-active > a, .uk-navbar-nav > li.uk-active > a, .uk-navbar-container:not(.uk-navbar-transparent) .uk-navbar-nav > li.uk-active > a{');
174
    css = css.concat(' color:' + (this.layout.links.lightBackground.onHover.color != null ? this.layout.links.lightBackground.onHover.color : `var(--portal-dark-color)`)+';');
175
    css = css.concat(' }');
176

    
177

    
178
    css = css.concat('  .communityBorder {');
179
    css = css.concat(' border-color: ' + (this.layout.box.borderColor != null ? this.layout.box.borderColor : 'var(--portal-main-color)') + ';');
180
    css = css.concat(' border-style: ' + (this.layout.box.borderStyle != null ? this.layout.box.borderStyle : 'solid') + ';');
181
    css = css.concat(' border-width: ' + (this.layout.box.borderWidth != null ? this.layout.box.borderWidth : '2') + 'px;');
182
    css = css.concat(' border-radius: ' + (this.layout.box.borderRadius != null ? this.layout.box.borderRadius : '6') + 'px;');
183
    css = css.concat(' }');
184

    
185
    /!*Panel Elements & cards*!/
186
    css = css.concat('  .communityPanelBackground .uk-card:not(.ignoreCommunityPanelBackground), .communityPanelBackground .uk-label:not(.ignoreCommunityPanelBackground) {');
187
    css = css.concat(' background-color: ' + (this.layout.panel.panelElements.backgroundColor != null ? this.layout.panel.panelElements.backgroundColor : 'rgba(255, 255, 255, 0.5)') + ';');
188
    css = css.concat( 'border-color: ' + (this.layout.panel.panelElements.borderColor != null ? this.layout.panel.panelElements.borderColor : 'rgba(255, 255, 255, 0.5)') + ';');
189
    css = css.concat(' }');
190

    
191
    css = css.concat('  .communityPanelBackground .uk-label:not(.ignoreCommunityPanelBackground) a{');
192
    css = css.concat( 'border-color: ' + (this.layout.panel.onDarkBackground ? (this.layout.links.darkBackground.color?this.layout.links.darkBackground.color:'rgba(255, 255, 255, 0.8)') :(this.layout.links.lightBackground.color?this.layout.links.lightBackground.color:'var(--portal-main-color)') ) +';' );     
193
    css = css.concat('  border-bottom: 1px solid;');
194
    css = css.concat(' }');
195

    
196
    css = css.concat('  .communityPanelBackground .uk-label:not(.ignoreCommunityPanelBackground) a:hover{');
197
    css = css.concat(' border-color:'+(this.layout.panel.onDarkBackground ? (this.layout.links.darkBackground.onHover.color?this.layout.links.darkBackground.onHover.color:'rgba(255, 255, 255, 0.5)') :(this.layout.links.lightBackground.onHover.color?this.layout.links.lightBackground.onHover.color:'var(--portal-dark-color)') )+';');
198
    css = css.concat(' }');
199
    
200
    
201
    css = css.concat('  .communityPanelBackground .uk-card:not(.ignoreCommunityPanelBackground), .communityPanelBackground .uk-label:not(.ignoreCommunityPanelBackground) {');
202
    css = css.concat(' color:'+(this.layout.panel.panelElements.color != null ? this.layout.panel.panelElements.color : 'rgba(255, 255, 255, 0.5)')+';');
203
    css = css.concat();
204
    css = css.concat(' }');
205

    
206
    css = css.concat('  .uk-button:not(.uk-button-text){');
207
    css = css.concat(' border-radius:' + (this.layout.buttons.lightBackground.borderRadius != null ? this.layout.buttons.lightBackground.borderRadius : '4') + 'px;');
208
    css = css.concat(' }');
209

    
210

    
211
    css = css.concat('  .uk-button:not(.uk-button-text):not(.uk-button-default):not(.uk-button-primary), .portal-button {');
212
    css = css.concat(' background-color:' + (this.layout.buttons.lightBackground.backgroundColor != null ? this.layout.buttons.lightBackground.backgroundColor : `#003052`) + ';');
213
    css = css.concat(' color: ' + (this.layout.buttons.lightBackground.color != null ? this.layout.buttons.lightBackground.color : `white`) +  ';');
214
    css = css.concat('border-color: ' + (this.layout.buttons.lightBackground.borderColor != null ? this.layout.buttons.lightBackground.borderColor : `transparent`) +  ';');
215
    css = css.concat(' border-style: ' + (this.layout.buttons.lightBackground.borderStyle != null ? this.layout.buttons.lightBackground.borderStyle : `solid`) +  ';');
216
    css = css.concat(' border-width: ' + (this.layout.buttons.lightBackground.borderWidth != null ? this.layout.buttons.lightBackground.borderWidth : `1`) + 'px;');
217
    css = css.concat(' }');
218

    
219

    
220
    css = css.concat('  .uk-button:not(.uk-button-text):not(.uk-button-default):not(.uk-button-primary):hover, .portal-button:hover {');
221
    css = css.concat(' background-color:' + (this.layout.buttons.lightBackground.onHover.backgroundColor != null ? this.layout.buttons.lightBackground.onHover.backgroundColor : '#154B71') + ';');
222
    css = css.concat(' color: '+ (this.layout.buttons.lightBackground.onHover.color != null ? this.layout.buttons.lightBackground.onHover.color : 'white') + ';');
223
    css = css.concat(' border-color: ' + (this.layout.buttons.lightBackground.onHover.color != null ? this.layout.buttons.lightBackground.onHover.color : 'transparent') + ';');
224
    css = css.concat(' }');
225
    /!*Buttons*!/
226
    css = css.concat('  .communityPanelBackground .uk-button:not(.ignoreCommunityPanelBackground) {');
227
    css = css.concat( 'background-color: ' +
228
      (this.layout.panel.onDarkBackground ? (this.layout.buttons.darkBackground.backgroundColor?this.layout.buttons.darkBackground.backgroundColor:'white') :(this.layout.buttons.lightBackground.backgroundColor?this.layout.buttons.lightBackground.backgroundColor:'var(--portal-main-color)') )
229
        +'  !important;');
230
    css = css.concat(' color: '
231
      + (this.layout.panel.onDarkBackground ? (this.layout.buttons.darkBackground.color?this.layout.buttons.darkBackground.color:'var(--portal-main-color)') :(this.layout.buttons.lightBackground.color?this.layout.buttons.lightBackground.color:'white') )
232
      +  ' !important;');
233
    css = css.concat(' border-color: '
234
      + (this.layout.panel.onDarkBackground ? (this.layout.buttons.darkBackground.borderColor?this.layout.buttons.darkBackground.borderColor:'white') :(this.layout.buttons.lightBackground.borderColor?this.layout.buttons.lightBackground.borderColor:'var(--portal-main-color)') )
235
       + ' !important;');
236
    css = css.concat(' border-style: ' +
237
       (this.layout.panel.onDarkBackground ? (this.layout.buttons.darkBackground.borderStyle?this.layout.buttons.darkBackground.borderStyle:'solid') :(this.layout.buttons.lightBackground.borderStyle?this.layout.buttons.lightBackground.borderStyle:'solid') )
238
       + '  !important;');
239
    css = css.concat( 'border-width: ' +
240
      (this.layout.panel.onDarkBackground ? (this.layout.buttons.darkBackground.borderWidth?this.layout.buttons.darkBackground.borderWidth:'1') :(this.layout.buttons.lightBackground.borderWidth?this.layout.buttons.lightBackground.borderWidth:'1') )
241
      + 'px !important;');
242
    css = css.concat( 'border-radius:' +
243
      (this.layout.panel.onDarkBackground ? (this.layout.buttons.darkBackground.borderRadius?this.layout.buttons.darkBackground.borderRadius:'4') :(this.layout.buttons.lightBackground.borderRadius?this.layout.buttons.lightBackground.borderRadius:'4') )
244
       + 'px !important;');
245

    
246
    css = css.concat(' }');
247

    
248

    
249
    css = css.concat('  .communityPanelBackground .uk-button:not(.ignoreCommunityPanelBackground):hover {');
250
    css = css.concat(' background-color: ' +
251
       (this.layout.panel.onDarkBackground ? (this.layout.buttons.darkBackground.onHover.backgroundColor?this.layout.buttons.darkBackground.onHover.backgroundColor:' #eeeeee') :(this.layout.buttons.lightBackground.onHover.backgroundColor?this.layout.buttons.lightBackground.onHover.backgroundColor:'var(--portal-dark-color)') )
252
      + ' !important;');
253
    css = css.concat(  'color: ' +
254
      (this.layout.panel.onDarkBackground ? (this.layout.buttons.darkBackground.onHover.color?this.layout.buttons.darkBackground.onHover.color:' var(--portal-main-color) ') :(this.layout.buttons.lightBackground.onHover.color?this.layout.buttons.lightBackground.onHover.color:'white') )
255
       + ' !important;');
256
    css = css.concat( 'border-color:'
257
       +(this.layout.panel.onDarkBackground ? (this.layout.buttons.darkBackground.onHover.borderColor?this.layout.buttons.darkBackground.onHover.borderColor:' #eeeeee ') :(this.layout.buttons.lightBackground.onHover.borderColor?this.layout.buttons.lightBackground.onHover.borderColor:'var(--portal-dark-color)') )
258
      + '  !important;');
259
    css = css.concat(' }');
260

    
261
    let css1 = `
262
 
263
.uk-navbar-dropdown {
264
    background-color: white;
265
    color: #666;
266
    box-shadow: 0 5px 12px rgba(0, 0, 0, .15);
267
    /!*border:var(--portal-main-color) 1px solid;*!/
268
}
269

    
270
.customTabs .uk-tab > .uk-active > a {
271
    border-color: var(--portal-main-color);
272
}
273

    
274
.customTabs .uk-tab > .uk-active > a {
275
    border-color: var(--portal-main-color);
276
}
277

    
278
.uk-tab > * > a:focus, .uk-tab > * > a:hover {
279
    border-color: var(--portal-dark-color);
280
}
281

    
282

    
283
`;
284
    css = css.concat(css1);
285
    console.log(css);
286
    appendCss(css);
287
  }*/
288
}
(1-1/2)