1
|
import {Component, Input, Output} from '@angular/core';
|
2
|
import {EventEmitter, ViewChild} from '@angular/core';
|
3
|
import {ChangeDetectionStrategy} from '@angular/core';
|
4
|
import {ViewEncapsulation} from '@angular/core';
|
5
|
import {ActivatedRoute, Router} from '@angular/router';
|
6
|
import {Location} from '@angular/common';
|
7
|
import {Title, Meta} from '@angular/platform-browser';
|
8
|
|
9
|
import {Observable} from 'rxjs/Observable';
|
10
|
|
11
|
import {FetchPublications} from '../../utils/fetchEntitiesClasses/fetchPublications.class';
|
12
|
import {FetchDataproviders} from '../../utils/fetchEntitiesClasses/fetchDataproviders.class';
|
13
|
import {FetchProjects} from '../../utils/fetchEntitiesClasses/fetchProjects.class';
|
14
|
import {FetchDatasets} from '../../utils/fetchEntitiesClasses/fetchDatasets.class';
|
15
|
import {FetchSoftware} from '../../utils/fetchEntitiesClasses/fetchSoftware.class';
|
16
|
import {FetchOrps} from '../../utils/fetchEntitiesClasses/fetchOrps.class';
|
17
|
import {FetchOrganizations} from '../../utils/fetchEntitiesClasses/fetchOrganizations.class';
|
18
|
|
19
|
import {SearchPublicationsService} from '../../services/searchPublications.service';
|
20
|
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
|
21
|
import {SearchProjectsService} from '../../services/searchProjects.service';
|
22
|
import {SearchDatasetsService} from '../../services/searchDatasets.service';
|
23
|
import {SearchSoftwareService} from '../../services/searchSoftware.service';
|
24
|
import {SearchOrpsService} from '../../services/searchOrps.service';
|
25
|
import {SearchOrganizationsService} from '../../services/searchOrganizations.service';
|
26
|
|
27
|
import {SearchFields, FieldDetails} from '../../utils/properties/searchFields';
|
28
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
29
|
import {RouterHelper} from '../../utils/routerHelper.class';
|
30
|
import {RefineFieldResultsService} from '../../services/refineFieldResults.service';
|
31
|
import {PiwikService} from '../../utils/piwik/piwik.service';
|
32
|
import {ConfigurationService} from '../../utils/configuration/configuration.service';
|
33
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
34
|
|
35
|
@Component({
|
36
|
changeDetection: ChangeDetectionStrategy.Default,
|
37
|
encapsulation: ViewEncapsulation.Emulated,
|
38
|
selector: 'search-find',
|
39
|
templateUrl: 'search.component.html'
|
40
|
})
|
41
|
export class SearchComponent {
|
42
|
public sub: any; piwiksub: any;
|
43
|
public reloadPublications: boolean;
|
44
|
public reloadDatasets: boolean;
|
45
|
public reloadSoftware: boolean;
|
46
|
public reloadOrps: boolean;
|
47
|
public reloadProjects: boolean;
|
48
|
public reloadDataproviders: boolean;
|
49
|
public reloadOrganizations: boolean;
|
50
|
|
51
|
|
52
|
public pageTitle = "Search in OpenAIRE"
|
53
|
public keyword:string = "";
|
54
|
public publications:string[];
|
55
|
public datasets:string[];
|
56
|
public software:string[];
|
57
|
public orps:string[];
|
58
|
public projectsTab:string[];
|
59
|
public dataproviders:string[];
|
60
|
public organizations:string[];
|
61
|
|
62
|
public activeTab = "publications";
|
63
|
public linkToSearchPublications = "";
|
64
|
public linkToSearchProjects = "";
|
65
|
public linkToSearchDataproviders = "";
|
66
|
public linkToSearchDatasets = "";
|
67
|
public linkToSearchSoftware = "";
|
68
|
public linkToSearchOrps = "";
|
69
|
public linkToSearchOrganizations = "";
|
70
|
|
71
|
public fetchPublications : FetchPublications;
|
72
|
public fetchDataproviders : FetchDataproviders;
|
73
|
public fetchProjects : FetchProjects;
|
74
|
public fetchDatasets: FetchDatasets;
|
75
|
public fetchSoftware: FetchSoftware;
|
76
|
public fetchOrps: FetchOrps;
|
77
|
public fetchOrganizations: FetchOrganizations;
|
78
|
|
79
|
public searchFields:SearchFields = new SearchFields();
|
80
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
81
|
public routerHelper:RouterHelper = new RouterHelper();
|
82
|
|
83
|
public publicationsSize:any = null;
|
84
|
public datasetsSize:any = null;
|
85
|
public softwareSize:any = null;
|
86
|
public oprsSize:any = null;
|
87
|
public fundersSize:any = null;
|
88
|
public projectsSize:any = null;
|
89
|
public datasourcesSize:any = null;
|
90
|
showPublications:boolean= false;
|
91
|
showDatasets:boolean= false;
|
92
|
showSoftware:boolean=false;
|
93
|
showOrps:boolean=false;
|
94
|
showProjects:boolean= false;
|
95
|
showDataProviders:boolean= false;
|
96
|
showOrganizations:boolean= false;
|
97
|
advancedSearchLink:string ="/search/advanced/publications";
|
98
|
properties: EnvProperties;
|
99
|
|
100
|
public subPub;public subData; public subSoftware; public subOrps; public subProjects;public subOrg; public subDataPr;
|
101
|
constructor ( private route: ActivatedRoute,
|
102
|
private _router: Router,
|
103
|
private _searchPublicationsService: SearchPublicationsService,
|
104
|
private _searchDataprovidersService: SearchDataprovidersService,
|
105
|
private _searchProjectsService: SearchProjectsService,
|
106
|
private _searchDatasetsService: SearchDatasetsService,
|
107
|
private _searchSoftwareService: SearchSoftwareService,
|
108
|
private _searchOrpsService: SearchOrpsService,
|
109
|
private _searchOrganizationsService: SearchOrganizationsService,
|
110
|
private _refineFieldResultsService:RefineFieldResultsService,
|
111
|
private location: Location,
|
112
|
private _meta: Meta,
|
113
|
private _title: Title,
|
114
|
private _piwikService:PiwikService,
|
115
|
private config: ConfigurationService ) {
|
116
|
this.fetchPublications = new FetchPublications(this._searchPublicationsService);
|
117
|
this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
|
118
|
this.fetchProjects = new FetchProjects(this._searchProjectsService);
|
119
|
this.fetchDatasets = new FetchDatasets( this._searchDatasetsService);
|
120
|
this.fetchSoftware = new FetchSoftware(this._searchSoftwareService);
|
121
|
this.fetchOrps = new FetchOrps( this._searchOrpsService);
|
122
|
this.fetchOrganizations = new FetchOrganizations( this._searchOrganizationsService);
|
123
|
|
124
|
}
|
125
|
|
126
|
public ngOnInit() {
|
127
|
this.route.data
|
128
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
129
|
|
130
|
var description = "open access, research, scientific publication, European Commission, EC, FP7, ERC, Horizon 2020, H2020, search, projects ";
|
131
|
var title = "OpenAIRE | Search publications, research data, projects... | OpenAIRE";
|
132
|
this.properties = data.envSpecific;
|
133
|
var url = data.envSpecific.baseLink+this._router.url;
|
134
|
this._title.setTitle(title);
|
135
|
this._meta.updateTag({content:description},"name='description'");
|
136
|
this._meta.updateTag({content:description},"property='og:description'");
|
137
|
this._meta.updateTag({content:title},"property='og:title'");
|
138
|
this._meta.updateTag({content:url},"property='og:url'");
|
139
|
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
|
140
|
this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE |Search publications, research data, projects...").subscribe();
|
141
|
|
142
|
}
|
143
|
|
144
|
|
145
|
|
146
|
this.config.getCommunityInformation(this.properties.adminToolsAPIURL, this.properties.adminToolsCommunity ).subscribe(data => {
|
147
|
var showEntity = {};
|
148
|
for(var i=0; i< data.entities.length; i++){
|
149
|
|
150
|
showEntity[""+data.entities[i]["pid"]+""] = data.entities[i]["isEnabled"];
|
151
|
}
|
152
|
this.showPublications = showEntity["publication"];
|
153
|
this.showDatasets = showEntity["dataset"];
|
154
|
this.showProjects = showEntity["project"];
|
155
|
this.showOrganizations = showEntity["organization"];
|
156
|
this.showDataProviders = showEntity["datasource"];
|
157
|
this.showSoftware = showEntity["software"];
|
158
|
this.showOrps = showEntity["other"];
|
159
|
|
160
|
this.sub = this.route.queryParams.subscribe(params => {
|
161
|
|
162
|
this.keyword = (params['keyword'])?params['keyword']:"";
|
163
|
if(this.keyword !=null && this.keyword.length > 0){
|
164
|
this.reloadTabs();
|
165
|
//if showPublications == false will set another entity as the first
|
166
|
if(this.showPublications){
|
167
|
this.activeTab = "publications";
|
168
|
this.searchPublications();
|
169
|
}else if(this.showDatasets){
|
170
|
this.activeTab = "research data";
|
171
|
this.searchDatasets();
|
172
|
}else if(this.showSoftware){
|
173
|
this.activeTab = "software";
|
174
|
this.searchSoftware();
|
175
|
}else if(this.showOrps){
|
176
|
this.activeTab = "other research products";
|
177
|
this.searchOrps();
|
178
|
}else if(this.showProjects){
|
179
|
this.activeTab = "projects";
|
180
|
this.searchProjects();
|
181
|
}else if(this.showDataProviders){
|
182
|
this.activeTab = "content providers";
|
183
|
this.searchDataProviders();
|
184
|
}else if(this.showOrganizations){
|
185
|
this.activeTab = "organizations";
|
186
|
this.searchOrganizations();
|
187
|
}
|
188
|
this.count();
|
189
|
}
|
190
|
});
|
191
|
});
|
192
|
});
|
193
|
}
|
194
|
|
195
|
|
196
|
|
197
|
|
198
|
public ngOnDestroy() {
|
199
|
if(this.sub){
|
200
|
this.sub.unsubscribe();
|
201
|
}
|
202
|
if(this.piwiksub){
|
203
|
this.piwiksub.unsubscribe();
|
204
|
}
|
205
|
if(this.keyword !=null && this.keyword.length > 0){
|
206
|
if(this.subPub){
|
207
|
this.subPub.unsubscribe();
|
208
|
}
|
209
|
if(this.subData){
|
210
|
this.subData.unsubscribe();
|
211
|
}
|
212
|
if(this.subSoftware){
|
213
|
this.subSoftware.unsubscribe();
|
214
|
}
|
215
|
if(this.subOrps){
|
216
|
this.subOrps.unsubscribe();
|
217
|
}
|
218
|
if(this.subProjects){
|
219
|
this.subProjects.unsubscribe();
|
220
|
}
|
221
|
if(this.subOrg){
|
222
|
this.subOrg.unsubscribe();
|
223
|
}
|
224
|
if(this.subDataPr){
|
225
|
this.subDataPr.unsubscribe();
|
226
|
}
|
227
|
|
228
|
}
|
229
|
}
|
230
|
public searchPublications() {
|
231
|
this.activeTab = "publications";
|
232
|
this.advancedSearchLink ="/search/advanced/publications";
|
233
|
if( this.reloadPublications &&
|
234
|
this.fetchPublications.searchUtils.status != this.errorCodes.NONE &&
|
235
|
this.fetchPublications.searchUtils.status != this.errorCodes.ERROR) {
|
236
|
this.reloadPublications = false;
|
237
|
this.fetchPublications.getResultsByKeyword(this.keyword, 1, 10,this.properties);
|
238
|
this.linkToSearchPublications = this.properties.searchLinkToPublications;// + "?keyword=" + this.keyword;
|
239
|
}
|
240
|
}
|
241
|
public searchDatasets() {
|
242
|
this.activeTab = "research data";
|
243
|
this.advancedSearchLink ="/search/advanced/datasets";
|
244
|
if(this.reloadDatasets &&
|
245
|
this.fetchDatasets.searchUtils.status != this.errorCodes.NONE &&
|
246
|
this.fetchDatasets.searchUtils.status != this.errorCodes.ERROR) {
|
247
|
this.reloadDatasets = false;
|
248
|
this.fetchDatasets.getResultsByKeyword(this.keyword, 1, 10,this.properties);
|
249
|
this.linkToSearchDatasets =this.properties.searchLinkToDatasets;// + "?keyword=" + this.keyword;
|
250
|
}
|
251
|
}
|
252
|
public searchSoftware() {
|
253
|
console.info("searchOrps: reload: "+ this.reloadSoftware, this.fetchSoftware.searchUtils.status);
|
254
|
|
255
|
this.activeTab = "software";
|
256
|
this.advancedSearchLink ="/search/advanced/software";
|
257
|
if(this.reloadSoftware &&
|
258
|
( this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING ||
|
259
|
this.fetchSoftware.searchUtils.status == this.errorCodes.DONE )) {
|
260
|
this.reloadSoftware = false;
|
261
|
this.fetchSoftware.getResultsByKeyword(this.keyword, 1, 10,this.properties);
|
262
|
this.linkToSearchSoftware = this.properties.searchLinkToSoftware;// + "?keyword=" + this.keyword;
|
263
|
}
|
264
|
}
|
265
|
public searchOrps() {
|
266
|
console.info("searchOrps: reload: "+ this.reloadOrps, this.fetchOrps.searchUtils.status);
|
267
|
this.activeTab = "other research products";
|
268
|
this.advancedSearchLink ="/search/advanced/other";
|
269
|
if(this.reloadOrps &&
|
270
|
this.fetchOrps.searchUtils.status != this.errorCodes.NONE &&
|
271
|
this.fetchOrps.searchUtils.status != this.errorCodes.ERROR) {
|
272
|
this.reloadOrps = false;
|
273
|
this.fetchOrps.getResultsByKeyword(this.keyword, 1, 10,this.properties);
|
274
|
this.linkToSearchOrps =this.properties.searchLinkToOrps;
|
275
|
}
|
276
|
}
|
277
|
public searchProjects() {
|
278
|
this.activeTab = "projects";
|
279
|
this.advancedSearchLink ="/search/advanced/projects";
|
280
|
if(this.reloadProjects &&
|
281
|
this.fetchProjects.searchUtils.status != this.errorCodes.NONE &&
|
282
|
this.fetchProjects.searchUtils.status != this.errorCodes.ERROR) {
|
283
|
this.reloadProjects = false;
|
284
|
this.fetchProjects.getResultsByKeyword(this.keyword, 1, 10,this.properties);
|
285
|
this.linkToSearchProjects = this.properties.searchLinkToProjects;// + "?keyword=" + this.keyword;
|
286
|
}
|
287
|
}
|
288
|
public searchDataProviders() {
|
289
|
this.activeTab = "content providers";
|
290
|
this.advancedSearchLink ="/search/advanced/dataproviders";
|
291
|
if( this.reloadDataproviders &&
|
292
|
this.fetchDataproviders.searchUtils.status != this.errorCodes.NONE &&
|
293
|
this.fetchDataproviders.searchUtils.status != this.errorCodes.ERROR) {
|
294
|
this.reloadDataproviders = false;
|
295
|
this.fetchDataproviders.getResultsByKeyword(this.keyword, 1, 10,this.properties);
|
296
|
this.linkToSearchDataproviders = this.properties.searchLinkToDataProviders;// + "?keyword=" + this.keyword;
|
297
|
}
|
298
|
}
|
299
|
public searchOrganizations() {
|
300
|
this.activeTab = "organizations";
|
301
|
this.advancedSearchLink ="/search/advanced/organizations";
|
302
|
if( this.reloadOrganizations &&
|
303
|
this.fetchOrganizations.searchUtils.status != this.errorCodes.NONE &&
|
304
|
this.fetchOrganizations.searchUtils.status != this.errorCodes.ERROR) {
|
305
|
this.reloadOrganizations = false;
|
306
|
this.fetchOrganizations.getResultsByKeyword(this.keyword, 1, 10,this.properties);
|
307
|
this.linkToSearchOrganizations = this.properties.searchLinkToOrganizations;// + "?keyword=" + this.keyword;
|
308
|
}
|
309
|
}
|
310
|
|
311
|
|
312
|
public keywordChanged($event){
|
313
|
|
314
|
this.keyword = $event.value;
|
315
|
console.info("Search Find: search with keyword \"" + this.keyword + "\"" );
|
316
|
this.location.go(location.pathname,"?keyword=" + this.keyword);
|
317
|
this.reloadTabs();
|
318
|
if(this.activeTab == "publications") {
|
319
|
this.searchPublications();
|
320
|
}
|
321
|
if(this.activeTab == "projects") {
|
322
|
this.searchProjects();
|
323
|
}
|
324
|
if(this.activeTab == "content providers") {
|
325
|
this.searchDataProviders();
|
326
|
}
|
327
|
if(this.activeTab == "research data") {
|
328
|
this.searchDatasets();
|
329
|
}
|
330
|
if(this.activeTab == "software") {
|
331
|
this.searchSoftware();
|
332
|
}
|
333
|
if(this.activeTab == "other research products") {
|
334
|
this.searchOrps();
|
335
|
}
|
336
|
if(this.activeTab == "organizations") {
|
337
|
this.searchOrganizations();
|
338
|
}
|
339
|
|
340
|
this.count();
|
341
|
}
|
342
|
|
343
|
private count() {
|
344
|
if(this.activeTab != "publications" && this.showPublications){
|
345
|
this.fetchPublications.searchUtils.status = this.errorCodes.LOADING;
|
346
|
this.fetchPublications.results = [];
|
347
|
this.subPub = this._searchPublicationsService.numOfSearchPublications(this.keyword,this.properties).subscribe(
|
348
|
data => {
|
349
|
console.log("Count results: "+data);
|
350
|
this.fetchPublications.searchUtils.totalResults = data;
|
351
|
this.fetchPublications.searchUtils.status = this.errorCodes.DONE;
|
352
|
if(this.fetchPublications.searchUtils.totalResults == 0) {
|
353
|
this.fetchPublications.searchUtils.status = this.errorCodes.NONE;
|
354
|
}
|
355
|
},
|
356
|
err => {
|
357
|
console.log(err);
|
358
|
this.fetchPublications.searchUtils.status = this.errorCodes.ERROR;
|
359
|
}
|
360
|
);
|
361
|
}
|
362
|
if(this.activeTab != "research data" && this.showDatasets){
|
363
|
this.fetchDatasets.searchUtils.status = this.errorCodes.LOADING;
|
364
|
this.fetchDatasets.results = [];
|
365
|
this.subData = this._searchDatasetsService.numOfSearchDatasets(this.keyword,this.properties).subscribe(
|
366
|
data => {
|
367
|
this.fetchDatasets.searchUtils.totalResults = data;
|
368
|
this.fetchDatasets.searchUtils.status = this.errorCodes.DONE;
|
369
|
if(this.fetchDatasets.searchUtils.totalResults == 0) {
|
370
|
this.fetchDatasets.searchUtils.status = this.errorCodes.NONE;
|
371
|
}
|
372
|
},
|
373
|
err => {
|
374
|
console.log(err);
|
375
|
this.fetchDatasets.searchUtils.status = this.errorCodes.ERROR;
|
376
|
}
|
377
|
);
|
378
|
}
|
379
|
if(this.activeTab != "software" && this.showSoftware){
|
380
|
this.fetchSoftware.searchUtils.status = this.errorCodes.LOADING;
|
381
|
this.fetchSoftware.results = [];
|
382
|
this.subSoftware = this._searchSoftwareService.numOfSearchSoftware(this.keyword,this.properties).subscribe(
|
383
|
data => {
|
384
|
this.fetchSoftware.searchUtils.totalResults = data;
|
385
|
this.fetchSoftware.searchUtils.status = this.errorCodes.DONE;
|
386
|
if(this.fetchSoftware.searchUtils.totalResults == 0) {
|
387
|
this.fetchSoftware.searchUtils.status = this.errorCodes.NONE;
|
388
|
}
|
389
|
},
|
390
|
err => {
|
391
|
console.log(err);
|
392
|
if(err.status == '404') {
|
393
|
this.fetchSoftware.searchUtils.status = this.errorCodes.NOT_FOUND;
|
394
|
} else if(err.status == '500') {
|
395
|
this.fetchSoftware.searchUtils.status = this.errorCodes.ERROR;
|
396
|
} else {
|
397
|
this.fetchSoftware.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
398
|
}
|
399
|
//this.fetchSoftware.searchUtils.status = this.errorCodes.ERROR;
|
400
|
}
|
401
|
);
|
402
|
}
|
403
|
if(this.activeTab != "other research products" && this.showOrps){
|
404
|
this.fetchOrps.searchUtils.status = this.errorCodes.LOADING;
|
405
|
this.fetchOrps.results = [];
|
406
|
this.subOrps = this._searchOrpsService.numOfSearchOrps(this.keyword,this.properties).subscribe(
|
407
|
data => {
|
408
|
this.fetchOrps.searchUtils.totalResults = data;
|
409
|
this.fetchOrps.searchUtils.status = this.errorCodes.DONE;
|
410
|
if(this.fetchOrps.searchUtils.totalResults == 0) {
|
411
|
this.fetchOrps.searchUtils.status = this.errorCodes.NONE;
|
412
|
}
|
413
|
},
|
414
|
err => {
|
415
|
console.log(err);
|
416
|
this.fetchOrps.searchUtils.status = this.errorCodes.ERROR;
|
417
|
}
|
418
|
);
|
419
|
}
|
420
|
if(this.activeTab != "projects" && this.showProjects){
|
421
|
this.fetchProjects.searchUtils.status = this.errorCodes.LOADING;
|
422
|
this.fetchProjects.results = [];
|
423
|
this.subProjects = this._searchProjectsService.numOfSearchProjects(this.keyword,this.properties).subscribe(
|
424
|
data => {
|
425
|
this.fetchProjects.searchUtils.totalResults = data;
|
426
|
this.fetchProjects.searchUtils.status = this.errorCodes.DONE;
|
427
|
if(this.fetchProjects.searchUtils.totalResults == 0) {
|
428
|
this.fetchProjects.searchUtils.status = this.errorCodes.NONE;
|
429
|
}
|
430
|
},
|
431
|
err => {
|
432
|
console.log(err);
|
433
|
this.fetchProjects.searchUtils.status = this.errorCodes.ERROR;
|
434
|
}
|
435
|
);
|
436
|
}
|
437
|
if(this.activeTab != "content providers" && this.showDataProviders){
|
438
|
this.fetchDataproviders.results = [];
|
439
|
this.fetchDataproviders.getNumForSearch(this.keyword,this.properties);
|
440
|
}
|
441
|
if(this.activeTab != "organizations" && this.showOrganizations){
|
442
|
this.fetchOrganizations.searchUtils.status = this.errorCodes.LOADING;
|
443
|
this.fetchOrganizations.results = [];
|
444
|
this.subOrg = this._searchOrganizationsService.numOfSearchOrganizations(this.keyword,this.properties).subscribe(
|
445
|
data => {
|
446
|
this.fetchOrganizations.searchUtils.totalResults = data;
|
447
|
this.fetchOrganizations.searchUtils.status = this.errorCodes.DONE;
|
448
|
if(this.fetchOrganizations.searchUtils.totalResults == 0) {
|
449
|
this.fetchOrganizations.searchUtils.status = this.errorCodes.NONE;
|
450
|
}
|
451
|
},
|
452
|
err => {
|
453
|
console.log(err);
|
454
|
this.fetchOrganizations.searchUtils.status = this.errorCodes.ERROR;
|
455
|
|
456
|
}
|
457
|
);
|
458
|
}
|
459
|
|
460
|
|
461
|
}
|
462
|
|
463
|
private reloadTabs() {
|
464
|
this.reloadPublications = true;
|
465
|
this.reloadDatasets = true;
|
466
|
this.reloadSoftware = true;
|
467
|
this.reloadOrps = true;
|
468
|
this.reloadProjects = true;
|
469
|
this.reloadDataproviders = true;
|
470
|
this.reloadOrganizations = true;
|
471
|
}
|
472
|
|
473
|
|
474
|
|
475
|
}
|