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
import { FetchSoftware } from '../../utils/fetchEntitiesClasses/fetchSoftware.class';
13
import { SearchSoftwareService } from '../../services/searchSoftware.service';
14

    
15
import {ModalLoading} from '../../utils/modal/loading.component';
16

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

    
21
import {PiwikService} from '../../utils/piwik/piwik.service';
22

    
23
@Component({
24
    selector: 'project',
25
    templateUrl: 'project.component.html',
26
 })
27
export class ProjectComponent{
28
  public projectInfo: ProjectInfo;
29
  public projectId : string ;
30
  public projectName: string;
31

    
32
  // Metrics tab variables
33
  public metricsClicked: boolean;
34
  public viewsFrameUrl: string;
35
  public downloadsFrameUrl: string;
36
  private totalViews: number;
37
  private totalDownloads: number;
38
  private pageViews: number;
39

    
40
  // Statistics tab variables
41
  public statsClicked: boolean;
42
  public chartScientificResultsUrl: string;
43
  public chartAccessModeUrl: string;
44
  public chartDatasourcesUrl: string;
45

    
46
  // HTML variables in APP BOX
47
  public publications_dynamic: string;
48
  public datasets_dynamic: string;
49

    
50
  public project ;
51

    
52
  // CSV variables
53
  public downloadURLAPI: string;
54
  public csvParams: string;
55
  public csvParamsDatasets: string;
56

    
57
  // Message variables
58
  public warningMessage = "";
59
  public errorMessage = "";
60
  public showLoading: boolean = true;
61

    
62
  // Active tab variable for responsiveness
63
  public activeTab: string = "Publications";
64

    
65
  // Request results for research data and software only the one time (first time tab is clicked)
66
  private reloadDatasets: boolean = true;
67
  private reloadSoftware: boolean = true;
68

    
69
  // Variables for publications, research data, software tabs
70
  public fetchPublications : FetchPublications;
71
  public linkToSearchPublications = "";
72
  public fetchDatasets : FetchDatasets;
73
  public linkToSearchDatasets = "";
74
  public fetchSoftware: FetchSoftware;
75
  public linkToSearchSoftware = "";
76

    
77
  public routerHelper:RouterHelper = new RouterHelper();
78
  public errorCodes:ErrorCodes = new ErrorCodes();
79

    
80
  @ViewChild (ModalLoading) loading : ModalLoading ;
81
  // Alert box when something is wrong with CSV requests
82
  @ViewChild('AlertModalCsvError') alertCsvError;
83

    
84
  sub: any; piwiksub: any; infoSub: any; downloadFilePiwikSub: any;
85

    
86
  constructor ( private element: ElementRef,
87
                private _projectService: ProjectService,
88
                private _piwikService:PiwikService,
89
                private  route: ActivatedRoute,
90
                private _searchPublicationsService: SearchPublicationsService,
91
                private _searchDatasetsService: SearchDatasetsService,
92
                private _searchSoftwareService: SearchSoftwareService,
93
                private _reportsService: ReportsService, private _meta: Meta,
94
                private _router: Router) {
95
    this.updateUrl(OpenaireProperties.getBaseLink()+this._router.url);
96
  }
97

    
98
  ngOnInit() {
99
    this.sub =  this.route.queryParams.subscribe(params => {
100
        this.metricsClicked = false;
101
        this.statsClicked = false;
102
        this.fetchPublications = new FetchPublications( this._searchPublicationsService);
103
        this.fetchDatasets = new FetchDatasets(this._searchDatasetsService);
104
        this.fetchSoftware = new FetchSoftware(this._searchSoftwareService);
105

    
106
        this.updateTitle("Project");
107
        this.updateDescription("project, funding, open access, publications, research data, software");
108

    
109
      this.projectId = params['projectId'];
110
       if(this.projectId){
111
           this.publications_dynamic =
112
                "<script type=\"text/javascript\">"
113
                + "\n<!--"
114
                + "\ndocument.write('<div id=\"oa_widget\"></div>');"
115
                + "\ndocument.write('<script type=\"text/javascript\""
116
                + "\nsrc=\"https://beta.openaire.eu/index.php?option=com_openaire&view=widget&format=raw&projectId="
117
                + this.projectId + "&type=publication\"></script>');"
118
                + "\n-->"
119
                + "\n</script>";
120

    
121
            this.datasets_dynamic =
122
                "<script type=\"text/javascript\">"
123
                + "\n<!--"
124
                + "\ndocument.write('<div id=\"oa_widget\"></div>');"
125
                + "\ndocument.write('<script type=\"text/javascript\""
126
                + "\nsrc=\"https://beta.openaire.eu/index.php?option=com_openaire&view=widget&format=raw&projectId="
127
                + this.projectId + "&type=dataset\"></script>');"
128
                + "\n-->"
129
                + "\n</script>";
130

    
131
          this.getProjectInfo(this.projectId);
132
          this.searchPublications();
133
          this.fetchDatasets.getNumForEntity("project", this.projectId);
134
          this.fetchSoftware.getNumForEntity("project", this.projectId);
135
      }else{
136
          this.showLoading = false;
137
		      this.warningMessage="No valid project id";
138
      }
139

    
140
      this.downloadURLAPI = OpenaireProperties.getCsvAPIURL();
141

    
142
      this.createClipboard();
143
      this.csvParams = "format=csv-special&page=0&type=publications&query=(((oaftype exact result) and (resulttypeid exact publication)) and (relprojectid exact "+this.projectId+"))&size=";
144
      this.csvParamsDatasets = "format=csv-special&page=0&type=datasets&query=(((oaftype exact result) and (resulttypeid exact dataset)) and (relprojectid exact "+this.projectId+"))&size=";
145

    
146
      if (typeof document !== 'undefined') {
147
         this.element.nativeElement.scrollIntoView();
148
      }
149
  });
150
}
151

    
152

    
153
  ngOnDestroy() {
154
    this.sub.unsubscribe();
155
    if(this.piwiksub){
156
      this.piwiksub.unsubscribe();
157
    }
158
    if(this.infoSub) {
159
      this.infoSub.unsubscribe();
160
    }
161
    if(this.downloadFilePiwikSub) {
162
      this.downloadFilePiwikSub.unsubscribe();
163
    }
164
  }
165

    
166
  private createClipboard() {
167
      if(typeof window !== 'undefined') {
168

    
169
          let publ_clipboard, datasets_clipboard;
170
          let Clipboard;
171
          Clipboard = require('clipboard');
172
          publ_clipboard = new Clipboard('.publ_clipboard_btn');
173
          datasets_clipboard = new Clipboard('.datasets_clipboard_btn');
174
      }
175
  }
176

    
177
  private searchPublications() {
178
    this.fetchPublications.getResultsForEntity("project", this.projectId, 1, 10);
179
    this.linkToSearchPublications = OpenaireProperties.getLinkToAdvancedSearchPublications();// + "?project=" + this.projectId+"&pr=and";
180
    if(this.fetchPublications.searchUtils.totalResults > 0) {
181
      //this.activeTab = "Publications";
182
    } else {
183
      //this.searchDatasetsInit();
184
    }
185
  }
186

    
187
  private searchDatasets() {
188
      this.fetchDatasets.getResultsForEntity("project", this.projectId, 1, 10);
189
      this.linkToSearchDatasets = OpenaireProperties.getLinkToAdvancedSearchDatasets();// + "?project=" + this.projectId+"&pr=and";
190

    
191
      this.reloadDatasets = false;
192
      //this.activeTab = "Research Data";
193
  }
194

    
195
  private searchSoftware() {
196
      this.fetchSoftware.getResultsForEntity("project", this.projectId, 1, 10);
197
      this.linkToSearchSoftware = OpenaireProperties.getLinkToAdvancedSearchSoftware();
198
      this.reloadSoftware = false;
199
  }
200

    
201
  public searchDatasetsInit() {
202
    console.info("searchDatasetsInit");
203
      if(this.reloadDatasets && this.fetchDatasets.searchUtils.totalResults > 0) {
204
	      this.searchDatasets();
205
      } else if(this.fetchDatasets.searchUtils.totalResults == 0) {
206
        //this.statsClicked=true;
207
        //this.activeTab = "Statistics";
208
      }
209
  }
210

    
211
  public searchSoftwareInit() {
212
    console.info("searchSoftwareInit");
213
      if(this.reloadSoftware && this.fetchSoftware.searchUtils.totalResults > 0) {
214
	      this.searchSoftware();
215
      }
216
  }
217

    
218
  private getProjectInfo (id:string)  {
219
	  this.warningMessage = '';
220
    this.errorMessage=""
221
    this.showLoading = true;
222

    
223
    this.infoSub = this._projectService.getProjectInfo(id).subscribe(
224
      data => {
225
          this.projectInfo = data;
226

    
227
          this.projectName = this.projectInfo.acronym;
228
          if(this.projectName == undefined || this.projectName == '') {
229
              this.projectName = this.projectInfo.title;
230
          }
231
          this.updateTitle(this.projectName);
232
          this.updateDescription("project, funding, open access, publications, research data, "+this.projectName+ ","+this.projectInfo.funder);
233
          if(OpenaireProperties.isPiwikTrackEnabled() && (typeof document !== 'undefined')){
234
            this.piwiksub = this._piwikService.trackView(this.projectName).subscribe();
235
          }
236

    
237
          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 };
238

    
239
          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';
240

    
241
          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';
242

    
243
          //stats tab charts
244
          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": ["Research Results"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [" "], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=600&h=250';
245
          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": ["Research Results"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [" "], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=600&h=250';
246
          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": ["Research Results"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [" "], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=600&h=250';
247

    
248
          this.showLoading = false;
249
      },
250
      err => {
251
		      console.log(err);
252
		      this.errorMessage = 'No project found';
253
          this.showLoading = false;
254
		  }
255
    );
256
   }
