Project

General

Profile

1
import {Component, Input} 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 {StringUtils} from "../../openaireLibrary/utils/string-utils.class";
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
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

    
57
     // TODO When customization is updated remove trhe followin and update appendCss in index.html
58
    appendCss("");
59
    if(typeof document === 'undefined') {
60
      return;
61
    }
62
    document.documentElement.style.setProperty('--portal-main-color',  '#4687E6');
63
    document.documentElement.style.setProperty('--portal-dark-color', '#2D72D6');
64

    
65

    
66
  }
67

    
68
  private buildCss() {
69
    if(typeof document === 'undefined') {
70
      return;
71
    }
72

    
73
    document.documentElement.style.setProperty('--portal-main-color', this.layout.mainColor);
74
    document.documentElement.style.setProperty('--portal-dark-color', this.layout.secondaryColor);
75
    let css:string = "";
76
    //Panel background
77
    css = css.concat('  .communityPanelBackground:not(bottom)  {   ');
78
    css = css.concat(' border-style: ' + (this.layout.panel.background.borderStyle != null ? this.layout.panel.background.borderStyle : 'solid') + ';');
79
    css = css.concat(' border-color: ' + (this.layout.panel.background.borderColor != null ? this.layout.panel.background.borderColor : 'transparent') + ';');
80
    css = css.concat(' border-width: ' + (this.layout.panel.background.borderWidth != null ? this.layout.panel.background.borderWidth : '1') + 'px;');
81
    css = css.concat(' }');
82
    css = css.concat('  .communityPanelBackground, .communityPanelBackground .uk-section-primary {');
83
    css = css.concat(' background-color:  '+ (this.layout.panel.background.color?this.layout.panel.background.color:this.layout.mainColor) + ';}')
84
//PAnel fonts
85
    css = css.concat('  .communityPanelBackground  {');
86
    css = css.concat('  color:' + (this.layout.panel.fonts.color != null ? this.layout.panel.fonts.color : 'white') + ' !important;');
87

    
88
    css = css.concat(this.layout.panel.fonts.family != null ? ('font-family: ' + this.layout.panel.fonts.family + ' !important;') : '');
89
    css = css.concat((this.layout.panel.fonts.size != null ? ('font-size: ' + this.layout.panel.fonts.size + 'px !important;') : ''));
90
    css = css.concat(this.layout.panel.fonts.weight != null ? ('font-weight: ' + this.layout.panel.fonts.weight + '!important;') : '');
91
    css = css.concat(' }');
92

    
93
    css = css.concat('  .communityPanelBackground svg .stroke_line {');
94
    css = css.concat('  stroke:' + (this.layout.panel.fonts.color != null ? this.layout.panel.fonts.color : 'white') + ' !important;');
95
    css = css.concat(' }');
96

    
97
    css = css.concat('   .communityPanelBackground  svg .fill_text {');
98
    css = css.concat('  fill:' + (this.layout.panel.fonts.color != null ? this.layout.panel.fonts.color : 'white') + ' !important;');
99
    css = css.concat(' }');
100

    
101

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

    
104
    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) {')
105
    css = css.concat(' color: ' + (this.layout.panel.title.color != null ? this.layout.panel.title.color : 'white') + ' !important;' );
106
    css = css.concat(' }');
107

    
108
    css = css.concat('  .communityPanelBackground .uk-h5:not(.ignoreCommunityPanelBackground){');
109
    css = css.concat((this.layout.panel.title.family != null ? ('font-family: ' + this.layout.panel.title.family + ' !important;') : ''));
110
    css = css.concat((this.layout.panel.title.size != null ? ('font-size: ' + this.layout.panel.title.size + 'px !important;') : ''));
111
    css = css.concat((this.layout.panel.title.weight != null ? ('font-weight: ' + this.layout.panel.title.weight + '!important;') : ''));
112
    css = css.concat(' }');
113

    
114
    //Panel links
115

    
116
    css = css.concat('  .communityPanelBackground .uk-link:not(.ignoreCommunityPanelBackground), .communityPanelBackground a:not(.uk-button):not(.uk-button-text):not(.ignoreCommunityPanelBackground), .portal-card a {');
117
    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;');
118
    css = css.concat((this.layout.panel.onDarkBackground ? (this.layout.links.darkBackground.family?('font-family: ' + this.layout.links.darkBackground.family + ' !important;') : '') :'' ));
119
    css = css.concat((this.layout.panel.onDarkBackground ? (this.layout.links.darkBackground.size?('font-size: ' + this.layout.links.darkBackground.size + 'px !important;') : '') :'' ));
120
    css = css.concat(' }');
121

    
122
//Panel links - hover
123
    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 {');
124
    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;');
125
    css = css.concat();
126
    css = css.concat(' }');
127

    
128

    
129

    
130
    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{');
131
    css = css.concat(' color:' + (this.layout.links.lightBackground.color != null ? this.layout.links.lightBackground.color : `var(--portal-main-color)`)+';');
132
    css = css.concat(' }');
133

    
134
    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{');
135
    css = css.concat(' color:' + (this.layout.links.lightBackground.onHover.color != null ? this.layout.links.lightBackground.onHover.color : `var(--portal-dark-color)`)+';');
136
    css = css.concat(' }');
137

    
138

    
139
    css = css.concat('  .communityBorder {');
140
    css = css.concat(' border-color: ' + (this.layout.box.borderColor != null ? this.layout.box.borderColor : 'var(--portal-main-color)') + ';');
141
    css = css.concat(' border-style: ' + (this.layout.box.borderStyle != null ? this.layout.box.borderStyle : 'solid') + ';');
142
    css = css.concat(' border-width: ' + (this.layout.box.borderWidth != null ? this.layout.box.borderWidth : '2') + 'px;');
143
    css = css.concat(' border-radius: ' + (this.layout.box.borderRadius != null ? this.layout.box.borderRadius : '6') + 'px;');
144
    css = css.concat(' }');
145

    
146
    /*Panel Elements & cards*/
147
    css = css.concat('  .communityPanelBackground .uk-card:not(.ignoreCommunityPanelBackground), .communityPanelBackground .uk-label:not(.ignoreCommunityPanelBackground) {');
148
    css = css.concat(' background-color: ' + (this.layout.panel.panelElements.backgroundColor != null ? this.layout.panel.panelElements.backgroundColor : 'rgba(255, 255, 255, 0.5)') + ';');
149
    css = css.concat( 'border-color: ' + (this.layout.panel.panelElements.borderColor != null ? this.layout.panel.panelElements.borderColor : 'rgba(255, 255, 255, 0.5)') + ';');
150
    css = css.concat(' }');
151

    
152
    css = css.concat('  .communityPanelBackground .uk-label:not(.ignoreCommunityPanelBackground) a{');
153
    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)') ) +';' );     
154
    css = css.concat('  border-bottom: 1px solid;');
155
    css = css.concat(' }');
156

    
157
    css = css.concat('  .communityPanelBackground .uk-label:not(.ignoreCommunityPanelBackground) a:hover{');
158
    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)') )+';');
159
    css = css.concat(' }');
160
    
161
    
162
    css = css.concat('  .communityPanelBackground .uk-card:not(.ignoreCommunityPanelBackground), .communityPanelBackground .uk-label:not(.ignoreCommunityPanelBackground) {');
163
    css = css.concat(' color:'+(this.layout.panel.panelElements.color != null ? this.layout.panel.panelElements.color : 'rgba(255, 255, 255, 0.5)')+';');
164
    css = css.concat();
165
    css = css.concat(' }');
166

    
167
    css = css.concat('  .uk-button:not(.uk-button-text){');
168
    css = css.concat(' border-radius:' + (this.layout.buttons.lightBackground.borderRadius != null ? this.layout.buttons.lightBackground.borderRadius : '4') + 'px;');
169
    css = css.concat(' }');
170

    
171

    
172
    css = css.concat('  .uk-button:not(.uk-button-text):not(.uk-button-default):not(.uk-button-primary), .portal-button {');
173
    css = css.concat(' background-color:' + (this.layout.buttons.lightBackground.backgroundColor != null ? this.layout.buttons.lightBackground.backgroundColor : `#003052`) + ';');
174
    css = css.concat(' color: ' + (this.layout.buttons.lightBackground.color != null ? this.layout.buttons.lightBackground.color : `white`) +  ';');
175
    css = css.concat('border-color: ' + (this.layout.buttons.lightBackground.borderColor != null ? this.layout.buttons.lightBackground.borderColor : `transparent`) +  ';');
176
    css = css.concat(' border-style: ' + (this.layout.buttons.lightBackground.borderStyle != null ? this.layout.buttons.lightBackground.borderStyle : `solid`) +  ';');
177
    css = css.concat(' border-width: ' + (this.layout.buttons.lightBackground.borderWidth != null ? this.layout.buttons.lightBackground.borderWidth : `1`) + 'px;');
178
    css = css.concat(' }');
179

    
180

    
181
    css = css.concat('  .uk-button:not(.uk-button-text):not(.uk-button-default):not(.uk-button-primary):hover, .portal-button:hover {');
182
    css = css.concat(' background-color:' + (this.layout.buttons.lightBackground.onHover.backgroundColor != null ? this.layout.buttons.lightBackground.onHover.backgroundColor : '#154B71') + ';');
183
    css = css.concat(' color: '+ (this.layout.buttons.lightBackground.onHover.color != null ? this.layout.buttons.lightBackground.onHover.color : 'white') + ';');
184
    css = css.concat(' border-color: ' + (this.layout.buttons.lightBackground.onHover.color != null ? this.layout.buttons.lightBackground.onHover.color : 'transparent') + ';');
185
    css = css.concat(' }');
186
    /*Buttons*/
187
    css = css.concat('  .communityPanelBackground .uk-button:not(.ignoreCommunityPanelBackground) {');
188
    css = css.concat( 'background-color: ' +
189
      (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)') )
190
        +'  !important;');
191
    css = css.concat(' color: '
192
      + (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') )
193
      +  ' !important;');
194
    css = css.concat(' border-color: '
195
      + (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)') )
196
       + ' !important;');
197
    css = css.concat(' border-style: ' +
198
       (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') )
199
       + '  !important;');
200
    css = css.concat( 'border-width: ' +
201
      (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') )
202
      + 'px !important;');
203
    css = css.concat( 'border-radius:' +
204
      (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') )
205
       + 'px !important;');
206

    
207
    css = css.concat(' }');
208

    
209

    
210
    css = css.concat('  .communityPanelBackground .uk-button:not(.ignoreCommunityPanelBackground):hover {');
211
    css = css.concat(' background-color: ' +
212
       (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)') )
213
      + ' !important;');
214
    css = css.concat(  'color: ' +
215
      (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') )
216
       + ' !important;');
217
    css = css.concat( 'border-color:'
218
       +(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)') )
219
      + '  !important;');
220
    css = css.concat(' }');
221

    
222
    let css1 = `
223
 
224
.uk-navbar-dropdown {
225
    background-color: white;
226
    color: #666;
227
    box-shadow: 0 5px 12px rgba(0, 0, 0, .15);
228
    /*border:var(--portal-main-color) 1px solid;*/
229
}
230

    
231
.customTabs .uk-tab > .uk-active > a {
232
    border-color: var(--portal-main-color);
233
}
234

    
235
.customTabs .uk-tab > .uk-active > a {
236
    border-color: var(--portal-main-color);
237
}
238

    
239
.uk-tab > * > a:focus, .uk-tab > * > a:hover {
240
    border-color: var(--portal-dark-color);
241
}
242

    
243

    
244
`;
245
    css = css.concat(css1);
246
    console.log(css);
247
    appendCss(css);
248
  }
249
}
(1-1/2)