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
|
|
9
|
@Component({
|
10
|
selector: 'tabs',
|
11
|
template: `
|
12
|
<ul class="nav nav-tabs">
|
13
|
<li *ngIf="tabs.length>0" class="active">
|
14
|
<a *ngIf="tabs[0].content=='publicationsTab' || tabs[0].content=='datasetsTab'"
|
15
|
data-toggle="tab" href="#{{tabs[0].content}}">
|
16
|
{{tabs[0].name}}
|
17
|
<span class="badge" *ngIf="tabs[0].content=='publicationsTab'">
|
18
|
{{searchPublicationsComponent.totalResults}}
|
19
|
</span>
|
20
|
<span class="badge" *ngIf="tabs[0].content=='datasetsTab'">
|
21
|
{{searchDatasetsComponent.totalResults}}
|
22
|
</span>
|
23
|
</a>
|
24
|
</li>
|
25
|
|
26
|
<li *ngFor="let tab of tabs; let i=index" role="presentation">
|
27
|
<a *ngIf="(tab.content=='publicationsTab' || tab.content=='datasetsTab') && i>0"
|
28
|
(click)="search(tab.content)" data-toggle="tab" href="#{{tab.content}}">
|
29
|
{{tab.name}}
|
30
|
<span class="badge" *ngIf="tab.content=='publicationsTab'">
|
31
|
{{searchPublicationsComponent.totalResults}}
|
32
|
</span>
|
33
|
<span class="badge" *ngIf="tab.content=='datasetsTab'">
|
34
|
{{searchDatasetsComponent.totalResults}}
|
35
|
</span>
|
36
|
</a>
|
37
|
</li>
|
38
|
</ul>
|
39
|
|
40
|
<div class="tab-content">
|
41
|
<div *ngIf="tabs.length>0" id="{{tabs[0].content}}" class="tab-pane fade in active panel-body">
|
42
|
<div *ngIf="tabs[0].content=='publicationsTab' || tabs[0].content=='datasetsTab'">
|
43
|
|
44
|
<publicationsTab *ngIf="tabs[0].content=='publicationsTab'"
|
45
|
[paramsForSearchLink]="paramsForSearchLink"
|
46
|
[searchPublicationsComponent]="searchPublicationsComponent">
|
47
|
</publicationsTab>
|
48
|
<datasetsTab *ngIf="tabs[0].content=='datasetsTab'"
|
49
|
[paramsForSearchLink]="paramsForSearchLink"
|
50
|
[searchDatasetsComponent]="searchDatasetsComponent">
|
51
|
</datasetsTab>
|
52
|
<statisticsTab *ngIf="tabs[0].content=='statisticsTab'"
|
53
|
[statistics]="statistics">
|
54
|
</statisticsTab>
|
55
|
<projectsTab *ngIf="tabs[0].content=='projectsTab'"
|
56
|
[projects]="projects">
|
57
|
</projectsTab>
|
58
|
<datasourcesTab *ngIf="tabs[0].content=='datasourcesTab'"
|
59
|
[datasources]="datasources">
|
60
|
</datasourcesTab>
|
61
|
</div>
|
62
|
<div>
|
63
|
|
64
|
<div *ngFor="let tab of tabs; let i=index" id="{{tab.content}}" class="tab-pane fade panel-body">
|
65
|
<div *ngIf="tab.content=='publicationsTab' || tab.content=='datasetsTab'">
|
66
|
|
67
|
<publicationsTab *ngIf="i>0 && tab.content=='publicationsTab'"
|
68
|
[paramsForSearchLink]="paramsForSearchLink"
|
69
|
[searchPublicationsComponent] = "searchPublicationsComponent">
|
70
|
</publicationsTab>
|
71
|
<datasetsTab *ngIf="i>0 && tab.content=='datasetsTab'"
|
72
|
[paramsForSearchLink]="paramsForSearchLink"
|
73
|
[searchDatasetsComponent]="searchDatasetsComponent">
|
74
|
</datasetsTab>
|
75
|
<statisticsTab *ngIf="i>0 && tab.content=='statisticsTab'"></statisticsTab>
|
76
|
<projectsTab *ngIf="i>0 && tab.content=='projectsTab'"></projectsTab>
|
77
|
<datasourcesTab *ngIf="i>0 && tab.content=='datasourcesTab'"></datasourcesTab>
|
78
|
</div>
|
79
|
</div>
|
80
|
</div>
|
81
|
`
|
82
|
})
|
83
|
|
84
|
export class TabsComponent {
|
85
|
|
86
|
@Input() id: string;
|
87
|
@Input() resultsBy: string;
|
88
|
@Input() tabs: {"name": string, "content": string}[];
|
89
|
//@Input() publications;
|
90
|
//@Input() datasets;
|
91
|
@Input() statistics;
|
92
|
@Input() projects;
|
93
|
@Input() datasources;
|
94
|
|
95
|
private paramsForSearchLink: string = "";
|
96
|
|
97
|
private reloadPublications: boolean = true;
|
98
|
private reloadDatasets: boolean = true;
|
99
|
|
100
|
subPublications: any;
|
101
|
subDatasets: any;
|
102
|
|
103
|
private searchPublicationsComponent : SearchPublicationsComponent;
|
104
|
private searchDatasetsComponent: SearchDatasetsComponent;
|
105
|
|
106
|
constructor (private route: ActivatedRoute,
|
107
|
private _searchPublicationsService: SearchPublicationsService,
|
108
|
private _searchDatasetsService: SearchDatasetsService) {
|
109
|
this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService);
|
110
|
this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService);
|
111
|
}
|
112
|
|
113
|
ngOnInit() {
|
114
|
if(this.tabs != []) {
|
115
|
this.search(this.tabs[0].content);
|
116
|
}
|
117
|
|
118
|
if(this.resultsBy == "collectedFrom") {
|
119
|
this.paramsForSearchLink = "?collectedfromdatasourceid="+this.id;
|
120
|
} else if (this.resultsBy == "hostedBy") {
|
121
|
this.paramsForSearchLink = "?resulthostingdatasourceid="+this.id;
|
122
|
}
|
123
|
}
|
124
|
|
125
|
ngOnDestroy() {
|
126
|
if(this.subPublications != undefined) {
|
127
|
this.subPublications.unsubscribe();
|
128
|
}
|
129
|
if(this.subDatasets != undefined) {
|
130
|
this.subDatasets.unsubscribe();
|
131
|
}
|
132
|
}
|
133
|
|
134
|
private search(content: string) {
|
135
|
if(content=='publicationsTab') {
|
136
|
this.subPublications = this.route.queryParams.subscribe(params => {
|
137
|
this.searchPublications();
|
138
|
});
|
139
|
} else if(content=='datasetsTab') {
|
140
|
this.subDatasets = this.route.queryParams.subscribe(params => {
|
141
|
this.searchDatasets();
|
142
|
});
|
143
|
}
|
144
|
}
|
145
|
|
146
|
private searchPublications() {
|
147
|
if(this.reloadPublications) {
|
148
|
this.searchPublicationsComponent.getResultsForDataproviders(this.id, this.resultsBy, 1, 10);
|
149
|
}
|
150
|
this.reloadPublications = false;
|
151
|
}
|
152
|
|
153
|
private searchDatasets() {
|
154
|
if(this.reloadDatasets) {
|
155
|
this.searchDatasetsComponent.getResultsForDataproviders(this.id, this.resultsBy, 1, 10);
|
156
|
}
|
157
|
this.reloadDatasets = false;
|
158
|
}
|
159
|
}
|