Project

General

Profile

1
import {Component, ViewChild, ElementRef} from '@angular/core';
2
import {Observable} from 'rxjs/Observable';
3
import {ActivatedRoute, Params, Router} from '@angular/router';
4
import {ProjectService} from './project.service';
5
import {ProjectInfo} from '../../utils/entities/projectInfo';
6
import {RouterHelper} from '../../utils/routerHelper.class';
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 {ModalLoading} from '../../utils/modal/loading.component';
14

    
15
import {ReportsService} from '../../services/reports.service';
16
import {OpenaireProperties, ErrorCodes} from '../../utils/properties/openaireProperties';
17
import { Meta} from '../../../angular2-meta';
18

    
19
import {PiwikService} from '../../utils/piwik/piwik.service';
20

    
21
@Component({
22
    selector: 'project',
23
    templateUrl: 'project.component.html',
24
 })
25
export class ProjectComponent{
26

    
27
  public projectId : string ;
28
  public projectInfo: ProjectInfo;
29
  public projectName: string;
30
  public metricsClicked: boolean;
31
  public viewsFrameUrl: string;
32
  public downloadsFrameUrl: string;
33
  private totalViews: number;
34
  private totalDownloads: number;
35
  private pageViews: number;
36
  public statsClicked: boolean;
37
  public chartScientificResultsUrl: string;
38
  public chartAccessModeUrl: string;
39
  public chartDatasourcesUrl: string;
40

    
41
  public publications_dynamic: string;
42
  public datasets_dynamic: string;
43

    
44
  public project ;
45

    
46
  public downloadURLAPI: string;
47
  public csvParams: string;
48
  public csvParamsDatasets: string;
49

    
50
  public warningMessage = "";
51
  public errorMessage = "";
52
  public showLoading: boolean = true;
53

    
54
  sub: any;piwiksub: any;
55

    
56
  public activeTab: string = "Publications";
57
  public reloadDatasets: boolean = true;
58

    
59
  public fetchPublications : FetchPublications;
60
  public linkToSearchPublications = "";
61
  public fetchDatasets : FetchDatasets;
62
  public linkToSearchDatasets = "";
63
  public routerHelper:RouterHelper = new RouterHelper();
64
  public errorCodes:ErrorCodes = new ErrorCodes();
65

    
66
  @ViewChild (ModalLoading) loading : ModalLoading ;
67

    
68
  constructor ( private element: ElementRef,
69
                private _projectService: ProjectService,
70
                private _piwikService:PiwikService,
71
                private  route: ActivatedRoute,
72
                private _searchPublicationsService: SearchPublicationsService,
73
                private _searchDatasetsService: SearchDatasetsService,
74
                private _reportsService: ReportsService, private _meta: Meta,
75
                private _router: Router) {
76
    this.updateUrl(OpenaireProperties.getBaseLink()+this._router.url);
77
  }
78

    
79
  ngOnInit() {
80
    this.sub =  this.route.queryParams.subscribe(params => {
81
        this.metricsClicked = false;
82
        this.statsClicked = false;
83
        this.fetchPublications = new FetchPublications( this._searchPublicationsService);
84
        this.fetchDatasets = new FetchDatasets(this._searchDatasetsService);
85

    
86
        this.updateTitle("Project");
87
        this.updateDescription("project, funding, open access, publications, research data");
88

    
89
      this.projectId = params['projectId'];
90
       if(this.projectId){
91
           this.publications_dynamic =
92
                "<script type=\"text/javascript\">"
93
                + "\n<!--"
94
                + "\ndocument.write('<div id=\"oa_widget\"></div>');"
95
                + "\ndocument.write('<script type=\"text/javascript\""
96
                + "\nsrc=\"https://beta.openaire.eu/index.php?option=com_openaire&view=widget&format=raw&projectId="
97
                + this.projectId + "&type=publication\"></script>');"
98
                + "\n-->"
99
                + "\n</script>";
100

    
101
            this.datasets_dynamic =
102
                "<script type=\"text/javascript\">"
103
                + "\n<!--"
104
                + "\ndocument.write('<div id=\"oa_widget\"></div>');"
105
                + "\ndocument.write('<script type=\"text/javascript\""
106
                + "\nsrc=\"https://beta.openaire.eu/index.php?option=com_openaire&view=widget&format=raw&projectId="
107
                + this.projectId + "&type=dataset\"></script>');"
108
                + "\n-->"
109
                + "\n</script>";
110

    
111
          this.getProjectInfo(this.projectId);
112
          this.searchPublications();
113
          this.fetchDatasets.getNumForEntity("project", this.projectId);
114
      }else{
115
          this.showLoading = false;
116
		      this.warningMessage="No valid project id";
117
      }
118

    
119
      this.downloadURLAPI = OpenaireProperties.getCsvAPIURL();
120

    
121
      this.createClipboard();
122
      this.csvParams = "format=csv-special&page=0&type=publications&query=(((oaftype exact result) and (resulttypeid exact publication)) and (relprojectid exact "+this.projectId+"))&size=";
123
      this.csvParamsDatasets = "format=csv-special&page=0&type=publications&query=(((oaftype exact result) and (resulttypeid exact dataset)) and (relprojectid exact "+this.projectId+"))&size=";
124

    
125
      if (typeof document !== 'undefined') {
126
         this.element.nativeElement.scrollIntoView();
127
      }
128
  });
129
}
130

    
131

    
132
  ngOnDestroy() {
133
    this.sub.unsubscribe();
134
    if(this.piwiksub){
135
  this.piwiksub.unsubscribe();
136
}
137
  }
138

    
139
  createClipboard() {
140
      if(typeof window !== 'undefined') {
141

    
142
          let publ_clipboard, datasets_clipboard;
143
          let Clipboard;
144
          Clipboard = require('clipboard');
145
          publ_clipboard = new Clipboard('.publ_clipboard_btn');
146
          datasets_clipboard = new Clipboard('.datasets_clipboard_btn');
147
      }
148
  }
149

    
150
  private searchPublications() {
151
    this.fetchPublications.getResultsForEntity("project", this.projectId, 1, 10);
152
    this.linkToSearchPublications = OpenaireProperties.getLinkToAdvancedSearchPublications();// + "?project=" + this.projectId+"&pr=and";
153
    if(this.fetchPublications.searchUtils.totalResults > 0) {
154
      //this.activeTab = "Publications";
155
    } else {
156
      //this.searchDatasetsInit();
157
    }
158
  }
159

    
160
  private searchDatasets() {
161
      this.fetchDatasets.getResultsForEntity("project", this.projectId, 1, 10);
162
      this.linkToSearchDatasets = OpenaireProperties.getLinkToAdvancedSearchDatasets();// + "?project=" + this.projectId+"&pr=and";
163

    
164
      this.reloadDatasets = false;
165
      //this.activeTab = "Research Data";
166
  }
167

    
168
  private searchDatasetsInit() {
169
    console.info("searchDatasetsInit");
170
      if(this.reloadDatasets && this.fetchDatasets.searchUtils.totalResults > 0) {
171
	      this.searchDatasets();
172
      } else if(this.fetchDatasets.searchUtils.totalResults == 0) {
173
        //this.statsClicked=true;
174
        //this.activeTab = "Statistics";
175
      }
176
  }
177

    
178
  getProjectInfo (id:string)  {
179
	  this.warningMessage = '';
180
    this.errorMessage=""
181
    this.showLoading = true;
182

    
183
    this._projectService.getProjectInfo(id).subscribe(
184
      data => {
185
          this.projectInfo = data;
186
console.info(this.projectInfo.title);
187
          this.projectName = this.projectInfo.acronym;
188
          if(this.projectName == undefined || this.projectName == '') {
189
              this.projectName = this.projectInfo.title;
190
          }
191
          this.updateTitle(this.projectName);
192
          this.updateDescription("project, funding, open access, publications, research data, "+this.projectName+ ","+this.projectInfo.funder);
193
          if(OpenaireProperties.isPiwikTrackEnabled() && (typeof document !== 'undefined')){
194
            this.piwiksub = this._piwikService.trackView(this.projectName).subscribe();
195
          }
196

    
197
          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 };
198

    
199
          this.viewsFrameUrl = OpenaireProperties.getFramesAPIURL()+'merge.php?com=query&data=[{"query":"projRepoViews","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=["column"]&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&persistent=false';
200
          /*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';
201
          */
202

    
203
          this.downloadsFrameUrl = OpenaireProperties.getFramesAPIURL()+'merge.php?com=query&data=[{"query":"projRepoDownloads","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=["column"]&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&persistent=false';
204
          /*
205
          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';
206
          */
207

    
208
          //stats tab charts
209
          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';
210
          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';
211
          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": "bar", "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';
212

    
213
          this.showLoading = false;
214
      },
215
      err => {
216
		      console.log(err);
217
		      this.errorMessage = 'No project found';
218
          this.showLoading = false;
219
		}
220
    );
221
   }
