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
|
|
7
|
import { FetchPublications } from '../../utils/fetchEntitiesClasses/fetchPublications.class';
|
8
|
import { FetchDataproviders } from '../../utils/fetchEntitiesClasses/fetchDataproviders.class';
|
9
|
import { FetchProjects } from '../../utils/fetchEntitiesClasses/fetchProjects.class';
|
10
|
import { FetchDatasets } from '../../utils/fetchEntitiesClasses/fetchDatasets.class';
|
11
|
import { FetchOrganizations } from '../../utils/fetchEntitiesClasses/fetchOrganizations.class';
|
12
|
import { FetchPeople } from '../../utils/fetchEntitiesClasses/fetchPeople.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 {SearchPeopleService} from '../../services/searchPeople.service';
|
19
|
import {SearchOrganizationsService} from '../../services/searchOrganizations.service';
|
20
|
|
21
|
import {OpenaireProperties} from '../../utils/properties/openaireProperties';
|
22
|
import {SearchFields} from '../../utils/properties/searchFields';
|
23
|
|
24
|
@Component({
|
25
|
changeDetection: ChangeDetectionStrategy.Default,
|
26
|
encapsulation: ViewEncapsulation.Emulated,
|
27
|
selector: 'search-find',
|
28
|
template: `
|
29
|
<div class="uk-margin-top">
|
30
|
<div class="page-header">
|
31
|
<h1>{{pageTitle}}</h1>
|
32
|
</div>
|
33
|
<div class="uk-grid">
|
34
|
<div class="uk-width-1-1 uk-margin uk-panel uk-panel-box uk-panel-box-default">
|
35
|
|
36
|
<search-form [(keyword)]=keyword (keywordChange)="keywordChanged($event)"></search-form>
|
37
|
</div>
|
38
|
<div class=" uk-grid uk-margin-top uk-width-1-1">
|
39
|
|
40
|
<ul class="uk-tab uk-tab-left uk-width-large-1-5 uk-width-small-1-1 " data-uk-switcher="{connect:'#searchtabs'}">
|
41
|
<li (click)="searchPublications()" >
|
42
|
<a href="#pubsTab">
|
43
|
Publications {{((keyword.length > 0)?'('+fetchPublications.searchUtils.totalResults+')':'')}}
|
44
|
</a>
|
45
|
</li>
|
46
|
<li (click)="searchDatasets()">
|
47
|
<a href="#dataTab" (click)="searchDatasets()">
|
48
|
Datasets {{((keyword.length > 0)?'('+fetchDatasets.searchUtils.totalResults+')':'')}}
|
49
|
</a>
|
50
|
</li>
|
51
|
<li (click)="searchProjects()" >
|
52
|
<a href="#projectsTab">
|
53
|
Projects {{((keyword.length > 0)?'('+fetchProjects.searchUtils.totalResults+')':'')}}
|
54
|
</a>
|
55
|
</li>
|
56
|
<li (click)="searchDataProviders()" >
|
57
|
<a href="#dataProviderTab">
|
58
|
Data Providers {{((keyword.length > 0)?'('+fetchDataproviders.searchUtils.totalResults+')':'')}}
|
59
|
</a>
|
60
|
</li>
|
61
|
<li (click)="searchOrganizations()" >
|
62
|
<a href="#organizationsTab" >
|
63
|
Organizations {{((keyword.length > 0)?'('+fetchOrganizations.searchUtils.totalResults+')':'')}}
|
64
|
</a>
|
65
|
</li>
|
66
|
<li (click)="searchPeople()" >
|
67
|
<a href="#peopleTab" >
|
68
|
People {{((keyword.length > 0)?'('+fetchPeople.searchUtils.totalResults+')':'')}}
|
69
|
</a>
|
70
|
</li>
|
71
|
|
72
|
|
73
|
|
74
|
</ul>
|
75
|
|
76
|
<ul id="searchtabs" class="uk-switcher uk-margin-left uk-width-large-3-4 uk-width-small-1-1">
|
77
|
<li id="pubsTab" class="uk-active">
|
78
|
<div *ngIf = "keyword.length > 0" class ="uk-animation-fade">
|
79
|
<div class = "uk-text-right" *ngIf = "fetchPublications.searchUtils.totalResults> 10" ><a [href] = "linkToSearchPublications" >View all {{fetchPublications.searchUtils.totalResults}} results</a></div>
|
80
|
<search-result [(results)]="fetchPublications.results" [(status)]= "fetchPublications.status"></search-result>
|
81
|
</div>
|
82
|
<div *ngIf = "keyword.length == 0 && activeTab=='publications'" class ="uk-animation-fade" >
|
83
|
<browse-entities entityName="publication" baseUrl="/search/find/publications" [refineFields]=searchFields.RESULT_REFINE_FIELDS></browse-entities>
|
84
|
</div>
|
85
|
</li>
|
86
|
<li id="dataTab">
|
87
|
<div *ngIf = "keyword.length > 0" class ="uk-animation-fade">
|
88
|
<div class = "uk-text-right" *ngIf = "fetchDatasets.searchUtils.totalResults> 10" ><a [href] = "linkToSearchDatasets" >View all {{fetchDatasets.searchUtils.totalResults}} results</a></div>
|
89
|
<search-result [(results)]="fetchDatasets.results" [(status)]= "fetchDatasets.status"></search-result>
|
90
|
</div>
|
91
|
<div *ngIf = "keyword.length == 0 && activeTab=='datasets'" class ="uk-animation-fade">
|
92
|
<browse-entities entityName="dataset" baseUrl="/search/find/datasets" [refineFields]=searchFields.RESULT_REFINE_FIELDS></browse-entities>
|
93
|
</div>
|
94
|
</li>
|
95
|
<li id="projectsTab" >
|
96
|
<div *ngIf = "keyword.length > 0" class ="uk-animation-fade">
|
97
|
<div class = "uk-text-right" *ngIf = "fetchProjects.searchUtils.totalResults> 10" ><a [href] = "linkToSearchProjects" >View all {{fetchProjects.searchUtils.totalResults}} results</a></div>
|
98
|
<search-result [(results)]="fetchProjects.results" [(status)]= "fetchProjects.status"></search-result>
|
99
|
</div>
|
100
|
<div *ngIf = "keyword.length == 0 && activeTab=='projects'" class ="uk-animation-fade">
|
101
|
<browse-entities entityName="project" baseUrl="/search/find/projects" [refineFields]=searchFields.PROJECT_REFINE_FIELDS></browse-entities>
|
102
|
</div>
|
103
|
</li>
|
104
|
<li id="dataProviderTab">
|
105
|
<div *ngIf = "keyword.length > 0" class ="uk-animation-fade">
|
106
|
<div class = "uk-text-right" *ngIf = "fetchDataproviders.searchUtils.totalResults> 10" ><a [href] = "linkToSearchDataproviders" >View all {{fetchDataproviders.searchUtils.totalResults}} results</a></div>
|
107
|
<search-result [(results)]="fetchDataproviders.results" [(status)]= "fetchDataproviders.status"></search-result>
|
108
|
</div>
|
109
|
<div *ngIf = "keyword.length == 0 && activeTab=='dataproviders'" class ="uk-animation-fade" >
|
110
|
<browse-entities entityName="dataprovider" baseUrl="/search/find/dataproviders" [refineFields]=searchFields.DATASOURCE_REFINE_FIELDS></browse-entities>
|
111
|
</div>
|
112
|
</li>
|
113
|
<li id="organizationsTab" >
|
114
|
<div *ngIf = "keyword.length > 0" class ="uk-animation-fade">
|
115
|
<div class = "uk-text-right" *ngIf = "fetchOrganizations.searchUtils.totalResults> 10" ><a [href] = "linkToSearchOrganizations" >View all {{fetchOrganizations.searchUtils.totalResults}} results</a></div>
|
116
|
<search-result [(results)]="fetchOrganizations.results" [(status)]= "fetchOrganizations.status"></search-result>
|
117
|
</div>
|
118
|
<div *ngIf = "keyword.length == 0 && activeTab=='organizations'" class ="uk-animation-fade">
|
119
|
<browse-entities entityName="organization" baseUrl="/search/find/organizations" [refineFields]=searchFields.ORGANIZATION_REFINE_FIELDS></browse-entities>
|
120
|
</div>
|
121
|
</li>
|
122
|
<li id="peopleTab">
|
123
|
<div *ngIf = "keyword.length > 0" class ="uk-animation-fade">
|
124
|
<div class = "uk-text-right" *ngIf = "fetchPeople.searchUtils.totalResults> 10" ><a [href] = "linkToSearchPeople" >View all {{fetchPeople.searchUtils.totalResults}} results</a></div>
|
125
|
<search-result [(results)]="fetchPeople.results" [(status)]= "fetchPeople.status"></search-result>
|
126
|
</div>
|
127
|
<div *ngIf = "keyword.length == 0 && activeTab=='people'" class ="uk-animation-fade">
|
128
|
<div class="uk-alert uk-alert-info " role="alert">No person statistics found</div>
|
129
|
|
130
|
</div>
|
131
|
</li>
|
132
|
</ul>
|
133
|
</div>
|
134
|
|
135
|
|
136
|
</div>
|
137
|
`
|
138
|
})
|
139
|
export class SearchComponent {
|
140
|
public sub: any;
|
141
|
public subPublicationsCount: any;
|
142
|
public subDatasetsCount: any;
|
143
|
public subProjectsCount: any;
|
144
|
public subDataprovidersCount: any;
|
145
|
public subOrganizationsCount: any;
|
146
|
public subPeopleCount: any;
|
147
|
|
148
|
public reloadPublications: boolean;
|
149
|
public reloadDatasets: boolean;
|
150
|
public reloadProjects: boolean;
|
151
|
public reloadDataproviders: boolean;
|
152
|
public reloadOrganizations: boolean;
|
153
|
public reloadPeople: boolean;
|
154
|
|
155
|
|
156
|
public pageTitle = "Search in OpenAIRE"
|
157
|
public keyword:string = "";
|
158
|
public publications:string[];
|
159
|
public datasets:string[];
|
160
|
public projectsTab:string[];
|
161
|
public dataproviders:string[];
|
162
|
public organizations:string[];
|
163
|
public people:string[];
|
164
|
|
165
|
public activeTab = "publications";
|
166
|
public linkToSearchPublications = "";
|
167
|
public linkToSearchProjects = "";
|
168
|
public linkToSearchDataproviders = "";
|
169
|
public linkToSearchDatasets = "";
|
170
|
public linkToSearchOrganizations = "";
|
171
|
public linkToSearchPeople = "";
|
172
|
|
173
|
public fetchPublications : FetchPublications;
|
174
|
public fetchDataproviders : FetchDataproviders;
|
175
|
public fetchProjects : FetchProjects;
|
176
|
public fetchDatasets: FetchDatasets;
|
177
|
public fetchOrganizations: FetchOrganizations;
|
178
|
public fetchPeople: FetchPeople;
|
179
|
public searchFields:SearchFields = new SearchFields();
|
180
|
|
181
|
public subPub;public subData;public subProjects;public subOrg;public subPeople; public subDataPr;
|
182
|
constructor ( private route: ActivatedRoute,
|
183
|
private _searchPublicationsService: SearchPublicationsService,
|
184
|
private _searchDataprovidersService: SearchDataprovidersService,
|
185
|
private _searchProjectsService: SearchProjectsService,
|
186
|
private _searchDatasetsService: SearchDatasetsService,
|
187
|
private _searchOrganizationsService: SearchOrganizationsService,
|
188
|
private _searchPeopleService: SearchPeopleService,
|
189
|
private location: Location ) {
|
190
|
this.fetchPublications = new FetchPublications(this._searchPublicationsService);
|
191
|
this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
|
192
|
this.fetchProjects = new FetchProjects(this._searchProjectsService);
|
193
|
this.fetchDatasets = new FetchDatasets( this._searchDatasetsService);
|
194
|
this.fetchOrganizations = new FetchOrganizations( this._searchOrganizationsService);
|
195
|
this.fetchPeople = new FetchPeople(this._searchPeopleService);
|
196
|
}
|
197
|
|
198
|
public ngOnInit() {
|
199
|
this.sub = this.route.queryParams.subscribe(params => {
|
200
|
this.keyword = (params['keyword'])?params['keyword']:"";
|
201
|
if(this.keyword !=null && this.keyword.length > 0){
|
202
|
this.reloadTabs();
|
203
|
this.searchPublications();
|
204
|
this.count();
|
205
|
}
|
206
|
});
|
207
|
}
|
208
|
public ngOnDestroy() {
|
209
|
this.sub.unsubscribe();
|
210
|
if(this.keyword !=null && this.keyword.length > 0){
|
211
|
if(this.subPub){
|
212
|
this.subPub.unsubscribe();
|
213
|
}
|
214
|
if(this.subData){
|
215
|
this.subData.unsubscribe();
|
216
|
}
|
217
|
if(this.subProjects){
|
218
|
this.subProjects.unsubscribe();
|
219
|
}
|
220
|
if(this.subOrg){
|
221
|
this.subOrg.unsubscribe();
|
222
|
}
|
223
|
if(this.subPeople){
|
224
|
this.subPeople.unsubscribe();
|
225
|
}
|
226
|
if(this.subDataPr){
|
227
|
this.subDataPr.unsubscribe();
|
228
|
}
|
229
|
this.subPublicationsCount.unsubscribe();
|
230
|
this.subDatasetsCount.unsubscribe();
|
231
|
this.subProjectsCount.unsubscribe();
|
232
|
//this.subDataprovidersCount.unsubscribe();
|
233
|
this.subOrganizationsCount.unsubscribe();
|
234
|
this.subPeopleCount.unsubscribe();
|
235
|
}
|
236
|
}
|
237
|
public searchPublications() {
|
238
|
this.activeTab = "publications";
|
239
|
if(this.reloadPublications) {
|
240
|
this.reloadPublications = false;
|
241
|
this.fetchPublications.getResultsByKeyword(this.keyword, 1, 10);
|
242
|
this.linkToSearchPublications = OpenaireProperties.getLinkToSearchPublications() + "?keyword=" + this.keyword;
|
243
|
}
|
244
|
}
|
245
|
public searchDatasets() {
|
246
|
this.activeTab = "datasets";
|
247
|
if(this.reloadDatasets) {
|
248
|
this.reloadDatasets = false;
|
249
|
this.fetchDatasets.getResultsByKeyword(this.keyword, 1, 10);
|
250
|
this.linkToSearchDatasets = OpenaireProperties.getLinkToSearchDatasets() + "?keyword=" + this.keyword;
|
251
|
}
|
252
|
}
|
253
|
public searchProjects() {
|
254
|
this.activeTab = "projects";
|
255
|
if(this.reloadProjects) {
|
256
|
this.reloadProjects = false;
|
257
|
this.fetchProjects.getResultsByKeyword(this.keyword, 1, 10);
|
258
|
this.linkToSearchProjects = OpenaireProperties.getLinkToSearchProjects() + "?keyword=" + this.keyword;
|
259
|
}
|
260
|
}
|
261
|
public searchDataProviders() {
|
262
|
this.activeTab = "dataproviders";
|
263
|
if(this.reloadDataproviders) {
|
264
|
this.reloadDataproviders = false;
|
265
|
this.fetchDataproviders.getResultsByKeyword(this.keyword, 1, 10);
|
266
|
this.linkToSearchDataproviders = OpenaireProperties.getLinkToSearchDataProviders() + "?keyword=" + this.keyword;
|
267
|
}
|
268
|
}
|
269
|
public searchOrganizations() {
|
270
|
this.activeTab = "organizations";
|
271
|
if(this.reloadOrganizations) {
|
272
|
this.reloadOrganizations = false;
|
273
|
this.fetchOrganizations.getResultsByKeyword(this.keyword, 1, 10);
|
274
|
this.linkToSearchOrganizations = OpenaireProperties.getLinkToSearchOrganizations() + "?keyword=" + this.keyword;
|
275
|
}
|
276
|
}
|
277
|
public searchPeople() {
|
278
|
this.activeTab = "people";
|
279
|
if(this.reloadPeople) {
|
280
|
this.reloadPeople = false;
|
281
|
this.fetchPeople.getResultsByKeyword(this.keyword, 1, 10);
|
282
|
this.linkToSearchPeople = OpenaireProperties.getLinkToSearchPeople() + "?keyword=" + this.keyword;
|
283
|
}
|
284
|
}
|
285
|
|
286
|
public keywordChanged($event){
|
287
|
this.keyword = $event.value;
|
288
|
console.info("Search Find: search with keyword \"" + this.keyword + "\"" );
|
289
|
this.location.go(location.pathname,"?keyword=" + this.keyword);
|
290
|
this.reloadTabs();
|
291
|
if(this.activeTab == "publications") {
|
292
|
this.searchPublications();
|
293
|
}
|
294
|
if(this.activeTab == "projects") {
|
295
|
this.searchProjects();
|
296
|
}
|
297
|
if(this.activeTab == "dataproviders") {
|
298
|
this.searchDataProviders();
|
299
|
}
|
300
|
if(this.activeTab == "datasets") {
|
301
|
this.searchDatasets();
|
302
|
}
|
303
|
if(this.activeTab == "organizations") {
|
304
|
this.searchOrganizations();
|
305
|
}
|
306
|
if(this.activeTab == "people") {
|
307
|
this.searchPeople();
|
308
|
}
|
309
|
this.count();
|
310
|
}
|
311
|
|
312
|
private count() {
|
313
|
this.subPublicationsCount = this.route.queryParams.subscribe(params => {
|
314
|
this.subPub = this._searchPublicationsService.numOfSearchPublications(this.keyword).subscribe(
|
315
|
data => {
|
316
|
this.fetchPublications.searchUtils.totalResults = data;
|
317
|
},
|
318
|
err => {
|
319
|
console.log(err);
|
320
|
}
|
321
|
);
|
322
|
})
|
323
|
|
324
|
this.subDatasetsCount = this.route.queryParams.subscribe(params => {
|
325
|
this.subData = this._searchDatasetsService.numOfSearchDatasets(this.keyword).subscribe(
|
326
|
data => {
|
327
|
this.fetchDatasets.searchUtils.totalResults = data;
|
328
|
},
|
329
|
err => {
|
330
|
console.log(err);
|
331
|
}
|
332
|
);
|
333
|
})
|
334
|
|
335
|
this.subProjectsCount = this.route.queryParams.subscribe(params => {
|
336
|
this.subProjects = this._searchProjectsService.numOfSearchProjects(this.keyword).subscribe(
|
337
|
data => {
|
338
|
this.fetchProjects.searchUtils.totalResults = data;
|
339
|
},
|
340
|
err => {
|
341
|
console.log(err);
|
342
|
}
|
343
|
);
|
344
|
})
|
345
|
|
346
|
this.fetchDataproviders.getNumForSearch(this.keyword);
|
347
|
|
348
|
this.subOrganizationsCount = this.route.queryParams.subscribe(params => {
|
349
|
this.subOrg = this._searchOrganizationsService.numOfSearchOrganizations(this.keyword).subscribe(
|
350
|
data => {
|
351
|
this.fetchOrganizations.searchUtils.totalResults = data;
|
352
|
},
|
353
|
err => {
|
354
|
console.log(err);
|
355
|
}
|
356
|
);
|
357
|
})
|
358
|
|
359
|
this.subPeopleCount = this.route.queryParams.subscribe(params => {
|
360
|
this.subPeople = this._searchPeopleService.numOfSearchPeople(this.keyword).subscribe(
|
361
|
data => {
|
362
|
this.fetchPeople.searchUtils.totalResults = data;
|
363
|
},
|
364
|
err => {
|
365
|
console.log(err);
|
366
|
}
|
367
|
);
|
368
|
})
|
369
|
}
|
370
|
|
371
|
private reloadTabs() {
|
372
|
this.reloadPublications = true;
|
373
|
this.reloadDatasets = true;
|
374
|
this.reloadProjects = true;
|
375
|
this.reloadDataproviders = true;
|
376
|
this.reloadOrganizations = true;
|
377
|
this.reloadPeople = true;
|
378
|
}
|
379
|
|
380
|
}
|