Project

General

Profile

1
import { Component, Input } from '@angular/core';
2
import {ActivatedRoute} from '@angular/router';
3
import 'rxjs';
4
import{MenuItem} from './menu';
5
import { ConfigurationService } from '../utils/configuration/configuration.service';
6
import {EnvProperties} from "../utils/properties/env-properties";
7
import {Subscription} from "rxjs";
8
import {properties} from '../../../environments/environment';
9
import {HelperService} from "../utils/helper/helper.service";
10

    
11
@Component({
12
  selector: 'bottom',
13
  templateUrl: 'bottom.component.html'
14
})
15
export class BottomComponent {
16

    
17
@Input() showSocialButtons:boolean = true;
18
@Input() showOpenaire:boolean = true;
19
@Input() showMenuItems:boolean = false;
20
@Input() showCommision:boolean = true;
21
@Input() assetsPath:string ='assets/common-assets/';
22
@Input() menuItems:MenuItem [];
23

    
24
@Input() communityId;
25
// @Input() environment:string = "beta";
26
showPage ={};
27
@Input() grantAdvance:boolean = true;
28
// grantAdvanceText = "OpenAIRE-Advance receives funding from the European Union's Horizon 2020 Research and Innovation programme under Grant Agreement No. 777541.";
29
// grantConenctText = "OpenAIRE-Connect receives funding from the European Union's Horizon 2020 Research and Innovation programme under grant agreement No. 731011 and  No. 777541.";
30
@Input()  properties:EnvProperties = properties;
31
@Input() darkBackground:boolean=true;
32
@Input() centered:boolean=false;
33
@Input() shortView: boolean = false;
34
sectionClass= "uk-section-primary";
35

    
36
subs: Subscription[] = [];
37
public divContents = null;
38

    
39
constructor(private config: ConfigurationService, private  route: ActivatedRoute,
40
            private helper: HelperService) {
41
}
42

    
43
  ngOnInit() {
44
  if(!properties.footerGrantText) {
45
    this.getDivContents();
46
  }
47
  if(!this.darkBackground){
48
    this.sectionClass= " footer-light-background";
49
  }
50
    this.subs.push(this.route.queryParams.subscribe(params => {
51
      if(this.showMenuItems){
52
        if( this.properties.adminToolsAPIURL && this.communityId ){
53
          //this.subs.push(this.config.getCommunityInformation(this.properties, this.communityId ).subscribe(data => {
54
          this.subs.push(this.config.communityInformationState.subscribe(data => {
55
            if(data) {
56
              for (var i = 0; i < data['pages'].length; i++) {
57
                this.showPage[data['pages'][i]["route"]] = data['pages'][i]["isEnabled"];
58

    
59
              }
60
              // console.log(this.showPage)
61
            }
62
          }));
63
        }
64
      }
65
    }));
66
  }
67

    
68
  public ngOnDestroy() {
69
    for (let sub of this.subs) {
70
      sub.unsubscribe();
71
    }
72
  }
73

    
74
  isEnabled(required, enabled){
75

    
76
    if(!required ){
77
      return true;
78
    }
79
    for(let requiredEntity of required){
80
      // console.log("R "+requiredEntity +" E "  + enabled[requiredEntity])
81
        if(typeof enabled[requiredEntity] === "undefined" || enabled[requiredEntity] == false){
82
          return false;
83
        }
84
    }
85
    return true;
86
  }
87

    
88
  private getDivContents() {
89
  let communityId = this.communityId;
90
    if(!communityId) {
91
      communityId = properties.adminToolsCommunity;
92
    }
93
    this.subs.push(this.helper.getDivHelpContents(this.properties, communityId, "/").subscribe(contents => {
94
      this.divContents = contents;
95
    }));
96
  }
97
}
(2-2/7)