222
   downloadfile(url:string){
223
       this.openLoading();
224
       this.setMessageLoading("Downloading CSV file");
225

    
226
       this._reportsService.downloadCSVFile(url).subscribe(
227
            data => {
228
                this.closeLoading();
229
                window.open(window.URL.createObjectURL(data));
230
            },
231
            error => console.log("Error downloading the file."),
232
            () => console.log('Completed file download.')
233
        );
234
    }
235

    
236
    showHTML(){
237
      let info:string = "<h1>Publications of Project ";
238

    
239
      if(this.projectInfo.title != undefined && this.projectInfo.title != "") {
240
          info += this.projectInfo.title;
241
      }
242
      if((this.projectInfo.title != undefined && this.projectInfo.title != "") &&
243
         ((this.projectInfo.acronym != undefined && this.projectInfo.acronym != "") ||
244
          (this.projectInfo.callIdentifier != undefined && this.projectInfo.callIdentifier != ""))) {
245
                info += "(";
246
      }
247
      if(this.projectInfo.acronym != undefined && this.projectInfo.acronym != "") {
248
          info += this.projectInfo.acronym + " - ";
249
      }
250
      if(this.projectInfo.callIdentifier != undefined && this.projectInfo.callIdentifier != "") {
251
          info += this.projectInfo.callIdentifier;
252
      }
253
      if((this.projectInfo.title != undefined && this.projectInfo.title != "") &&
254
         ((this.projectInfo.acronym != undefined && this.projectInfo.acronym != "") ||
255
          (this.projectInfo.callIdentifier != undefined && this.projectInfo.callIdentifier != ""))) {
256
                info += ")";
257
      }
258
      info +="</h1>";
259
      info += "<h3>"+this.fetchPublications.searchUtils.totalResults+" publications</h3>";
260

    
261
      let htmlParams = 'resources?format=html&page=0&size='+this.fetchPublications.searchUtils.totalResults+'&type=publications&query=(((oaftype exact result) and (resulttypeid exact publication)) and (relprojectid exact "'+this.projectId+'"))';
262
      this._reportsService.downloadHTMLFile(this.downloadURLAPI+htmlParams, info)
263
          .subscribe(data => this.funct(data),
264
                      error => console.log("Error downloading the file."),
265
                      () => console.log('Completed file download.'));
266
     }
267
     funct(data) {
268
         var win = window.open(window.URL.createObjectURL(data));
269
     }
270

    
271
    public metricsResults($event) {
272
      this.totalViews = $event.totalViews;
273
      this.totalDownloads = $event.totalDownloads;
274
      this.pageViews = $event.pageViews;
275
    }
276
    updateDescription(description:string){
277
      this._meta.updateMeta("description", description);
278
      this._meta.updateProperty("og:description", description);
279
    }
280
    updateTitle(title:string){
281
      var _prefix ="OpenAIRE | ";
282
      var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
283
      this._meta.setTitle(_title );
284
      this._meta.updateProperty("og:title",_title);
285
    }
286
    updateUrl(url:string){
287
      this._meta.updateProperty("og:url", url);
288
    }
289

    
290
    public openLoading(){
291
      if(this.loading){
292
        this.loading.open();
293
      }
294
    }
295
    public closeLoading(){
296
      if(this.loading){
297
        this.loading.close();
298
      }
299
    }
300
    public setMessageLoading(message: string){
301
      if(this.loading){
302
        this.loading.message = message;
303
      }
304
    }
305

    
306
}
(3-3/6)