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
|
|
8
|
import { FetchPublications } from '../../utils/fetchEntitiesClasses/fetchPublications.class';
|
9
|
import { FetchDataproviders } from '../../utils/fetchEntitiesClasses/fetchDataproviders.class';
|
10
|
import { FetchProjects } from '../../utils/fetchEntitiesClasses/fetchProjects.class';
|
11
|
import { FetchDatasets } from '../../utils/fetchEntitiesClasses/fetchDatasets.class';
|
12
|
import { FetchOrganizations } from '../../utils/fetchEntitiesClasses/fetchOrganizations.class';
|
13
|
|
14
|
import {SearchPublicationsService} from '../../services/searchPublications.service';
|
15
|
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
|
16
|
import {SearchProjectsService} from '../../services/searchProjects.service';
|
17
|
import {SearchDatasetsService} from '../../services/searchDatasets.service';
|
18
|
import {SearchOrganizationsService} from '../../services/searchOrganizations.service';
|
19
|
|
20
|
import {OpenaireProperties} from '../../utils/properties/openaireProperties';
|
21
|
import {SearchFields} from '../../utils/properties/searchFields';
|
22
|
import {ErrorCodes} from '../../utils/properties/openaireProperties';
|
23
|
import {RouterHelper} from '../../utils/routerHelper.class';
|
24
|
import {RefineFieldResultsService} from '../../services/refineFieldResults.service';
|
25
|
import {PiwikService} from '../../utils/piwik/piwik.service';
|
26
|
|
27
|
@Component({
|
28
|
changeDetection: ChangeDetectionStrategy.Default,
|
29
|
encapsulation: ViewEncapsulation.Emulated,
|
30
|
selector: 'search-find',
|
31
|
templateUrl: 'search.component.html'
|
32
|
})
|
33
|
export class SearchComponent {
|
34
|
public sub: any; piwiksub: any;
|
35
|
public reloadPublications: boolean;
|
36
|
public reloadDatasets: boolean;
|
37
|
public reloadProjects: boolean;
|
38
|
public reloadDataproviders: boolean;
|
39
|
public reloadOrganizations: boolean;
|
40
|
|
41
|
|
42
|
public pageTitle = "Search in OpenAIRE"
|
43
|
public keyword:string = "";
|
44
|
public publications:string[];
|
45
|
public datasets:string[];
|
46
|
public projectsTab:string[];
|
47
|
public dataproviders:string[];
|
48
|
public organizations:string[];
|
49
|
|
50
|
public activeTab = "publications";
|
51
|
public linkToSearchPublications = "";
|
52
|
public linkToSearchProjects = "";
|
53
|
public linkToSearchDataproviders = "";
|
54
|
public linkToSearchDatasets = "";
|
55
|
public linkToSearchOrganizations = "";
|
56
|
|
57
|
public fetchPublications : FetchPublications;
|
58
|
public fetchDataproviders : FetchDataproviders;
|
59
|
public fetchProjects : FetchProjects;
|
60
|
public fetchDatasets: FetchDatasets;
|
61
|
public fetchOrganizations: FetchOrganizations;
|
62
|
|
63
|
public searchFields:SearchFields = new SearchFields();
|
64
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
65
|
public routerHelper:RouterHelper = new RouterHelper();
|
66
|
|
67
|
public publicationsSize:any = null;
|
68
|
public datasetsSize:any = null;
|
69
|
public fundersSize:any = null;
|
70
|
public projectsSize:any = null;
|
71
|
public datasourcesSize:any = null;
|
72
|
|
73
|
public subPub;public subData;public subProjects;public subOrg; public subDataPr;
|
74
|
constructor ( private route: ActivatedRoute,
|
75
|
private _router: Router,
|
76
|
private _searchPublicationsService: SearchPublicationsService,
|
77
|
private _searchDataprovidersService: SearchDataprovidersService,
|
78
|
private _searchProjectsService: SearchProjectsService,
|
79
|
private _searchDatasetsService: SearchDatasetsService,
|
80
|
private _searchOrganizationsService: SearchOrganizationsService,
|
81
|
private _refineFieldResultsService:RefineFieldResultsService,
|
82
|
private location: Location, private _meta: Meta,private _piwikService:PiwikService ) {
|
83
|
this.fetchPublications = new FetchPublications(this._searchPublicationsService);
|
84
|
this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
|
85
|
this.fetchProjects = new FetchProjects(this._searchProjectsService);
|
86
|
this.fetchDatasets = new FetchDatasets( this._searchDatasetsService);
|
87
|
this.fetchOrganizations = new FetchOrganizations( this._searchOrganizationsService);
|
88
|
|
89
|
var description = "open access, research, scientific publication, European Commission, EC, FP7, ERC, Horizon 2020, H2020, search, projects ";
|
90
|
|
91
|
var title = "OpenAIRE | Search publications, research data, projects... | OpenAIRE";
|
92
|
|
93
|
var url = OpenaireProperties.getBaseLink()+this._router.url;
|
94
|
this._meta.setTitle(title);
|
95
|
this._meta.updateMeta("description", description);
|
96
|
this._meta.updateProperty("og:description", description);
|
97
|
this._meta.updateProperty("og:title", title);
|
98
|
this._meta.updateProperty("og:url", url);
|
99
|
if(OpenaireProperties.isPiwikTrackEnabled() && (typeof document !== 'undefined')){
|
100
|
this.piwiksub = this._piwikService.trackView("OpenAIRE |Search publications, research data, projects...").subscribe();
|
101
|
|
102
|
}
|
103
|
|
104
|
}
|
105
|
|
106
|
public ngOnInit() {
|
107
|
this.sub = this.route.queryParams.subscribe(params => {
|
108
|
this.keyword = (params['keyword'])?params['keyword']:"";
|
109
|
if(this.keyword !=null && this.keyword.length > 0){
|
110
|
this.reloadTabs();
|
111
|
this.activeTab = "publications";
|
112
|
this.searchPublications();
|
113
|
this.count();
|
114
|
}
|
115
|
});
|
116
|
|
117
|
}
|
118
|
public ngOnDestroy() {
|
119
|
this.sub.unsubscribe();
|
120
|
if(this.piwiksub){
|
121
|
this.piwiksub.unsubscribe();
|
122
|
}
|
123
|
if(this.keyword !=null && this.keyword.length > 0){
|
124
|
if(this.subPub){
|
125
|
this.subPub.unsubscribe();
|
126
|
}
|
127
|
if(this.subData){
|
128
|
this.subData.unsubscribe();
|
129
|
}
|
130
|
if(this.subProjects){
|
131
|
this.subProjects.unsubscribe();
|
132
|
}
|
133
|
if(this.subOrg){
|
134
|
this.subOrg.unsubscribe();
|
135
|
}
|
136
|
if(this.subDataPr){
|
137
|
this.subDataPr.unsubscribe();
|
138
|
}
|
139
|
|
140
|
}
|
141
|
}
|
142
|
public searchPublications() {
|
143
|
this.activeTab = "publications";
|
144
|
if( this.reloadPublications &&
|
145
|
( this.fetchPublications.searchUtils.status == this.errorCodes.LOADING ||
|
146
|
this.fetchPublications.searchUtils.status == this.errorCodes.DONE )) {
|
147
|
this.reloadPublications = false;
|
148
|
this.fetchPublications.getResultsByKeyword(this.keyword, 1, 10);
|
149
|
this.linkToSearchPublications = OpenaireProperties.getLinkToSearchPublications();// + "?keyword=" + this.keyword;
|
150
|
}
|
151
|
}
|
152
|
public searchDatasets() {
|
153
|
this.activeTab = "research data";
|
154
|
if(this.reloadDatasets &&
|
155
|
( this.fetchDatasets.searchUtils.status == this.errorCodes.LOADING ||
|
156
|
this.fetchDatasets.searchUtils.status == this.errorCodes.DONE )) {
|
157
|
this.reloadDatasets = false;
|
158
|
this.fetchDatasets.getResultsByKeyword(this.keyword, 1, 10);
|
159
|
this.linkToSearchDatasets = OpenaireProperties.getLinkToSearchDatasets();// + "?keyword=" + this.keyword;
|
160
|
}
|
161
|
}
|
162
|
public searchProjects() {
|
163
|
this.activeTab = "projects";
|
164
|
console.log("searchProjects");
|
165
|
if(this.reloadProjects &&
|
166
|
( this.fetchProjects.searchUtils.status == this.errorCodes.LOADING ||
|
167
|
this.fetchProjects.searchUtils.status == this.errorCodes.DONE )) {
|
168
|
this.reloadProjects = false;
|
169
|
console.log("do the search searchProjects");
|
170
|
|
171
|
this.fetchProjects.getResultsByKeyword(this.keyword, 1, 10);
|
172
|
this.linkToSearchProjects = OpenaireProperties.getLinkToSearchProjects();// + "?keyword=" + this.keyword;
|
173
|
}
|
174
|
}
|
175
|
public searchDataProviders() {
|
176
|
this.activeTab = "content providers";
|
177
|
if( this.reloadDataproviders &&
|
178
|
( this.fetchDataproviders.searchUtils.status == this.errorCodes.LOADING ||
|
179
|
this.fetchDataproviders.searchUtils.status == this.errorCodes.DONE )) {
|
180
|
this.reloadDataproviders = false;
|
181
|
this.fetchDataproviders.getResultsByKeyword(this.keyword, 1, 10);
|
182
|
this.linkToSearchDataproviders = OpenaireProperties.getLinkToSearchDataProviders();// + "?keyword=" + this.keyword;
|
183
|
}
|
184
|
}
|
185
|
public searchOrganizations() {
|
186
|
this.activeTab = "organizations";
|
187
|
if( this.reloadOrganizations &&
|
188
|
( this.fetchOrganizations.searchUtils.status == this.errorCodes.LOADING ||
|
189
|
this.fetchOrganizations.searchUtils.status == this.errorCodes.DONE )) {
|
190
|
this.reloadOrganizations = false;
|
191
|
this.fetchOrganizations.getResultsByKeyword(this.keyword, 1, 10);
|
192
|
this.linkToSearchOrganizations = OpenaireProperties.getLinkToSearchOrganizations();// + "?keyword=" + this.keyword;
|
193
|
}
|
194
|
}
|
195
|
|
196
|
|
197
|
public keywordChanged($event){
|
198
|
|
199
|
this.keyword = $event.value;
|
200
|
console.info("Search Find: search with keyword \"" + this.keyword + "\"" );
|
201
|
this.location.go(location.pathname,"?keyword=" + this.keyword);
|
202
|
this.reloadTabs();
|
203
|
if(this.activeTab == "publications") {
|
204
|
this.searchPublications();
|
205
|
}
|
206
|
if(this.activeTab == "projects") {
|
207
|
this.searchProjects();
|
208
|
}
|
209
|
if(this.activeTab == "content providers") {
|
210
|
this.searchDataProviders();
|
211
|
}
|
212
|
if(this.activeTab == "research data") {
|
213
|
this.searchDatasets();
|
214
|
}
|
215
|
if(this.activeTab == "organizations") {
|
216
|
this.searchOrganizations();
|
217
|
}
|
218
|
|
219
|
this.count();
|
220
|
}
|
221
|
|
222
|
private count() {
|
223
|
if(this.activeTab != "publications"){
|
224
|
this.fetchPublications.searchUtils.status = this.errorCodes.LOADING;
|
225
|
this.fetchPublications.results = [];
|
226
|
this.subPub = this._searchPublicationsService.numOfSearchPublications(this.keyword).subscribe(
|
227
|
data => {
|
228
|
console.log("Count results: "+data);
|
229
|
this.fetchPublications.searchUtils.totalResults = data;
|
230
|
this.fetchPublications.searchUtils.status = this.errorCodes.DONE;
|
231
|
if(this.fetchPublications.searchUtils.totalResults == 0) {
|
232
|
this.fetchPublications.searchUtils.status = this.errorCodes.NONE;
|
233
|
}
|
234
|
},
|
235
|
err => {
|
236
|
console.log(err);
|
237
|
if(err.status == '404') {
|
238
|
this.fetchPublications.searchUtils.status = this.errorCodes.NOT_FOUND;
|
239
|
} else if(err.status == '500') {
|
240
|
this.fetchPublications.searchUtils.status = this.errorCodes.ERROR;
|
241
|
} else {
|
242
|
this.fetchPublications.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
243
|
}
|
244
|
//this.fetchPublications.searchUtils.status = this.errorCodes.ERROR;
|
245
|
}
|
246
|
);
|
247
|
}
|
248
|
if(this.activeTab != "research data"){
|
249
|
this.fetchDatasets.searchUtils.status = this.errorCodes.LOADING;
|
250
|
this.fetchDatasets.results = [];
|
251
|
this.subData = this._searchDatasetsService.numOfSearchDatasets(this.keyword).subscribe(
|
252
|
data => {
|
253
|
this.fetchDatasets.searchUtils.totalResults = data;
|
254
|
this.fetchDatasets.searchUtils.status = this.errorCodes.DONE;
|
255
|
if(this.fetchDatasets.searchUtils.totalResults == 0) {
|
256
|
this.fetchDatasets.searchUtils.status = this.errorCodes.NONE;
|
257
|
}
|
258
|
},
|
259
|
err => {
|
260
|
console.log(err);
|
261
|
if(err.status == '404') {
|
262
|
this.fetchDatasets.searchUtils.status = this.errorCodes.NOT_FOUND;
|
263
|
} else if(err.status == '500') {
|
264
|
this.fetchDatasets.searchUtils.status = this.errorCodes.ERROR;
|
265
|
} else {
|
266
|
this.fetchDatasets.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
267
|
}
|
268
|
//this.fetchDatasets.searchUtils.status = this.errorCodes.ERROR;
|
269
|
}
|
270
|
);
|
271
|
}
|
272
|
if(this.activeTab != "projects"){
|
273
|
this.fetchProjects.searchUtils.status = this.errorCodes.LOADING;
|
274
|
this.fetchProjects.results = [];
|
275
|
this.subProjects = this._searchProjectsService.numOfSearchProjects(this.keyword).subscribe(
|
276
|
data => {
|
277
|
this.fetchProjects.searchUtils.totalResults = data;
|
278
|
this.fetchProjects.searchUtils.status = this.errorCodes.DONE;
|
279
|
if(this.fetchProjects.searchUtils.totalResults == 0) {
|
280
|
this.fetchProjects.searchUtils.status = this.errorCodes.NONE;
|
281
|
}
|
282
|
},
|
283
|
err => {
|
284
|
console.log(err);
|
285
|
if(err.status == '404') {
|
286
|
this.fetchProjects.searchUtils.status = this.errorCodes.NOT_FOUND;
|
287
|
} else if(err.status == '500') {
|
288
|
this.fetchProjects.searchUtils.status = this.errorCodes.ERROR;
|
289
|
} else {
|
290
|
this.fetchProjects.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
291
|
}
|
292
|
//this.fetchProjects.searchUtils.status = this.errorCodes.ERROR;
|
293
|
}
|
294
|
);
|
295
|
}
|
296
|
if(this.activeTab != "content providers"){
|
297
|
this.fetchDataproviders.results = [];
|
298
|
this.fetchDataproviders.getNumForSearch(this.keyword);
|
299
|
}
|
300
|
if(this.activeTab != "organizations"){
|
301
|
this.fetchOrganizations.searchUtils.status = this.errorCodes.LOADING;
|
302
|
this.fetchOrganizations.results = [];
|
303
|
this.subOrg = this._searchOrganizationsService.numOfSearchOrganizations(this.keyword).subscribe(
|
304
|
data => {
|
305
|
this.fetchOrganizations.searchUtils.totalResults = data;
|
306
|
this.fetchOrganizations.searchUtils.status = this.errorCodes.DONE;
|
307
|
if(this.fetchOrganizations.searchUtils.totalResults == 0) {
|
308
|
this.fetchOrganizations.searchUtils.status = this.errorCodes.NONE;
|
309
|
}
|
310
|
},
|
311
|
err => {
|
312
|
console.log(err);
|
313
|
if(err.status == '404') {
|
314
|
this.fetchOrganizations.searchUtils.status = this.errorCodes.NOT_FOUND;
|
315
|
} else if(err.status == '500') {
|
316
|
this.fetchOrganizations.searchUtils.status = this.errorCodes.ERROR;
|
317
|
} else {
|
318
|
this.fetchOrganizations.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
319
|
}
|
320
|
//this.fetchOrganizations.searchUtils.status = this.errorCodes.ERROR;
|
321
|
|
322
|
}
|
323
|
);
|
324
|
}
|
325
|
|
326
|
|
327
|
}
|
328
|
|
329
|
private reloadTabs() {
|
330
|
this.reloadPublications = true;
|
331
|
this.reloadDatasets = true;
|
332
|
this.reloadProjects = true;
|
333
|
this.reloadDataproviders = true;
|
334
|
this.reloadOrganizations = true;
|
335
|
}
|
336
|
|
337
|
|
338
|
|
339
|
}
|