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 'rxjs/add/observable/zip';
6
import {Meta, Title} from '@angular/platform-browser';
7
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
8
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
9
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
10
import {SEOService} from '../openaireLibrary/sharedComponents/SEO/SEO.service';
11
import {properties} from '../../environments/environment';
12
import {portals} from './portals';
13
import {Filter} from '../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class';
14
import {RouterHelper} from '../openaireLibrary/utils/routerHelper.class';
15

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