1
|
import {Component, Input, Output, EventEmitter, ViewChild, ChangeDetectionStrategy, ViewEncapsulation} from '@angular/core';
|
2
|
import {Observable} from 'rxjs/Observable';
|
3
|
import {ActivatedRoute, Router} from '@angular/router';
|
4
|
import {Location} from '@angular/common';
|
5
|
|
6
|
import { Meta, MetaDefinition} from '../../angular2-meta';
|
7
|
import {SearchPublicationsService} from '../services/searchPublications.service';
|
8
|
import {SearchDataprovidersService} from '../services/searchDataproviders.service';
|
9
|
import {SearchProjectsService} from '../services/searchProjects.service';
|
10
|
import {SearchDatasetsService} from '../services/searchDatasets.service';
|
11
|
import {SearchOrganizationsService} from '../services/searchOrganizations.service';
|
12
|
|
13
|
import {OpenaireProperties} from '../utils/properties/openaireProperties';
|
14
|
import {SearchFields} from '../utils/properties/searchFields';
|
15
|
import {ErrorCodes} from '../utils/properties/openaireProperties';
|
16
|
import {RouterHelper} from '../utils/routerHelper.class';
|
17
|
import {NumberUtils} from '../utils/number-utils.class';
|
18
|
import {RefineFieldResultsService} from '../services/refineFieldResults.service';
|
19
|
import {PiwikService} from '../utils/piwik/piwik.service';
|
20
|
import { ConfigurationService } from '../utils/configuration/configuration.service';
|
21
|
|
22
|
@Component({
|
23
|
selector: 'home',
|
24
|
templateUrl: 'home.component.html',
|
25
|
})
|
26
|
export class HomeComponent {
|
27
|
public piwiksub: any;
|
28
|
public subfunders: any;
|
29
|
|
30
|
public pageTitle = "OpenAIRE"
|
31
|
public keyword:string = "";
|
32
|
|
33
|
public searchFields:SearchFields = new SearchFields();
|
34
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
35
|
public routerHelper:RouterHelper = new RouterHelper();
|
36
|
|
37
|
public publicationsSize:any = null;
|
38
|
public datasetsSize:any = null;
|
39
|
public fundersSize:any = null;
|
40
|
public projectsSize:any = null;
|
41
|
public datasourcesSize:any = null;
|
42
|
|
43
|
showPublications:boolean= false;
|
44
|
showDatasets:boolean= false;
|
45
|
showProjects:boolean= false;
|
46
|
showDataProviders:boolean= false;
|
47
|
|
48
|
public subPub;public subData;public subProjects;public subOrg; public subDataPr;
|
49
|
|
50
|
constructor (
|
51
|
private route: ActivatedRoute,
|
52
|
private _router: Router,
|
53
|
private _searchPublicationsService: SearchPublicationsService,
|
54
|
private _searchDataprovidersService: SearchDataprovidersService,
|
55
|
private _searchProjectsService: SearchProjectsService,
|
56
|
private _searchDatasetsService: SearchDatasetsService,
|
57
|
private _searchOrganizationsService: SearchOrganizationsService,
|
58
|
private _refineFieldResultsService:RefineFieldResultsService,
|
59
|
private location: Location, private _meta: Meta,private _piwikService:PiwikService,
|
60
|
private config: ConfigurationService) {
|
61
|
|
62
|
var description = "open access, research, scientific publication, European Commission, EC, FP7, ERC, Horizon 2020, H2020, search, projects ";
|
63
|
|
64
|
var title = "OpenAIRE";
|
65
|
|
66
|
var url = OpenaireProperties.getBaseLink()+this._router.url;
|
67
|
this._meta.setTitle(title);
|
68
|
this._meta.updateMeta("description", description);
|
69
|
this._meta.updateProperty("og:description", description);
|
70
|
this._meta.updateProperty("og:title", title);
|
71
|
this._meta.updateProperty("og:url", url);
|
72
|
|
73
|
const entityOne = this.config.isEntityEnabled("publication");
|
74
|
const entityTwo = this.config.isEntityEnabled("dataset");
|
75
|
const entityThree = this.config.isEntityEnabled("project");
|
76
|
const entityFour = this.config.isEntityEnabled("datasource");
|
77
|
const example = Observable.zip(entityOne,entityTwo,entityThree,entityFour);
|
78
|
|
79
|
//wait until all observables have emitted a value then emit all as an array
|
80
|
example.subscribe(data => {
|
81
|
this.showPublications = data[0];
|
82
|
this.showDatasets = data[1];
|
83
|
this.showProjects = data[2];
|
84
|
this.showDataProviders = data[3];
|
85
|
this.getNumbers();
|
86
|
});
|
87
|
if(OpenaireProperties.isPiwikTrackEnabled() && (typeof document !== 'undefined')){
|
88
|
this.piwiksub = this._piwikService.trackView("OpenAIRE").subscribe();
|
89
|
}
|
90
|
|
91
|
}
|
92
|
|
93
|
public ngOnInit() {
|
94
|
}
|
95
|
public ngOnDestroy() {
|
96
|
if(this.piwiksub){
|
97
|
this.piwiksub.unsubscribe();
|
98
|
}
|
99
|
if(this.subfunders){
|
100
|
this.subfunders.unsubscribe();
|
101
|
}
|
102
|
if(this.subPub){
|
103
|
this.subPub.unsubscribe();
|
104
|
}
|
105
|
if(this.subData){
|
106
|
this.subData.unsubscribe();
|
107
|
}
|
108
|
// if(this.subProjects){
|
109
|
// this.subProjects.unsubscribe();
|
110
|
// }
|
111
|
// if(this.subOrg){
|
112
|
// this.subOrg.unsubscribe();
|
113
|
// }
|
114
|
if(this.subDataPr){
|
115
|
this.subDataPr.unsubscribe();
|
116
|
}
|
117
|
|
118
|
}
|
119
|
|
120
|
private getNumbers() {
|
121
|
if(this.showPublications){
|
122
|
this.subPub = this._searchPublicationsService.numOfSearchPublications("").subscribe(
|
123
|
data => {
|
124
|
console.log("Count results: "+data);
|
125
|
if(data && data != null && data > 0 ){
|
126
|
this.publicationsSize = NumberUtils.roundNumber(data);
|
127
|
console.log("After round");
|
128
|
|
129
|
}
|
130
|
},
|
131
|
err => {
|
132
|
console.log(err);
|
133
|
}
|
134
|
);
|
135
|
}
|
136
|
if(this.showDatasets){
|
137
|
this.subData = this._searchDatasetsService.numOfSearchDatasets("").subscribe(
|
138
|
data => {
|
139
|
if(data && data != null && data > 0 ){
|
140
|
this.datasetsSize = NumberUtils.roundNumber(data);
|
141
|
}
|
142
|
},
|
143
|
err => {
|
144
|
console.log(err);
|
145
|
}
|
146
|
);
|
147
|
}
|
148
|
if(this.showProjects){
|
149
|
this.subfunders = this._refineFieldResultsService.getRefineFieldsResultsByEntityName(["funder"],"project").subscribe(
|
150
|
data => {
|
151
|
|
152
|
console.info("Funders: "+data[1][0].title+ " values "+data[1][0].values.length+"]");
|
153
|
console.info("Projects: "+data[0]);
|
154
|
|
155
|
if(data[0] && data[0] > 0 ){
|
156
|
this.projectsSize = NumberUtils.roundNumber(data[0]);
|
157
|
}
|
158
|
if(data[1].length > 0 && data[1][0].filterId == "funder" && data[1][0].values ){
|
159
|
this.fundersSize = NumberUtils.roundNumber(data[1][0].values.length);
|
160
|
}
|
161
|
|
162
|
},
|
163
|
err => {
|
164
|
console.log(err);
|
165
|
});
|
166
|
}
|
167
|
if(this.showDataProviders){
|
168
|
this.subDataPr = this._searchDataprovidersService.numOfSearchDataproviders("").subscribe(
|
169
|
data => {
|
170
|
if(data && data != null && data > 0 ){
|
171
|
this.datasourcesSize = NumberUtils.roundNumber(data);
|
172
|
}
|
173
|
|
174
|
},
|
175
|
err => {
|
176
|
console.log(err);
|
177
|
|
178
|
}
|
179
|
);
|
180
|
}
|
181
|
}
|
182
|
}
|