Project

General

Profile

1
import {Component} 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 {Title, Meta} from '@angular/platform-browser';
7
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
8
import {SearchDataprovidersService} from '../openaireLibrary/services/searchDataproviders.service';
9
import {SearchProjectsService} from '../openaireLibrary/services/searchProjects.service';
10
import {SearchOrganizationsService} from '../openaireLibrary/services/searchOrganizations.service';
11
import {RefineFieldResultsService} from '../openaireLibrary/services/refineFieldResults.service';
12
import {NumberUtils} from '../openaireLibrary/utils/number-utils.class';
13

    
14
import {RouterHelper} from '../openaireLibrary/utils/routerHelper.class';
15
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
16
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
17
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
18
import {SEOService} from '../openaireLibrary/sharedComponents/SEO/SEO.service';
19
import {SearchResearchResultsService} from "../openaireLibrary/services/searchResearchResults.service";
20
import {properties} from "../../environments/environment";
21
import {portals} from "./portals";
22

    
23
@Component({
24
  selector: 'home',
25
  templateUrl: 'home.component.html',
26
  styleUrls: ['home.component.css']
27
})
28
export class HomeComponent {
29
  public pageTitle = "OpenAIRE - Research Graph";
30
  public publicationsSize: any = null;
31
  public datasetsSize: any = null;
32
  public datasetsLinkedSize: any = null;
33
  public softwareLinkedSize: any = null;
34
  public softwareSize: any = null;
35
  public otherSize: any = null;
36
  public fundersSize: any = null;
37
  public projectsSize: any = null;
38
  public datasourcesSize: any = null;
39
  public portals: any[] = portals;
40
  public state: number = 0;
41
  public properties: EnvProperties = properties;
42
  private timeouts: any[] = [];
43
  private subs: Subscription[] = [];
44
  
45
  constructor(
46
    private route: ActivatedRoute,
47
    private _router: Router,
48
    private _searchResearchResultsService: SearchResearchResultsService,
49
    private _searchDataprovidersService: SearchDataprovidersService,
50
    private _searchProjectsService: SearchProjectsService,
51
    private _searchOrganizationsService: SearchOrganizationsService,
52
    private _refineFieldResultsService: RefineFieldResultsService,
53
    private location: Location, private _piwikService: PiwikService,
54
    private config: ConfigurationService, private _meta: Meta, private _title: Title, private seoService: SEOService
55
  ) {
56
    
57
    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.";
58
    
59
    this._title.setTitle(this.pageTitle);
60
    this._meta.updateTag({content: description}, "name='description'");
61
    this._meta.updateTag({content: description}, "property='og:description'");
62
    this._meta.updateTag({content: this.pageTitle}, "property='og:title'");
63
  }
64
  
65
  public ngOnInit() {
66
    if (this.properties) {
67
      let url = this.properties.domain + this.properties.baseLink + this._router.url;
68
      this.seoService.createLinkForCanonicalURL(url, false);
69
      this._meta.updateTag({content: url}, "property='og:url'");
70
      if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
71
        this.subs.push(this._piwikService.trackView(this.properties, this.pageTitle).subscribe());
72
      }
73
      this.getNumbers();
74
      this.animation();
75
    }
76
  }
77
  
78
  public ngOnDestroy() {
79
    for (let sub of this.subs) {
80
      sub.unsubscribe();
81
    }
82
    this.clearTimeouts();
83
  }
84
  
85
  private animation() {
86
    this.timeouts.push(setTimeout(() => {
87
      this.animation();
88
      if (this.state === (this.portals.length -1)) {
89
        this.state = 0
90
      } else {
91
        this.state++;
92
      }
93
    }, 4000));
94
  }
95
  
96
  private changeSlide(slide: number) {
97
    this.clearTimeouts();
98
    this.state = slide;
99
    this.animation();
100
  }
101
  
102
  private clearTimeouts() {
103
    this.timeouts.forEach(timeout => {
104
      clearTimeout(timeout);
105
    });
106
    this.state = 0;
107
  }
108
  
109
  private getNumbers() {
110
    this.subs.push(this._searchResearchResultsService.numOfSearchResults("publication", "", this.properties).subscribe(
111
      data => {
112
        if (data && data > 0) {
113
          this.publicationsSize = NumberUtils.roundNumber(data);
114
          
115
        }
116
      },
117
      err => {
118
        this.handleError("Error getting number of publications", err);
119
      }
120
    ));
121
    this.subs.push(this._searchResearchResultsService.numOfSearchResults("dataset", "", this.properties).subscribe(
122
      data => {
123
        if (data && data > 0) {
124
          this.datasetsSize = NumberUtils.roundNumber(data);
125
        }
126
      },
127
      err => {
128
        //console.log(err);
129
        this.handleError("Error getting number of research data", err);
130
      }
131
    ));
132
    this.subs.push(this._searchResearchResultsService.numOfSearchResultsLinkedToPub("dataset", this.properties).subscribe(
133
      data => {
134
        if (data && data > 0) {
135
          this.datasetsLinkedSize = NumberUtils.roundNumber(data);
136
        }
137
      },
138
      err => {
139
        this.handleError("Error getting number of linkedresearch data", err);
140
      }
141
    ));
142
    this.subs.push(this._searchResearchResultsService.numOfSearchResults("software", "", this.properties).subscribe(
143
      data => {
144
        if (data && data > 0) {
145
          this.softwareSize = NumberUtils.roundNumber(data);
146
        }
147
      },
148
      err => {
149
        this.handleError("Error getting number of software data", err);
150
      }
151
    ));
152
    this.subs.push(this._searchResearchResultsService.numOfSearchResultsLinkedToPub("software", this.properties).subscribe(
153
      data => {
154
        if (data && data > 0) {
155
          this.softwareLinkedSize = NumberUtils.roundNumber(data);
156
        }
157
      },
158
      err => {
159
        this.handleError("Error getting number of linked software", err);
160
      }
161
    ));
162
    this.subs.push(this._searchResearchResultsService.numOfSearchResults("other", "", this.properties).subscribe(
163
      data => {
164
        if (data && data > 0) {
165
          this.otherSize = NumberUtils.roundNumber(data);
166
        }
167
      },
168
      err => {
169
        this.handleError("Error getting number of software data", err);
170
      }
171
    ));
172
    this.subs.push(this._refineFieldResultsService.getRefineFieldsResultsByEntityName(["funder"], "project", this.properties).subscribe(
173
      data => {
174
        
175
        
176
        if (data[0] && data[0] > 0) {
177
          this.projectsSize = NumberUtils.roundNumber(data[0]);
178
        }
179
        if (data[1].length > 0 && data[1][0].filterId == "funder" && data[1][0].values) {
180
          this.fundersSize = NumberUtils.roundNumber(data[1][0].values.length);
181
        }
182
        
183
      },
184
      err => {
185
        this.handleError("Error getting 'funder' field results of projects", err);
186
      })
187
    );
188
    
189
    this.subs.push(this._searchDataprovidersService.numOfSearchDataproviders("", this.properties).subscribe(
190
      data => {
191
        if (data && data > 0) {
192
          this.datasourcesSize = NumberUtils.roundNumber(data);
193
        }
194
        
195
      },
196
      err => {
197
        this.handleError("Error getting number of content providers", err);
198
      }
199
    ));
200
  }
201
  
202
  private handleError(message: string, error) {
203
    console.error("Home Page: " + message, error);
204
  }
205
}
(3-3/5)