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
|
import "rxjs/add/observable/zip";
|
6
|
import {Title, Meta} from '@angular/platform-browser';
|
7
|
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
|
8
|
import { SearchPublicationsService} from '../openaireLibrary/services/searchPublications.service';
|
9
|
import { FetchDataproviders} from '../openaireLibrary/utils/fetchEntitiesClasses/fetchDataproviders.class';
|
10
|
import { SearchDataprovidersService} from '../openaireLibrary/services/searchDataproviders.service';
|
11
|
import { SearchProjectsService} from '../openaireLibrary/services/searchProjects.service';
|
12
|
import { SearchDatasetsService} from '../openaireLibrary/services/searchDatasets.service';
|
13
|
import { SearchOrganizationsService} from '../openaireLibrary/services/searchOrganizations.service';
|
14
|
import { RefineFieldResultsService} from '../openaireLibrary/services/refineFieldResults.service';
|
15
|
import { SearchFields} from '../openaireLibrary/utils/properties/searchFields';
|
16
|
import { NumberUtils} from '../openaireLibrary/utils/number-utils.class';
|
17
|
|
18
|
import { RouterHelper} from '../openaireLibrary/utils/routerHelper.class';
|
19
|
import { EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
20
|
import { ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
|
21
|
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
|
22
|
|
23
|
@Component({
|
24
|
selector: 'home',
|
25
|
templateUrl: 'home.component.html',
|
26
|
})
|
27
|
export class HomeComponent {
|
28
|
public piwiksub: any;
|
29
|
public subfunders: any;
|
30
|
|
31
|
public pageTitle = "OpenAIRE"
|
32
|
public keyword:string = "";
|
33
|
|
34
|
public searchFields:SearchFields = new SearchFields();
|
35
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
36
|
public routerHelper:RouterHelper = new RouterHelper();
|
37
|
|
38
|
public publicationsSize:any = null;
|
39
|
public datasetsSize:any = null;
|
40
|
public fundersSize:any = null;
|
41
|
public projectsSize:any = null;
|
42
|
public datasourcesSize:any = null;
|
43
|
|
44
|
private numResults: number = 2;
|
45
|
public fetchDataproviders : FetchDataproviders;
|
46
|
|
47
|
showPublications:boolean= false;
|
48
|
showDatasets:boolean= false;
|
49
|
showProjects:boolean= false;
|
50
|
showDataProviders:boolean= false;
|
51
|
properties: EnvProperties;
|
52
|
public subPub;public subData;public subProjects;public subOrg; public subDataPr;
|
53
|
|
54
|
constructor (
|
55
|
private route: ActivatedRoute,
|
56
|
private _router: Router,
|
57
|
private _searchPublicationsService: SearchPublicationsService,
|
58
|
private _searchDataprovidersService: SearchDataprovidersService,
|
59
|
private _searchProjectsService: SearchProjectsService,
|
60
|
private _searchDatasetsService: SearchDatasetsService,
|
61
|
private _searchOrganizationsService: SearchOrganizationsService,
|
62
|
private _refineFieldResultsService:RefineFieldResultsService,
|
63
|
private location: Location, private _piwikService:PiwikService,
|
64
|
private config: ConfigurationService, private _meta: Meta, private _title: Title
|
65
|
) {
|
66
|
|
67
|
var description = "open access, research, scientific publication, European Commission, EC, FP7, ERC, Horizon 2020, H2020, search, projects ";
|
68
|
|
69
|
var title = "OpenAIRE";
|
70
|
|
71
|
this._title.setTitle(title);
|
72
|
this._meta.updateTag({content:description},"name='description'");
|
73
|
this._meta.updateTag({content:description},"property='og:description'");
|
74
|
this._meta.updateTag({content:title},"property='og:title'");
|
75
|
|
76
|
//this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
|
77
|
}
|
78
|
|
79
|
public ngOnInit() {
|
80
|
this.route.data
|
81
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
82
|
this.properties = data.envSpecific;
|
83
|
if(this.properties!=null){
|
84
|
var url = this.properties.baseLink+this._router.url;
|
85
|
this._meta.updateTag({content:url},"property='og:url'");
|
86
|
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
|
87
|
this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE").subscribe();
|
88
|
}
|
89
|
|
90
|
this.config.getCommunityInformation(this.properties.adminToolsAPIURL, this.properties.adminToolsCommunity ).subscribe(data => {
|
91
|
var showEntity = {};
|
92
|
for(var i=0; i< data.entities.length; i++){
|
93
|
|
94
|
showEntity[""+data.entities[i]["pid"]+""] = data.entities[i]["isEnabled"];
|
95
|
}
|
96
|
this.showPublications = showEntity["publication"];
|
97
|
this.showDatasets = showEntity["dataset"];
|
98
|
this.showProjects = showEntity["project"];
|
99
|
this.showDataProviders = showEntity["datasource"];
|
100
|
this.getNumbers();
|
101
|
// if(this.showDataProviders) {
|
102
|
// this.fetchDataproviders.getResultsForHome(this.numResults, this.properties);
|
103
|
// }
|
104
|
});
|
105
|
}
|
106
|
});
|
107
|
|
108
|
}
|
109
|
public ngOnDestroy() {
|
110
|
if(this.piwiksub){
|
111
|
this.piwiksub.unsubscribe();
|
112
|
}
|
113
|
if(this.subfunders){
|
114
|
this.subfunders.unsubscribe();
|
115
|
}
|
116
|
if(this.subPub){
|
117
|
this.subPub.unsubscribe();
|
118
|
}
|
119
|
if(this.subData){
|
120
|
this.subData.unsubscribe();
|
121
|
}
|
122
|
// if(this.subProjects){
|
123
|
// this.subProjects.unsubscribe();
|
124
|
// }
|
125
|
// if(this.subOrg){
|
126
|
// this.subOrg.unsubscribe();
|
127
|
// }
|
128
|
if(this.subDataPr){
|
129
|
this.subDataPr.unsubscribe();
|
130
|
}
|
131
|
|
132
|
}
|
133
|
|
134
|
private getNumbers() {
|
135
|
if(this.showPublications){
|
136
|
this.subPub = this._searchPublicationsService.numOfSearchPublications("", this.properties).subscribe(
|
137
|
data => {
|
138
|
if(data && data != null && data > 0 ){
|
139
|
this.publicationsSize = NumberUtils.roundNumber(data);
|
140
|
|
141
|
}
|
142
|
},
|
143
|
err => {
|
144
|
console.log(err);
|
145
|
}
|
146
|
);
|
147
|
}
|
148
|
if(this.showDatasets){
|
149
|
this.subData = this._searchDatasetsService.numOfSearchDatasets("", this.properties).subscribe(
|
150
|
data => {
|
151
|
if(data && data != null && data > 0 ){
|
152
|
this.datasetsSize = NumberUtils.roundNumber(data);
|
153
|
}
|
154
|
},
|
155
|
err => {
|
156
|
console.log(err);
|
157
|
}
|
158
|
);
|
159
|
}
|
160
|
if(this.showProjects){
|
161
|
this.subfunders = this._refineFieldResultsService.getRefineFieldsResultsByEntityName(["funder"],"project", this.properties).subscribe(
|
162
|
data => {
|
163
|
|
164
|
|
165
|
if(data[0] && data[0] > 0 ){
|
166
|
this.projectsSize = NumberUtils.roundNumber(data[0]);
|
167
|
}
|
168
|
if(data[1].length > 0 && data[1][0].filterId == "funder" && data[1][0].values ){
|
169
|
this.fundersSize = NumberUtils.roundNumber(data[1][0].values.length);
|
170
|
}
|
171
|
|
172
|
},
|
173
|
err => {
|
174
|
console.log(err);
|
175
|
});
|
176
|
}
|
177
|
if(this.showDataProviders){
|
178
|
this.subDataPr = this._searchDataprovidersService.numOfSearchDataproviders("", this.properties).subscribe(
|
179
|
data => {
|
180
|
if(data && data != null && data > 0 ){
|
181
|
this.datasourcesSize = NumberUtils.roundNumber(data);
|
182
|
}
|
183
|
|
184
|
},
|
185
|
err => {
|
186
|
console.log(err);
|
187
|
|
188
|
}
|
189
|
);
|
190
|
}
|
191
|
}
|
192
|
}
|