1
|
import {Component, Input} from '@angular/core';
|
2
|
import {ActivatedRoute, Params} from '@angular/router';
|
3
|
|
4
|
import { SearchPublicationsComponent } from '../../searchPages/simple/searchPublications.component';
|
5
|
import { SearchPublicationsService } from '../../services/searchPublications.service';
|
6
|
import { SearchDatasetsComponent } from '../../searchPages/simple/searchDatasets.component';
|
7
|
import { SearchDatasetsService } from '../../services/searchDatasets.service';
|
8
|
import { SearchProjectsComponent } from '../../searchPages/simple/searchProjects.component';
|
9
|
import { SearchProjectsService } from '../../services/searchProjects.service';
|
10
|
import { SearchDataprovidersComponent } from '../../searchPages/simple/searchDataproviders.component';
|
11
|
import { SearchDataprovidersService } from '../../services/searchDataproviders.service';
|
12
|
|
13
|
@Component({
|
14
|
selector: 'tabs',
|
15
|
template: `
|
16
|
<ul *ngIf="tabs != undefined" class="nav nav-tabs">
|
17
|
<li *ngIf="tabs.length>0" class="active">
|
18
|
<a data-toggle="tab" href="#{{tabs[0].content}}">
|
19
|
{{tabs[0].name}}
|
20
|
<span class="badge" *ngIf="tabs[0].content=='publicationsTab'">
|
21
|
{{searchPublicationsComponent.searchUtils.totalResults}}
|
22
|
</span>
|
23
|
<span class="badge" *ngIf="tabs[0].content=='datasetsTab'">
|
24
|
{{searchDatasetsComponent.searchUtils.totalResults}}
|
25
|
</span>
|
26
|
<span class="badge" *ngIf="tabs[0].content=='projectsTab'">
|
27
|
{{searchProjectsComponent.searchUtils.totalResults}}
|
28
|
</span>
|
29
|
<span class="badge" *ngIf="tabs[0].content=='datasourcesTab'">
|
30
|
{{searchDataprovidersComponent.searchUtils.totalResults}}
|
31
|
</span>
|
32
|
<span class="badge" *ngIf="tabs[0].content=='organizationsTab'">
|
33
|
{{organizations.length}}
|
34
|
</span>
|
35
|
</a>
|
36
|
</li>
|
37
|
|
38
|
<li *ngFor="let tab of tabs; let i=index" role="presentation">
|
39
|
<a *ngIf="i>0"
|
40
|
(click)="search(tab.content, 1, 10)" data-toggle="tab" href="#{{tab.content}}">
|
41
|
{{tab.name}}
|
42
|
<span class="badge" *ngIf="tab.content=='publicationsTab'">
|
43
|
{{searchPublicationsComponent.searchUtils.totalResults}}
|
44
|
</span>
|
45
|
<span class="badge" *ngIf="tab.content=='datasetsTab'">
|
46
|
{{searchDatasetsComponent.searchUtils.totalResults}}
|
47
|
</span>
|
48
|
<span class="badge" *ngIf="tab.content=='projectsTab'">
|
49
|
{{searchProjectsComponent.searchUtils.totalResults}}
|
50
|
</span>
|
51
|
<span class="badge" *ngIf="tab.content=='datasourcesTab'">
|
52
|
{{searchDataprovidersComponent.searchUtils.totalResults}}
|
53
|
</span>
|
54
|
<span class="badge" *ngIf="tab.content=='organizationsTab'">
|
55
|
{{organizations.length}}
|
56
|
</span>
|
57
|
</a>
|
58
|
</li>
|
59
|
</ul>
|
60
|
|
61
|
<div *ngIf="tabs != undefined" class="tab-content">
|
62
|
<div *ngIf="tabs.length>0" id="{{tabs[0].content}}" class="tab-pane fade in active panel-body">
|
63
|
<publicationsTab *ngIf="tabs[0].content=='publicationsTab'"
|
64
|
[paramsForSearchLink]="paramsForSearchLink"
|
65
|
[searchPublicationsComponent]="searchPublicationsComponent">
|
66
|
</publicationsTab>
|
67
|
<datasetsTab *ngIf="tabs[0].content=='datasetsTab'"
|
68
|
[paramsForSearchLink]="paramsForSearchLink"
|
69
|
[searchDatasetsComponent]="searchDatasetsComponent">
|
70
|
</datasetsTab>
|
71
|
<statisticsTab *ngIf="tabs[0].content=='statisticsTab'"
|
72
|
[statistics]="statistics">
|
73
|
</statisticsTab>
|
74
|
<projectsTab *ngIf="tabs[0].content=='projectsTab'"
|
75
|
[paramsForSearchLink]="paramsForSearchLink"
|
76
|
[searchProjectsComponent]="searchProjectsComponent">
|
77
|
</projectsTab>
|
78
|
<datasourcesTab *ngIf="tabs[0].content=='datasourcesTab'"
|
79
|
[paramsForSearchLink]="paramsForSearchLink"
|
80
|
[searchDataprovidersComponent]="searchDataprovidersComponent">
|
81
|
</datasourcesTab>
|
82
|
<organizationsTab *ngIf="tabs[0].content=='organizationsTab'">
|
83
|
[organizations]="organizations"
|
84
|
</organizationsTab>
|
85
|
<relatedDatasourcesTab *ngIf="tabs[0].content=='relatedDatasourcesTab'"
|
86
|
[searchPublicationsComponent]="searchPublicationsComponentAggregators">
|
87
|
</relatedDatasourcesTab>
|
88
|
<div *ngIf="tabs[0].content=='metricsTab'" class="well">
|
89
|
<b>Views: </b>{{metrics}}
|
90
|
</div>
|
91
|
</div>
|
92
|
|
93
|
<div *ngFor="let tab of tabs; let i=index" id="{{tab.content}}" class="tab-pane fade panel-body">
|
94
|
<publicationsTab *ngIf="i>0 && tab.content=='publicationsTab'"
|
95
|
[paramsForSearchLink]="paramsForSearchLink"
|
96
|
[searchPublicationsComponent] = "searchPublicationsComponent">
|
97
|
</publicationsTab>
|
98
|
<datasetsTab *ngIf="i>0 && tab.content=='datasetsTab'"
|
99
|
[paramsForSearchLink]="paramsForSearchLink"
|
100
|
[searchDatasetsComponent]="searchDatasetsComponent">
|
101
|
</datasetsTab>
|
102
|
<statisticsTab *ngIf="i>0 && tab.content=='statisticsTab'"></statisticsTab>
|
103
|
<projectsTab *ngIf="i>0 && tab.content=='projectsTab'"
|
104
|
[paramsForSearchLink]="paramsForSearchLink"
|
105
|
[searchProjectsComponent]="searchProjectsComponent">
|
106
|
</projectsTab>
|
107
|
<datasourcesTab *ngIf="i>0 && tab.content=='datasourcesTab'"
|
108
|
[paramsForSearchLink]="paramsForSearchLink"
|
109
|
[searchDataprovidersComponent]="searchDataprovidersComponent">
|
110
|
</datasourcesTab>
|
111
|
<organizationsTab *ngIf="i>0 && tab.content=='organizationsTab'"
|
112
|
[organizations]="organizations">
|
113
|
</organizationsTab>
|
114
|
<relatedDatasourcesTab *ngIf="i>0 && tab.content=='relatedDatasourcesTab'"
|
115
|
[dataproviderId]="id"
|
116
|
[searchPublicationsComponent]="searchPublicationsComponentAggregators">
|
117
|
</relatedDatasourcesTab>
|
118
|
<div *ngIf="i>0 && tab.content=='metricsTab'" class="well">
|
119
|
<b>Views: </b>{{metrics}}
|
120
|
</div>
|
121
|
</div>
|
122
|
</div>
|
123
|
`
|
124
|
})
|
125
|
|
126
|
export class TabsComponent {
|
127
|
|
128
|
@Input() id: string;
|
129
|
@Input() resultsBy: string;
|
130
|
@Input() tabs: {"name": string, "content": string}[];
|
131
|
//@Input() publications;
|
132
|
//@Input() datasets;
|
133
|
@Input() statistics;
|
134
|
//@Input() projects;
|
135
|
//@Input() datasources;
|
136
|
@Input() organizations: {"name": string, "url": string}[];
|
137
|
|
138
|
@Input() _dataproviderService;
|
139
|
|
140
|
public metrics: string;
|
141
|
|
142
|
public paramsForSearchLink: string = "";
|
143
|
|
144
|
public reloadPublications: boolean = true;
|
145
|
public reloadDatasets: boolean = true;
|
146
|
public reloadProjects: boolean = true;
|
147
|
public reloadDataproviders: boolean = true;
|
148
|
public reloadRelatedDatasources: boolean = true;
|
149
|
|
150
|
public searchPublicationsComponent : SearchPublicationsComponent;
|
151
|
public searchDatasetsComponent: SearchDatasetsComponent;
|
152
|
public searchProjectsComponent: SearchProjectsComponent;
|
153
|
public searchDataprovidersComponent: SearchDataprovidersComponent;
|
154
|
public searchPublicationsComponentAggregators: SearchPublicationsComponent;
|
155
|
|
156
|
constructor (private route: ActivatedRoute,
|
157
|
private _searchPublicationsService: SearchPublicationsService,
|
158
|
private _searchDatasetsService: SearchDatasetsService,
|
159
|
private _searchProjectsService: SearchProjectsService,
|
160
|
private _searchDataprovidersService: SearchDataprovidersService) {
|
161
|
this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService);
|
162
|
this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService);
|
163
|
this.searchProjectsComponent = new SearchProjectsComponent(this.route, this._searchProjectsService);
|
164
|
this.searchDataprovidersComponent = new SearchDataprovidersComponent(this.route, this._searchDataprovidersService);
|
165
|
this.searchPublicationsComponentAggregators = new SearchPublicationsComponent(this.route, this._searchPublicationsService);
|
166
|
}
|
167
|
|
168
|
ngOnInit() {
|
169
|
if(this.tabs != undefined && this.tabs.length > 0) {
|
170
|
this.search(this.tabs[0].content, 1, 10);
|
171
|
this.count(1, 0);
|
172
|
}
|
173
|
|
174
|
if(this.resultsBy == "collectedFrom") {
|
175
|
this.paramsForSearchLink = "?collectedFrom="+this.id+"&co=and";
|
176
|
} else if (this.resultsBy == "hostedBy") {
|
177
|
this.paramsForSearchLink = "?hostedBy="+this.id+"&ho=and";
|
178
|
}
|
179
|
}
|
180
|
|
181
|
private count(page: number, size: number) {
|
182
|
console.info("number of tabs: "+this.tabs.length);
|
183
|
|
184
|
for(let i=1; i<this.tabs.length; i++) {
|
185
|
let content: string = this.tabs[i].content;
|
186
|
if(content=='publicationsTab') {
|
187
|
this.countPublications(page, size);
|
188
|
} else if(content=='datasetsTab') {
|
189
|
this.countDatasets(page, size);
|
190
|
} else if(content=='projectsTab') {
|
191
|
this.countProjects(page, size);
|
192
|
} else if(content=='datasourcesTab') {
|
193
|
this.countDatasources(page, size);
|
194
|
}// else if(content=='relatedDatasourcesTab') {
|
195
|
// this.countRelatedDatasources(page, size);
|
196
|
//}
|
197
|
}
|
198
|
}
|
199
|
|
200
|
private search(content: string, page: number, size: number) {
|
201
|
if(content=='publicationsTab') {
|
202
|
this.searchPublications(page, size);
|
203
|
} else if(content=='datasetsTab') {
|
204
|
this.searchDatasets(page, size);
|
205
|
} else if(content=='projectsTab') {
|
206
|
this.searchProjects(page, size);
|
207
|
} else if(content=='datasourcesTab') {
|
208
|
this.searchDatasources(page, size);
|
209
|
} else if(content=='relatedDatasourcesTab') {
|
210
|
this.searchRelatedDatasources(1, 0);
|
211
|
} else if(content=='metricsTab') {
|
212
|
this.getMetrics();
|
213
|
}
|
214
|
}
|
215
|
|
216
|
private getMetrics() {
|
217
|
console.info("getDatasourceMetrics: component");
|
218
|
this._dataproviderService.getMetrics(this.id).subscribe(
|
219
|
data => {
|
220
|
this.metrics = data;
|
221
|
},
|
222
|
err => {
|
223
|
console.log(err);
|
224
|
console.info("error");
|
225
|
}
|
226
|
);
|
227
|
}
|
228
|
|
229
|
private searchPublications(page: number, size: number) {
|
230
|
if(this.reloadPublications) {
|
231
|
this.searchPublicationsComponent.getResultsForDataproviders(this.id, this.resultsBy, page, size);
|
232
|
}
|
233
|
this.reloadPublications = false;
|
234
|
}
|
235
|
|
236
|
private countPublications(page: number, size: number) {
|
237
|
this.searchPublicationsComponent.getResultsForDataproviders(this.id, this.resultsBy, page, size);
|
238
|
}
|
239
|
|
240
|
private searchDatasets(page: number, size: number) {
|
241
|
if(this.reloadDatasets) {
|
242
|
this.searchDatasetsComponent.getResultsForDataproviders(this.id, this.resultsBy, page, size);
|
243
|
}
|
244
|
this.reloadDatasets = false;
|
245
|
}
|
246
|
|
247
|
private countDatasets(page: number, size: number) {
|
248
|
this.searchDatasetsComponent.getResultsForDataproviders(this.id, this.resultsBy, page, size);
|
249
|
}
|
250
|
|
251
|
private searchProjects(page: number, size: number) {
|
252
|
if(this.reloadProjects) {
|
253
|
this.searchProjectsComponent.getResultsForDataproviders(this.id, page, size);
|
254
|
}
|
255
|
this.reloadProjects = false;
|
256
|
}
|
257
|
|
258
|
private countProjects(page: number, size: number) {
|
259
|
this.searchProjectsComponent.getResultsForDataproviders(this.id, page, size);
|
260
|
}
|
261
|
|
262
|
private searchDatasources(page: number, size: number) {
|
263
|
if(this.reloadDataproviders) {
|
264
|
this.searchDataprovidersComponent.getResultsForDataproviders(this.id, page, size);
|
265
|
}
|
266
|
this.reloadDataproviders = false;
|
267
|
}
|
268
|
|
269
|
private countDatasources(page: number, size: number) {
|
270
|
this.searchDataprovidersComponent.getResultsForDataproviders(this.id, page, size);
|
271
|
}
|
272
|
|
273
|
private searchRelatedDatasources(page: number, size: number) {
|
274
|
if(this.reloadRelatedDatasources) {
|
275
|
this.searchPublicationsComponentAggregators.getAggregatorResults(this.id, page, size);
|
276
|
}
|
277
|
this.reloadRelatedDatasources = false;
|
278
|
}
|
279
|
|
280
|
private countRelatedDatasources(page: number, size: number) {
|
281
|
//searchPublicationsComponentAggregator
|
282
|
this.searchPublicationsComponentAggregators.getAggregatorResults(this.id, page, size);
|
283
|
}
|
284
|
}
|