257

    
258
   public downloadfile(url:string){
259
       this.openLoading();
260
       this.setMessageLoading("Downloading CSV file");
261

    
262
       this._reportsService.downloadCSVFile(url).subscribe(
263
            data => {
264
                this.closeLoading();
265
                window.open(window.URL.createObjectURL(data));
266
                if(OpenaireProperties.isPiwikTrackEnabled() && (typeof document !== 'undefined')){
267
                  this.downloadFilePiwikSub = this._piwikService.trackDownload(url).subscribe();
268
                }
269
            },
270
            error => {
271
              console.log("Error downloading the file.");
272
              this.closeLoading();
273
              this.confirmOpenCsvError();
274
            },
275
            () => console.log('Completed file download.')
276
        );
277
    }
278

    
279
/*
280
    showHTML(){
281
      let info:string = "<h1>Publications of Project ";
282

    
283
      if(this.projectInfo.title != undefined && this.projectInfo.title != "") {
284
          info += this.projectInfo.title;
285
      }
286
      if((this.projectInfo.title != undefined && this.projectInfo.title != "") &&
287
         ((this.projectInfo.acronym != undefined && this.projectInfo.acronym != "") ||
288
          (this.projectInfo.callIdentifier != undefined && this.projectInfo.callIdentifier != ""))) {
289
                info += "(";
290
      }
291
      if(this.projectInfo.acronym != undefined && this.projectInfo.acronym != "") {
292
          info += this.projectInfo.acronym + " - ";
293
      }
294
      if(this.projectInfo.callIdentifier != undefined && this.projectInfo.callIdentifier != "") {
295
          info += this.projectInfo.callIdentifier;
296
      }
297
      if((this.projectInfo.title != undefined && this.projectInfo.title != "") &&
298
         ((this.projectInfo.acronym != undefined && this.projectInfo.acronym != "") ||
299
          (this.projectInfo.callIdentifier != undefined && this.projectInfo.callIdentifier != ""))) {
300
                info += ")";
301
      }
302
      info +="</h1>";
303
      info += "<h3>"+this.fetchPublications.searchUtils.totalResults+" publications</h3>";
304

    
305
      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+'"))';
306
      this._reportsService.downloadHTMLFile(this.downloadURLAPI+htmlParams, info)
307
          .subscribe(data => this.funct(data),
308
                      error => console.log("Error downloading the file."),
309
                      () => console.log('Completed file download.'));
310
     }
311

    
312
     funct(data) {
313
         var win = window.open(window.URL.createObjectURL(data));
314
     }
315
*/
316
    public metricsResults($event) {
317
      this.totalViews = $event.totalViews;
318
      this.totalDownloads = $event.totalDownloads;
319
      this.pageViews = $event.pageViews;
320
    }
