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