1
|
import {Component} from '@angular/core';
|
2
|
import {Observable} from 'rxjs/Observable';
|
3
|
import {ActivatedRoute} from '@angular/router';
|
4
|
import {OrganizationService} from '../../services/organization.service';
|
5
|
import {OrganizationInfo} from '../../utils/entities/organizationInfo';
|
6
|
|
7
|
import { SearchDataprovidersComponent } from '../../searchPages/simple/searchDataproviders.component';
|
8
|
import { SearchDataprovidersService } from '../../services/searchDataproviders.service';
|
9
|
import {SearchResultComponent} from '../../searchPages/searchUtils/searchResult.component';
|
10
|
import { SearchPublicationsComponent } from '../../searchPages/simple/searchPublications.component';
|
11
|
import { SearchPublicationsService } from '../../services/searchPublications.service';
|
12
|
|
13
|
import {OpenaireProperties} from '../../utils/properties/openaireProperties';
|
14
|
import {ExportCSVComponent} from '../../utils/exportCSV.component';
|
15
|
|
16
|
@Component({
|
17
|
selector: 'organization',
|
18
|
templateUrl: 'organization.component.html',
|
19
|
})
|
20
|
|
21
|
export class OrganizationComponent {
|
22
|
|
23
|
organizationInfo: OrganizationInfo;
|
24
|
private metrics: string;
|
25
|
private organizationId: string;
|
26
|
private projectsNum: number = 0;
|
27
|
private fundersSet: Set<string>;
|
28
|
private emptyFundersSet: boolean = true;
|
29
|
public warningMessage = "";
|
30
|
public errorMessage = "";
|
31
|
private csvData: any = {};
|
32
|
|
33
|
sub: any;
|
34
|
subDataproviders: any;
|
35
|
subDataprovidersCount: any;
|
36
|
|
37
|
private searchDataprovidersComponent : SearchDataprovidersComponent;
|
38
|
private linkToSearchDataproviders = "";
|
39
|
private searchPublicationsComponent : SearchPublicationsComponent;
|
40
|
|
41
|
constructor (private _organizationService: OrganizationService,
|
42
|
private route: ActivatedRoute,
|
43
|
private _searchDataprovidersService: SearchDataprovidersService,
|
44
|
private _searchPublicationsService: SearchPublicationsService) {
|
45
|
console.info('organization constructor');
|
46
|
this.searchDataprovidersComponent = new SearchDataprovidersComponent(this.route, this._searchDataprovidersService);
|
47
|
this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService);
|
48
|
}
|
49
|
|
50
|
ngOnInit() {
|
51
|
console.info('organization init');
|
52
|
this.sub = this.route.queryParams.subscribe(params => {
|
53
|
this.organizationId = params['organizationId'];
|
54
|
console.info("Id is :"+this.organizationId);
|
55
|
if(this.organizationId){
|
56
|
this.getOrganizationInfo();
|
57
|
}else{
|
58
|
this.warningMessage="No valid organization id";
|
59
|
}
|
60
|
});
|
61
|
|
62
|
/*
|
63
|
this.subDataprovidersCount = this.route.queryParams.subscribe(params => {
|
64
|
this._searchDataprovidersService.numOfDataproviders("organizations/"+this.organizationId+"/datasources/count").subscribe(
|
65
|
data => {
|
66
|
this.searchDataprovidersComponent.searchUtils.totalResults = data;
|
67
|
console.info("this.searchDataprovidersComponent.searchUtils.totalResults = "+this.searchDataprovidersComponent.searchUtils.totalResults);
|
68
|
},
|
69
|
err => {
|
70
|
console.log(err);
|
71
|
}
|
72
|
);
|
73
|
})
|
74
|
*/
|
75
|
this.searchDataprovidersComponent.getNumForEntity("organization", this.organizationId);
|
76
|
}
|
77
|
|
78
|
|
79
|
ngOnDestroy() {
|
80
|
this.sub.unsubscribe();
|
81
|
if(this.subDataproviders != undefined) {
|
82
|
this.subDataproviders.unsubscribe();
|
83
|
}
|
84
|
//this.subDataprovidersCount.unsubscribe();
|
85
|
}
|
86
|
|
87
|
private getOrganizationInfo () {
|
88
|
|
89
|
this.warningMessage = '';
|
90
|
this.errorMessage=""
|
91
|
|
92
|
this._organizationService.getOrganizationInfo(this.organizationId).subscribe(
|
93
|
data => {
|
94
|
this.organizationInfo = data;
|
95
|
|
96
|
let projectsNum = 0;
|
97
|
if(this.organizationInfo.projects != undefined) {
|
98
|
this.fundersSet = new Set<string>();
|
99
|
this.organizationInfo.projects.forEach(function (value, key, map) {
|
100
|
projectsNum += value.length;
|
101
|
this.fundersSet.add(key);
|
102
|
}.bind(this));
|
103
|
}
|
104
|
this.projectsNum = projectsNum;
|
105
|
},
|
106
|
err => {
|
107
|
console.log(err)
|
108
|
|
109
|
this.errorMessage = 'No organization found';
|
110
|
}
|
111
|
);
|
112
|
}
|
113
|
|
114
|
private getMetrics() {
|
115
|
console.info("getOrganizationMetrics: component");
|
116
|
this._organizationService.getMetrics(this.organizationId).subscribe(
|
117
|
data => {
|
118
|
this.metrics = data;
|
119
|
},
|
120
|
err => {
|
121
|
console.log(err);
|
122
|
console.info("error");
|
123
|
|
124
|
this.errorMessage = 'No organization metrics found';
|
125
|
}
|
126
|
);
|
127
|
}
|
128
|
|
129
|
private handleClick(funder: string) {
|
130
|
if(this.emptyFundersSet) {
|
131
|
this.fundersSet.clear();
|
132
|
this.emptyFundersSet = false;
|
133
|
}
|
134
|
|
135
|
if(this.fundersSet.has(funder)) {
|
136
|
this.fundersSet.delete(funder);
|
137
|
|
138
|
if(this.fundersSet.size == 0) {
|
139
|
this.organizationInfo.projects.forEach(function (value, key, map) {
|
140
|
this.fundersSet.add(key);
|
141
|
}.bind(this));
|
142
|
this.emptyFundersSet = true;
|
143
|
}
|
144
|
console.info(funder+" funder deleted");
|
145
|
} else {
|
146
|
this.fundersSet.add(funder);
|
147
|
console.info(funder+" funder added");
|
148
|
}
|
149
|
}
|
150
|
|
151
|
private exportProjects(key: string) {
|
152
|
let projectsData : any = { "columnNames": [], "export":[] };
|
153
|
let projectName = "Projects"+key;
|
154
|
|
155
|
if(!(projectName in this.csvData)) {
|
156
|
projectsData.columnNames = ['Project title', 'Project Acronym', 'Project ID',
|
157
|
'Funder', 'Funding Stream',
|
158
|
'Funding Substream level 1', 'Funding Substream level 2',
|
159
|
'SC39', 'Start Date', 'End Date'];
|
160
|
for(let project of this.organizationInfo.projects.get(key)) {
|
161
|
projectsData.export[projectsData.export.length] =
|
162
|
/*{
|
163
|
'Project title': this.quote(project.name),
|
164
|
'Project Acronym': this.quote(project.acronym),
|
165
|
'Project ID': this.quote(project.code),
|
166
|
'Funder': this.quote(project.funder),
|
167
|
'Funding Stream':this.quote(project.fundingStream),
|
168
|
'Funding Substream level 1': this.quote(project.fundingLevel1),
|
169
|
'Funding Substream level 2': this.quote(project.fundingLevel2),
|
170
|
'SC39': this.quote(project.sc39),
|
171
|
'Start Date': this.quote(project.startDate),
|
172
|
'End Date': this.quote(project.endDate)
|
173
|
};
|
174
|
*/
|
175
|
[
|
176
|
this.quote(project.name),
|
177
|
this.quote(project.acronym),
|
178
|
this.quote(project.code),
|
179
|
this.quote(project.funder),
|
180
|
this.quote(project.fundingStream),
|
181
|
this.quote(project.fundingLevel1),
|
182
|
this.quote(project.fundingLevel2),
|
183
|
this.quote(project.sc39),
|
184
|
this.quote(project.startDate),
|
185
|
this.quote(project.endDate)
|
186
|
];
|
187
|
}
|
188
|
|
189
|
this.csvData[projectName] = projectsData;
|
190
|
}
|
191
|
ExportCSVComponent.downloadCSV(this.csvData[projectName], "projects "+key+".csv");
|
192
|
}
|
193
|
|
194
|
private exportPublications(key: string) {
|
195
|
let publicationsData : any = { "columnNames": [], "export":[] };
|
196
|
let publicationName = "Publications"+key;
|
197
|
|
198
|
if(!(publicationName in this.csvData)) {
|
199
|
publicationsData.columnNames = ['Title', 'Authors', 'Publication Year',
|
200
|
'DOI', 'Download From', 'Publication type',
|
201
|
'Journal', 'Funder', 'Project Name (GA Number)', 'Access'];
|
202
|
|
203
|
for(let project of this.organizationInfo.projects.get(key)) {
|
204
|
let result = this.searchPublicationsComponent.getCSVResultsForEntity("project", project.id);
|
205
|
//publicationsData.export.concat(["aaaa", "ooo"], ["iiii", "eeee"]]);
|
206
|
result.every(function(item) {publicationsData.export.push(item);});
|
207
|
//console.info("publications export: "+publicationsData.export);
|
208
|
//console.info("publications export: "+result);
|
209
|
}
|
210
|
this.csvData[publicationName] = publicationsData;
|
211
|
}
|
212
|
ExportCSVComponent.downloadCSV(this.csvData[publicationName], "publications "+key+".csv");
|
213
|
}
|
214
|
|
215
|
private quote(word: string): string {
|
216
|
return '"'+word+'"';
|
217
|
}
|
218
|
|
219
|
//private getProjectsData(key: string): any {
|
220
|
//return this.projectsData;
|
221
|
//}
|
222
|
|
223
|
private searchDataproviders() {
|
224
|
this.searchDataprovidersComponent.getResultsForEntity("organization", this.organizationId, 1, 10);
|
225
|
this.linkToSearchDataproviders = OpenaireProperties.getLinkToAdvancedSearchDataProviders() + "?organization=" + this.organizationId + "&or=and";;
|
226
|
}
|
227
|
|
228
|
private searchDataprovidersInit() {
|
229
|
if(this.subDataproviders == undefined && this.searchDataprovidersComponent.searchUtils.totalResults > 0) {
|
230
|
this.subDataproviders = this.route.queryParams.subscribe(params => {
|
231
|
this.searchDataproviders();
|
232
|
});
|
233
|
}
|
234
|
}
|
235
|
}
|