1
|
import {Component, Input, Output, EventEmitter, ViewChild} 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 { SearchPublicationsComponent } from '../simple/searchPublications.component';
|
7
|
import { SearchDataprovidersComponent } from '../simple/searchDataproviders.component';
|
8
|
import { SearchProjectsComponent } from '../simple/searchProjects.component';
|
9
|
import { SearchDatasetsComponent } from '../simple/searchDatasets.component';
|
10
|
import { SearchOrganizationsComponent } from '../simple/searchOrganizations.component';
|
11
|
import { SearchPeopleComponent } from '../simple/searchPeople.component';
|
12
|
|
13
|
import {SearchPublicationsService} from '../../services/searchPublications.service';
|
14
|
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
|
15
|
import {SearchProjectsService} from '../../services/searchProjects.service';
|
16
|
import {SearchDatasetsService} from '../../services/searchDatasets.service';
|
17
|
import {SearchPeopleService} from '../../services/searchPeople.service';
|
18
|
import {SearchOrganizationsService} from '../../services/searchOrganizations.service';
|
19
|
|
20
|
import {OpenaireProperties} from '../../utils/properties/openaireProperties';
|
21
|
|
22
|
@Component({
|
23
|
selector: 'search-find',
|
24
|
template: `
|
25
|
|
26
|
<div class="container">
|
27
|
<div class="page-header">
|
28
|
<h1>{{pageTitle}}</h1>
|
29
|
</div>
|
30
|
<div >
|
31
|
|
32
|
<search-form [(keyword)]=keyword (keywordChange)="keywordChanged($event)"></search-form>
|
33
|
|
34
|
|
35
|
<div *ngIf = "keyword.length > 0" class="container">
|
36
|
|
37
|
|
38
|
<ul class="nav nav-tabs">
|
39
|
<li (click)="searchPublications()">
|
40
|
<a data-toggle="tab" href="#pubsTab">
|
41
|
Publications ({{searchPublicationsComponent.totalResults}})
|
42
|
</a>
|
43
|
</li>
|
44
|
<li (click)="searchDatasets()">
|
45
|
<a data-toggle="tab" href="#dataTab">
|
46
|
Datasets ({{searchDatasetsComponent.totalResults}})
|
47
|
</a>
|
48
|
</li>
|
49
|
<li (click)="searchProjects()">
|
50
|
<a data-toggle="tab" href="#projectsTab">
|
51
|
Projects ({{searchProjectsComponent.totalResults}})
|
52
|
</a>
|
53
|
</li>
|
54
|
<li (click)="searchDataProviders()">
|
55
|
<a data-toggle="tab" href="#dataProviderTab">
|
56
|
Data Providers ({{searchDataProvidersComponent.totalResults}})
|
57
|
</a>
|
58
|
</li>
|
59
|
<li (click)="searchOrganizations()">
|
60
|
<a data-toggle="tab" href="#organizationsTab" >
|
61
|
Organizations ({{searchOrganizationsComponent.totalResults}})
|
62
|
</a>
|
63
|
</li>
|
64
|
<li (click)="searchPeople()">
|
65
|
<a data-toggle="tab" href="#peopleTab" >
|
66
|
People ({{searchPeopleComponent.totalResults}})
|
67
|
</a>
|
68
|
</li>
|
69
|
</ul>
|
70
|
<div class="tab-content">
|
71
|
<div id="pubsTab" class="tab-pane fade in active panel-body">
|
72
|
<div class = "text-right" *ngIf = "searchPublicationsComponent.totalResults > 10" ><a [href] = "linkToSearchPublications" >View all {{searchPublicationsComponent.totalResults}} results</a></div>
|
73
|
<search-result [(results)]="searchPublicationsComponent.results" [(status)]= "searchPublicationsComponent.status"></search-result>
|
74
|
</div>
|
75
|
<div id="dataTab" class="tab-pane fade in panel-body" >
|
76
|
<div class = "text-right" *ngIf = "searchDatasetsComponent.totalResults > 10" ><a [href] = "linkToSearchDatasets" >View all {{searchDatasetsComponent.totalResults}} results</a></div>
|
77
|
<search-result [(results)]="searchDatasetsComponent.results" [(status)]= "searchDatasetsComponent.status"></search-result>
|
78
|
</div>
|
79
|
<div id="projectsTab" class="tab-pane fade in panel-body" >
|
80
|
<div class = "text-right" *ngIf = "searchProjectsComponent.totalResults > 10" ><a [href] = "linkToSearchProjects" >View all {{searchProjectsComponent.totalResults}} results</a></div>
|
81
|
<search-result [(results)]="searchProjectsComponent.results" [(status)]= "searchProjectsComponent.status"></search-result>
|
82
|
</div>
|
83
|
<div id="dataProviderTab" class="tab-pane fade in panel-body" >
|
84
|
<div class = "text-right" *ngIf = "searchDataProvidersComponent.totalResults > 10" ><a [href] = "linkToSearchDataproviders" >View all {{searchDataProvidersComponent.totalResults}} results</a></div>
|
85
|
<search-result [(results)]="searchDataProvidersComponent.results" [(status)]= "searchDataProvidersComponent.status"></search-result>
|
86
|
</div>
|
87
|
<div id="organizationsTab" class="tab-pane fade in panel-body" >
|
88
|
<div class = "text-right" *ngIf = "searchOrganizationsComponent.totalResults > 10" ><a [href] = "linkToSearchOrganizations" >View all {{searchOrganizationsComponent.totalResults}} results</a></div>
|
89
|
<search-result [(results)]="searchOrganizationsComponent.results" [(status)]= "searchOrganizationsComponent.status"></search-result>
|
90
|
</div>
|
91
|
<div id="peopleTab" class="tab-pane fade in panel-body" >
|
92
|
<div class = "text-right" *ngIf = "searchPeopleComponent.totalResults > 10" ><a [href] = "linkToSearchPeople" >View all {{searchPeopleComponent.totalResults}} results</a></div>
|
93
|
<search-result [(results)]="searchPeopleComponent.results" [(status)]= "searchPeopleComponent.status"></search-result>
|
94
|
</div>
|
95
|
</div>
|
96
|
</div>
|
97
|
</div>
|
98
|
`
|
99
|
})
|
100
|
export class SearchComponent {
|
101
|
private sub: any;
|
102
|
private subPublicationsCount: any;
|
103
|
private subDatasetsCount: any;
|
104
|
private subProjectsCount: any;
|
105
|
private subDataprovidersCount: any;
|
106
|
private subOrganizationsCount: any;
|
107
|
private subPeopleCount: any;
|
108
|
|
109
|
private reloadPublications: boolean;
|
110
|
private reloadDatasets: boolean;
|
111
|
private reloadProjects: boolean;
|
112
|
private reloadDataproviders: boolean;
|
113
|
private reloadOrganizations: boolean;
|
114
|
private reloadPeople: boolean;
|
115
|
|
116
|
|
117
|
private pageTitle = "Search in OpenAIRE"
|
118
|
private keyword:string = "";
|
119
|
private publications:string[];
|
120
|
private datasets:string[];
|
121
|
private projectsTab:string[];
|
122
|
private dataproviders:string[];
|
123
|
private organizations:string[];
|
124
|
private people:string[];
|
125
|
|
126
|
private activeTab = "publications";
|
127
|
private linkToSearchPublications = "";
|
128
|
private linkToSearchProjects = "";
|
129
|
private linkToSearchDataproviders = "";
|
130
|
private linkToSearchDatasets = "";
|
131
|
private linkToSearchOrganizations = "";
|
132
|
private linkToSearchPeople = "";
|
133
|
|
134
|
private searchPublicationsComponent : SearchPublicationsComponent;
|
135
|
private searchDataProvidersComponent : SearchDataprovidersComponent;
|
136
|
private searchProjectsComponent : SearchProjectsComponent;
|
137
|
private searchDatasetsComponent: SearchDatasetsComponent;
|
138
|
private searchOrganizationsComponent: SearchOrganizationsComponent;
|
139
|
private searchPeopleComponent: SearchPeopleComponent;
|
140
|
|
141
|
private subPub;private subData;private subProjects;private subOrg;private subPeople; private subDataPr;
|
142
|
constructor ( private route: ActivatedRoute,
|
143
|
private _searchPublicationsService: SearchPublicationsService,
|
144
|
private _searchDataprovidersService: SearchDataprovidersService,
|
145
|
private _searchProjectsService: SearchProjectsService,
|
146
|
private _searchDatasetsService: SearchDatasetsService,
|
147
|
private _searchOrganizationsService: SearchOrganizationsService,
|
148
|
private _searchPeopleService: SearchPeopleService,
|
149
|
private location: Location ) {
|
150
|
this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService);
|
151
|
this.searchDataProvidersComponent = new SearchDataprovidersComponent(this.route,this._searchDataprovidersService);
|
152
|
this.searchProjectsComponent = new SearchProjectsComponent(this.route, this._searchProjectsService);
|
153
|
this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService);
|
154
|
this.searchOrganizationsComponent = new SearchOrganizationsComponent(this.route, this._searchOrganizationsService);
|
155
|
this.searchPeopleComponent = new SearchPeopleComponent(this.route, this._searchPeopleService);
|
156
|
}
|
157
|
|
158
|
private ngOnInit() {
|
159
|
this.sub = this.route.queryParams.subscribe(params => {
|
160
|
this.keyword = (params['keyword'])?params['keyword']:"";
|
161
|
if(this.keyword !=null && this.keyword.length > 0){
|
162
|
this.reloadTabs();
|
163
|
this.searchPublications();
|
164
|
this.count();
|
165
|
}
|
166
|
});
|
167
|
}
|
168
|
private ngOnDestroy() {
|
169
|
this.sub.unsubscribe();
|
170
|
if(this.keyword !=null && this.keyword.length > 0){
|
171
|
if(this.subPub){
|
172
|
this.subPub.unsubscribe();
|
173
|
}
|
174
|
if(this.subData){
|
175
|
this.subData.unsubscribe();
|
176
|
}
|
177
|
if(this.subProjects){
|
178
|
this.subProjects.unsubscribe();
|
179
|
}
|
180
|
if(this.subOrg){
|
181
|
this.subOrg.unsubscribe();
|
182
|
}
|
183
|
if(this.subPeople){
|
184
|
this.subPeople.unsubscribe();
|
185
|
}
|
186
|
if(this.subDataPr){
|
187
|
this.subDataPr.unsubscribe();
|
188
|
}
|
189
|
this.subPublicationsCount.unsubscribe();
|
190
|
this.subDatasetsCount.unsubscribe();
|
191
|
this.subProjectsCount.unsubscribe();
|
192
|
//this.subDataprovidersCount.unsubscribe();
|
193
|
this.subOrganizationsCount.unsubscribe();
|
194
|
this.subPeopleCount.unsubscribe();
|
195
|
}
|
196
|
}
|
197
|
private searchPublications() {
|
198
|
this.activeTab = "publications";
|
199
|
if(this.reloadPublications) {
|
200
|
this.reloadPublications = false;
|
201
|
this.searchPublicationsComponent.getResults(this.keyword, false, 1, 10);
|
202
|
this.linkToSearchPublications = OpenaireProperties.getLinkToSearchPublications() + "?keyword=" + this.keyword;
|
203
|
}
|
204
|
}
|
205
|
private searchDatasets() {
|
206
|
this.activeTab = "datasets";
|
207
|
if(this.reloadDatasets) {
|
208
|
this.reloadDatasets = false;
|
209
|
this.searchDatasetsComponent.getResults(this.keyword, false, 1, 10);
|
210
|
this.linkToSearchDatasets = OpenaireProperties.getLinkToSearchDatasets() + "?keyword=" + this.keyword;
|
211
|
}
|
212
|
}
|
213
|
private searchProjects() {
|
214
|
this.activeTab = "projects";
|
215
|
if(this.reloadProjects) {
|
216
|
this.reloadProjects = false;
|
217
|
this.searchProjectsComponent.getResults(this.keyword, false, 1, 10);
|
218
|
this.linkToSearchProjects = OpenaireProperties.getLinkToSearchProjects() + "?keyword=" + this.keyword;
|
219
|
}
|
220
|
}
|
221
|
private searchDataProviders() {
|
222
|
this.activeTab = "datproviders";
|
223
|
if(this.reloadDataproviders) {
|
224
|
this.reloadDataproviders = false;
|
225
|
this.searchDataProvidersComponent.getResults(this.keyword, false, 1, 10);
|
226
|
this.linkToSearchDataproviders = OpenaireProperties.getLinkToSearchDataProviders() + "?keyword=" + this.keyword;
|
227
|
}
|
228
|
}
|
229
|
private searchOrganizations() {
|
230
|
this.activeTab = "organizations";
|
231
|
if(this.reloadOrganizations) {
|
232
|
this.reloadOrganizations = false;
|
233
|
this.searchOrganizationsComponent.getResults(this.keyword, false, 1, 10);
|
234
|
this.linkToSearchOrganizations = OpenaireProperties.getLinkToSearchOrganizations() + "?keyword=" + this.keyword;
|
235
|
}
|
236
|
}
|
237
|
private searchPeople() {
|
238
|
this.activeTab = "people";
|
239
|
if(this.reloadPeople) {
|
240
|
this.reloadPeople = false;
|
241
|
this.searchPeopleComponent.getResults(this.keyword, false, 1, 10);
|
242
|
this.linkToSearchPeople = OpenaireProperties.getLinkToSearchPeople() + "?keyword=" + this.keyword;
|
243
|
}
|
244
|
}
|
245
|
|
246
|
private keywordChanged($event){
|
247
|
this.keyword = $event.value;
|
248
|
console.info("Search Find: search with keyword \"" + this.keyword + "\"" );
|
249
|
if(location.pathname.indexOf("search/find") ==-1){
|
250
|
this.location.go(location.pathname+"search/find","?keyword=" + this.keyword);
|
251
|
}else{
|
252
|
this.location.go(location.pathname,"?keyword=" + this.keyword);
|
253
|
}
|
254
|
|
255
|
//unsubscribeSearch();
|
256
|
|
257
|
this.reloadTabs();
|
258
|
if(this.activeTab == "publications") {
|
259
|
this.searchPublications();
|
260
|
}
|
261
|
if(this.activeTab == "projects") {
|
262
|
this.searchProjects();
|
263
|
}
|
264
|
if(this.activeTab == "datasources") {
|
265
|
this.searchDataProviders();
|
266
|
}
|
267
|
if(this.activeTab == "datasets") {
|
268
|
this.searchDatasets();
|
269
|
}
|
270
|
if(this.activeTab == "organizations") {
|
271
|
this.searchOrganizations();
|
272
|
}
|
273
|
if(this.activeTab == "people") {
|
274
|
this.searchPeople();
|
275
|
}
|
276
|
this.count();
|
277
|
}
|
278
|
|
279
|
private count() {
|
280
|
this.subPublicationsCount = this.route.queryParams.subscribe(params => {
|
281
|
this.subPub = this._searchPublicationsService.numOfSearchPublications(this.keyword).subscribe(
|
282
|
data => {
|
283
|
this.searchPublicationsComponent.totalResults = data;
|
284
|
},
|
285
|
err => {
|
286
|
console.error(err);
|
287
|
}
|
288
|
);
|
289
|
})
|
290
|
|
291
|
this.subDatasetsCount = this.route.queryParams.subscribe(params => {
|
292
|
this.subData = this._searchDatasetsService.numOfSearchDatasets(this.keyword).subscribe(
|
293
|
data => {
|
294
|
this.searchDatasetsComponent.totalResults = data;
|
295
|
},
|
296
|
err => {
|
297
|
console.error(err);
|
298
|
}
|
299
|
);
|
300
|
})
|
301
|
|
302
|
this.subProjectsCount = this.route.queryParams.subscribe(params => {
|
303
|
this.subProjects = this._searchProjectsService.numOfSearchProjects(this.keyword).subscribe(
|
304
|
data => {
|
305
|
this.searchProjectsComponent.totalResults = data;
|
306
|
},
|
307
|
err => {
|
308
|
console.error(err);
|
309
|
}
|
310
|
);
|
311
|
})
|
312
|
|
313
|
this.searchDataProvidersComponent.getNumForSearch(this.keyword);
|
314
|
|
315
|
this.subOrganizationsCount = this.route.queryParams.subscribe(params => {
|
316
|
this.subOrg = this._searchOrganizationsService.numOfSearchOrganizations(this.keyword).subscribe(
|
317
|
data => {
|
318
|
this.searchOrganizationsComponent.totalResults = data;
|
319
|
},
|
320
|
err => {
|
321
|
console.error(err);
|
322
|
}
|
323
|
);
|
324
|
})
|
325
|
|
326
|
this.subPeopleCount = this.route.queryParams.subscribe(params => {
|
327
|
this.subPeople = this._searchPeopleService.numOfSearchPeople(this.keyword).subscribe(
|
328
|
data => {
|
329
|
this.searchPeopleComponent.totalResults = data;
|
330
|
},
|
331
|
err => {
|
332
|
console.error(err);
|
333
|
}
|
334
|
);
|
335
|
})
|
336
|
}
|
337
|
|
338
|
private reloadTabs() {
|
339
|
this.reloadPublications = true;
|
340
|
this.reloadDatasets = true;
|
341
|
this.reloadProjects = true;
|
342
|
this.reloadDataproviders = true;
|
343
|
this.reloadOrganizations = true;
|
344
|
this.reloadPeople = true;
|
345
|
}
|
346
|
|
347
|
}
|