321

    
322
    private updateDescription(description:string){
323
      this._meta.updateMeta("description", description);
324
      this._meta.updateProperty("og:description", description);
325
    }
326
    private updateTitle(title:string){
327
      var _prefix ="OpenAIRE | ";
328
      var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
329
      this._meta.setTitle(_title );
330
      this._meta.updateProperty("og:title",_title);
331
    }
332
    private updateUrl(url:string){
333
      this._meta.updateProperty("og:url", url);
334
    }
335

    
336
    private openLoading(){
337
      if(this.loading){
338
        this.loading.open();
339
      }
340
    }
341
    private closeLoading(){
342
      if(this.loading){
343
        this.loading.close();
344
      }
345
    }
346
    private setMessageLoading(message: string){
347
      if(this.loading){
348
        this.loading.message = message;
349
      }
350
    }
351

    
352
    public confirmOpenCsvError(){
353
      this.alertCsvError.cancelButton = false;
354
      this.alertCsvError.okButton = true;
355
      this.alertCsvError.alertTitle = "ERROR DOWNLOADING CSV FILE";
356
      this.alertCsvError.message = "There was an error in csv downloading. Please try again later.";
357
      this.alertCsvError.okButtonText = "OK";
358
      this.alertCsvError.open();
359
    }
360
}
(3-3/6)