1
|
import {Component, ViewChild} from '@angular/core';
|
2
|
import {Observable} from 'rxjs/Observable';
|
3
|
import {ActivatedRoute, Params} from '@angular/router';
|
4
|
import {ProjectService} from './project.service';
|
5
|
import {ProjectInfo} from '../../utils/entities/projectInfo';
|
6
|
|
7
|
|
8
|
import { FetchPublications } from '../../utils/fetchEntitiesClasses/fetchPublications.class';
|
9
|
import { SearchPublicationsService } from '../../services/searchPublications.service';
|
10
|
import { FetchDatasets } from '../../utils/fetchEntitiesClasses/fetchDatasets.class';
|
11
|
import { SearchDatasetsService } from '../../services/searchDatasets.service';
|
12
|
|
13
|
import {ReportsService} from '../../services/reports.service';
|
14
|
import {OpenaireProperties} from '../../utils/properties/openaireProperties';
|
15
|
|
16
|
@Component({
|
17
|
selector: 'project',
|
18
|
templateUrl: 'project.component.html',
|
19
|
})
|
20
|
export class ProjectComponent{
|
21
|
|
22
|
|
23
|
public projectId : string ;
|
24
|
public projectInfo: ProjectInfo;
|
25
|
public projectName: string;
|
26
|
public metricsClicked: boolean;
|
27
|
public viewsFrameUrl: string;
|
28
|
public downloadsFrameUrl: string;
|
29
|
public statsClicked: boolean;
|
30
|
public chartScientificResultsUrl: string;
|
31
|
public chartAccessModeUrl: string;
|
32
|
public chartDatasourcesUrl: string;
|
33
|
|
34
|
public project ;
|
35
|
|
36
|
public downloadURLAPI: string;
|
37
|
public csvParams: string;
|
38
|
|
39
|
public warningMessage = "";
|
40
|
public errorMessage = "";
|
41
|
|
42
|
sub: any;
|
43
|
subPublications: any;
|
44
|
subDatasets: any;
|
45
|
subDatasetsCount: any;
|
46
|
|
47
|
public fetchPublications : FetchPublications;
|
48
|
public linkToSearchPublications = "";
|
49
|
public fetchDatasets : FetchDatasets;
|
50
|
public linkToSearchDatasets = "";
|
51
|
|
52
|
constructor (private _projectService: ProjectService,
|
53
|
private route: ActivatedRoute,
|
54
|
private _searchPublicationsService: SearchPublicationsService,
|
55
|
private _searchDatasetsService: SearchDatasetsService,
|
56
|
private _reportsService: ReportsService) {
|
57
|
console.info('project constructor.');
|
58
|
|
59
|
this.fetchPublications = new FetchPublications( this._searchPublicationsService);
|
60
|
this.fetchDatasets = new FetchDatasets(this._searchDatasetsService);
|
61
|
}
|
62
|
|
63
|
ngOnInit() {
|
64
|
this.metricsClicked = false;
|
65
|
this.statsClicked = false;
|
66
|
|
67
|
this.sub = this.route.queryParams.subscribe(params => {
|
68
|
this.projectId = params['projectId'];
|
69
|
console.info("Id is :"+this.projectId);
|
70
|
if(this.projectId){
|
71
|
this.getProjectInfo(this.projectId);
|
72
|
// this.subPublications = this.route.queryParams.subscribe(params => {
|
73
|
this.searchPublications();
|
74
|
// });
|
75
|
|
76
|
this.subDatasetsCount = this._searchDatasetsService.numOfEntityDatasets(this.projectId, "projects/").subscribe(
|
77
|
data => {
|
78
|
this.fetchDatasets.searchUtils.totalResults = data;
|
79
|
},
|
80
|
err => {
|
81
|
console.log(err);
|
82
|
});
|
83
|
}else{
|
84
|
this.warningMessage="No valid project id";
|
85
|
}
|
86
|
|
87
|
this.downloadURLAPI = OpenaireProperties.getCsvAPIURL();
|
88
|
this.csvParams = "format=csv-special&page=0&size="+this.fetchPublications.searchUtils.totalResults+"&type=publications&query=(((oaftype exact result) and (resulttypeid exact publication)) and (relprojectid exact "+this.projectId+"))";
|
89
|
|
90
|
});
|
91
|
|
92
|
}
|
93
|
|
94
|
|
95
|
ngOnDestroy() {
|
96
|
this.sub.unsubscribe();
|
97
|
this.subDatasetsCount.unsubscribe();
|
98
|
}
|
99
|
|
100
|
private searchPublications() {
|
101
|
this.fetchPublications.getResultsForEntity("project", this.projectId, 1, 10);
|
102
|
this.linkToSearchPublications = OpenaireProperties.getLinkToAdvancedSearchPublications() + "?project=" + this.projectId+"&pr=and";
|
103
|
}
|
104
|
|
105
|
private searchDatasets() {
|
106
|
this.fetchDatasets.getResultsForEntity("project", this.projectId, 1, 10);
|
107
|
this.linkToSearchDatasets = OpenaireProperties.getLinkToAdvancedSearchDatasets() + "?project=" + this.projectId+"&pr=and";
|
108
|
}
|
109
|
|
110
|
private searchDatasetsInit() {
|
111
|
if(this.subDatasets == undefined && this.fetchDatasets.searchUtils.totalResults > 0) {
|
112
|
this.searchDatasets();
|
113
|
}
|
114
|
}
|
115
|
|
116
|
getProjectInfo (id:string) {
|
117
|
console.info("inside getProjectInfo of component");
|
118
|
this.warningMessage = '';
|
119
|
this.errorMessage=""
|
120
|
this._projectService.getProjectInfo(id).subscribe(
|
121
|
data => {
|
122
|
this.projectInfo = data;
|
123
|
this.project= { funderId: "", funderName: this.projectInfo.funder, projectId: this.projectId, projectName: this.projectInfo.title, projectAcronym: this.projectInfo.acronym, startDate: this.projectInfo.startDate, endDate: this.projectInfo.endDate };
|
124
|
|
125
|
this.viewsFrameUrl = OpenaireProperties.getFramesAPIURL()+'merge.php?com=query&data=[{"query":"projViewsTimeline","projTitle":"'+this.projectId+'","table":"","fields":[{"fld":"sum","agg":"sum","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[]}]&info_types=["spline"]&stacking=&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(124, 181, 236, 1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125, 1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233, 1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84, 1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91, 1)&colors[]=rgba(145, 232, 225, 1)&xlinew=0&ylinew=1&legends=true&tooltips=true';
|
126
|
this.downloadsFrameUrl = OpenaireProperties.getFramesAPIURL()+'merge.php?com=query&data=[{"query":"projDownloadsTimeline","projTitle":"'+this.projectId+'","table":"","fields":[{"fld":"sum","agg":"sum","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[]}]&info_types=["spline"]&stacking=&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(124, 181, 236, 1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125, 1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233, 1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84, 1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91, 1)&colors[]=rgba(145, 232, 225, 1)&xlinew=0&ylinew=1&legends=true&tooltips=true';
|
127
|
//stats tab charts
|
128
|
this.chartScientificResultsUrl='https://beta.openaire.eu/stats/chart.php?com=query&persistent=false&data={"query":"projScient","projTitle":"'+this.projectId+'", "table": "result", "fields": [{"fld": "number", "agg": "count", "type": "spline", "yaxis":1, "c":false}], "xaxis":{"name": "result_classifications-type", "agg": "avg"}, "group": "", "color": "", "type": "chart", "size":30, "sort": "xaxis", "xStyle":{"r": "-", "s": "-", "l": "-", "ft": "-", "wt": "-"}, "yaxisheaders": [""], "fieldsheaders": ["Publications"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [" "], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=600&h=250';
|
129
|
this.chartAccessModeUrl='https://beta.openaire.eu/stats/chart.php?com=query&persistent=false&data={"query":"projOA","projTitle":"'+this.projectId+'", "table": "result", "fields": [{"fld": "number", "agg": "count", "type": "pie", "yaxis":1, "c":false}], "xaxis":{"name": "result_classifications-type", "agg": "avg"}, "group": "", "color": "", "type": "chart", "size":30, "sort": "xaxis", "xStyle":{"r": "-", "s": "-", "l": "-", "ft": "-", "wt": "-"}, "yaxisheaders": [""], "fieldsheaders": ["Publications"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [" "], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=600&h=250';
|
130
|
this.chartDatasourcesUrl= 'https://beta.openaire.eu/stats/chart.php?com=query&persistent=false&data={"query":"projPubsRepos","projTitle":"'+this.projectId+'", "table": "result", "fields": [{"fld": "number", "agg": "count", "type": "column", "yaxis":1, "c":false}], "xaxis":{"name": "result_classifications-type", "agg": "avg"}, "group": "", "color": "", "type": "chart", "size":30, "sort": "xaxis", "xStyle":{"r": "-", "s": "-", "l": "-", "ft": "-", "wt": "-"}, "yaxisheaders": [""], "fieldsheaders": ["Publications"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [" "], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=600&h=250';
|
131
|
},
|
132
|
err => {
|
133
|
console.log(err);
|
134
|
this.errorMessage = 'No project found';
|
135
|
}
|
136
|
);
|
137
|
}
|
138
|
downloadfile(url:string){
|
139
|
console.log("Downloading file: "+ url);
|
140
|
this._reportsService.downloadCSVFile(url)
|
141
|
.subscribe(data => window.open(window.URL.createObjectURL(data)),
|
142
|
error => console.log("Error downloading the file."),
|
143
|
() => console.log('Completed file download.'));
|
144
|
}
|
145
|
}
|