Project

General

Profile

1
import {Component, OnDestroy, OnInit} from '@angular/core';
2
import {Subscription} from 'rxjs';
3
import {ActivatedRoute, Router} from '@angular/router';
4
import {Location} from '@angular/common';
5
import {Meta, Title} from '@angular/platform-browser';
6
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
7
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
8
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
9
import {SEOService} from '../openaireLibrary/sharedComponents/SEO/SEO.service';
10
import {properties} from '../../environments/environment';
11
import {portals} from './portals';
12
import {Filter} from '../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class';
13
import {RouterHelper} from '../openaireLibrary/utils/routerHelper.class';
14

    
15
@Component({
16
  selector: 'home',
17
  templateUrl: 'home.component.html',
18
  styleUrls: ['home.component.css']
19
})
20
export class HomeComponent implements OnInit, OnDestroy {
21
  public pageTitle = 'OpenAIRE - Research Graph';
22
  public portals: any[] = portals;
23
  public state: number = 0;
24
  public properties: EnvProperties = properties;
25
  public selectedEntity = 'all';
26
  public url: string;
27
  public routerHelper: RouterHelper = new RouterHelper();
28
  public resultTypes: Filter = {
29
    values: [
30
      {name: 'Publications', id: 'publications', selected: true, number: 0},
31
      {name: "Research data", id: "datasets", selected: true, number: 0},
32
      {name: "Software", id: "software", selected: true, number: 0},
33
      {name: "Other research products", id: "other", selected: true, number: 0}
34
    ],
35
    filterId: 'type',
36
    countSelectedValues: 0,
37
    filterType: 'checkbox',
38
    originalFilterId: '',
39
    valueIsExact: true,
40
    title: 'Result Types',
41
    filterOperator: 'or'
42
  };
43
  public resultsQuickFilter: { filter: Filter, selected: boolean, filterId: string, value: string } = {
44
    filter: null,
45
    selected: true,
46
    filterId: 'resultbestaccessright',
47
    value: 'Open Access'
48
  };
49
  public keyword: string = '';
50
  private timeouts: any[] = [];
51
  private subs: Subscription[] = [];
52
  
53
  constructor(
54
    private route: ActivatedRoute,
55
    private _router: Router,
56
    private location: Location, private _piwikService: PiwikService,
57
    private config: ConfigurationService, private _meta: Meta, private _title: Title, private seoService: SEOService
58
  ) {
59
    
60
    let description = 'OpenAIRE Research Graph is an open resource that aggregates a collection of research data properties (metadata, links) available within the OpenAIRE Open Science infrastructure for funders, organizations, researchers, research communities and publishers to interlink information by using a semantic graph database approach.';
61
    
62
    this._title.setTitle(this.pageTitle);
63
    this._meta.updateTag({content: description}, 'name="description"');
64
    this._meta.updateTag({content: description}, 'property="og:description"');
65
    this._meta.updateTag({content: this.pageTitle}, 'property="og:title"');
66
  }
67
  
68
  public ngOnInit() {
69
    if (this.properties) {
70
      let url = this.properties.domain + this.properties.baseLink + this._router.url;
71
      this.seoService.createLinkForCanonicalURL(url, false);
72
      this._meta.updateTag({content: url}, 'property=\'og:url\'');
73
      if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
74
        this.subs.push(this._piwikService.trackView(this.properties, this.pageTitle).subscribe());
75
      }
76
      this.animation();
77
    }
78
  }
79
  
80
  public ngOnDestroy() {
81
    this.subs.forEach(sub => {
82
      if(sub instanceof Subscription) {
83
        sub.unsubscribe();
84
      }
85
    });
86
    this.clearTimeouts();
87
  }
88
  
89
  private animation() {
90
    this.timeouts.push(setTimeout(() => {
91
      this.animation();
92
      if (this.state === (this.portals.length - 1)) {
93
        this.state = 0;
94
      } else {
95
        this.state++;
96
      }
97
    }, 4000));
98
  }
99
  
100
  entityChanged($event) {
101
    this.selectedEntity = $event.entity;
102
    this.url = $event.simpleUrl;
103
  }
104
  
105
  private changeSlide(slide: number) {
106
    this.clearTimeouts();
107
    this.state = slide;
108
    this.animation();
109
  }
110
  
111
  private clearTimeouts() {
112
    this.timeouts.forEach(timeout => {
113
      clearTimeout(timeout);
114
    });
115
    this.state = 0;
116
  }
117
  
118
  goTo() {
119
    let url = 'https://explore.openaire.eu' + this.url;
120
    let parameterNames = [];
121
    let parameterValues = [];
122
    if (this.selectedEntity == 'result') {
123
      if (this.resultTypes) {
124
        let values = [];
125
        for (let value of this.resultTypes.values) {
126
          if (value.selected) {
127
            values.push(value.id);
128
          }
129
        }
130
        if (values.length > 0 && values.length != 4) {
131
          parameterNames.push('type');
132
          parameterValues.push(values.join(','));
133
        }
134
        if (this.resultsQuickFilter && this.resultsQuickFilter.selected) {
135
          parameterNames.push(this.resultsQuickFilter.filterId);
136
          parameterValues.push('"'+ encodeURIComponent(this.resultsQuickFilter.value)+'"');
137
        }
138
      }
139
    } else if (this.selectedEntity == 'all') {
140
      if (this.resultsQuickFilter && this.resultsQuickFilter.selected) {
141
        parameterNames.push(this.resultsQuickFilter.filterId);
142
        parameterValues.push('"'+ encodeURIComponent(this.resultsQuickFilter.value)+'"');
143
      }
144
    }
145
    if (this.keyword.length > 0) {
146
      parameterNames.push('fv0');
147
      parameterValues.push(this.keyword);
148
      parameterNames.push('f0');
149
      parameterValues.push('q');
150
    }
151
    window.open(url + this.routerHelper.createQueryParamsString(parameterNames, parameterValues), '_blank').focus();
152
  }
153
}
(3-3/5)