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

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

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

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

    
43
  public project ;
44

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

    
49
  public warningMessage = "";
50
  public errorMessage = "";
51

    
52
  sub: any;
53
  subPublications: any;
54
  subDatasets: any;
55
  subDatasetsCount: any;
56

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

    
64
  @ViewChild (ModalLoading) loading : ModalLoading ;
65

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

    
76
  ngOnInit() {
77
    this.sub =  this.route.queryParams.subscribe(params => {
78
        this.metricsClicked = false;
79
        this.statsClicked = false;
80

    
81
        this.fetchPublications = new FetchPublications( this._searchPublicationsService);
82
        this.fetchDatasets = new FetchDatasets(this._searchDatasetsService);
83

    
84
        this.updateTitle("Project");
85
        this.updateDescription("project, funding, open access, publications, datasets, ");
86

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

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

    
109
          this.getProjectInfo(this.projectId);
110
          //  this.subPublications =  this.route.queryParams.subscribe(params => {
111
          this.searchPublications();
112
          //  });
113

    
114
          //this.subDatasetsCount = this._searchDatasetsService.numOfEntityDatasets(this.projectId, "projects/").subscribe(
115
          //  data => {
116
          //    this.fetchDatasets.searchUtils.totalResults = data;
117
          //  },
118
          //  err => {
119
          //    console.log(err);
120
          //  }
121
          //);
122
          this.fetchDatasets.getNumResultsForEntity("project", this.projectId);
123

    
124
      }else{
125
		      this.warningMessage="No valid project id";
126
      }
127

    
128
      this.downloadURLAPI = OpenaireProperties.getCsvAPIURL();
129

    
130
      this.createClipboard();
131
      this.csvParams = "format=csv-special&page=0&type=publications&query=(((oaftype exact result) and (resulttypeid exact publication)) and (relprojectid exact "+this.projectId+"))&size=";
132
      this.csvParamsDatasets = "format=csv-special&page=0&type=publications&query=(((oaftype exact result) and (resulttypeid exact dataset)) and (relprojectid exact "+this.projectId+"))&size=";
133

    
134
      if (typeof document !== 'undefined') {
135
         this.element.nativeElement.scrollIntoView();
136
      }
137
  });
138
}
139

    
140

    
141
  ngOnDestroy() {
142
    this.sub.unsubscribe();
143
    //this.subDatasetsCount.unsubscribe();
144
  }
145

    
146
  createClipboard() {
147
      if(typeof window !== 'undefined') {
148

    
149
          let publ_clipboard, datasets_clipboard;
150
          let Clipboard;
151
          Clipboard = require('clipboard');
152
          publ_clipboard = new Clipboard('.publ_clipboard_btn');
153
          datasets_clipboard = new Clipboard('.datasets_clipboard_btn');
154
      }
155
  }
156

    
157
  private searchPublications() {
158
    this.fetchPublications.getResultsForEntity("project", this.projectId, 1, 10);
159
    this.linkToSearchPublications = OpenaireProperties.getLinkToAdvancedSearchPublications();// + "?project=" + this.projectId+"&pr=and";
160
  }
161

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

    
167
  private searchDatasetsInit() {
168
      if(this.subDatasets == undefined && this.fetchDatasets.searchUtils.totalResults > 0) {
169
	      this.searchDatasets();
170
      }
171
  }
172

    
173
  getProjectInfo (id:string)  {
174
	  this.warningMessage = '';
175
    this.errorMessage=""
176
    this._projectService.getProjectInfo(id).subscribe(
177
      data => {
178
          this.projectInfo = data;
179
console.info(this.projectInfo.title);
180
          this.projectName = this.projectInfo.acronym;
181
          if(this.projectName == undefined || this.projectName == '') {
182
              this.projectName = this.projectInfo.title;
183
          }
184
          this.updateTitle(this.projectName);
185
          this.updateDescription("project, funding, open access, publications, datasets, "+this.projectName+ ","+this.projectInfo.funder);
186
          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 };
187

    
188
          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=["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&persistent=false';
189
          /*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';
190
          */
191

    
192
          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=["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&persistent=false';
193
          /*
194
          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';
195
          */
196

    
197
          //stats tab charts
198
          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';
199
          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';
200
          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';
201
      },
202
      err => {
203
		console.log(err);
204
		this.errorMessage = 'No project found';
205
		}
206
    );
207
   }
208
   downloadfile(url:string){
209
       this.openLoading();
210
       this.setMessageLoading("Downloading CSV file");
211

    
212
       this._reportsService.downloadCSVFile(url).subscribe(
213
            data => {
214
                this.closeLoading();
215
                window.open(window.URL.createObjectURL(data));
216
            },
217
            error => console.log("Error downloading the file."),
218
            () => console.log('Completed file download.')
219
        );
220
    }
221

    
222
    showHTML(){
223
      let info:string = "<h1>Publications of Project ";
224

    
225
      if(this.projectInfo.title != undefined && this.projectInfo.title != "") {
226
          info += this.projectInfo.title;
227
      }
228
      if((this.projectInfo.title != undefined && this.projectInfo.title != "") &&
229
         ((this.projectInfo.acronym != undefined && this.projectInfo.acronym != "") ||
230
          (this.projectInfo.callIdentifier != undefined && this.projectInfo.callIdentifier != ""))) {
231
                info += "(";
232
      }
233
      if(this.projectInfo.acronym != undefined && this.projectInfo.acronym != "") {
234
          info += this.projectInfo.acronym + " - ";
235
      }
236
      if(this.projectInfo.callIdentifier != undefined && this.projectInfo.callIdentifier != "") {
237
          info += this.projectInfo.callIdentifier;
238
      }
239
      if((this.projectInfo.title != undefined && this.projectInfo.title != "") &&
240
         ((this.projectInfo.acronym != undefined && this.projectInfo.acronym != "") ||
241
          (this.projectInfo.callIdentifier != undefined && this.projectInfo.callIdentifier != ""))) {
242
                info += ")";
243
      }
244
      info +="</h1>";
245
      info += "<h3>"+this.fetchPublications.searchUtils.totalResults+" publications</h3>";
246

    
247
      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+'"))';
248
      this._reportsService.downloadHTMLFile(this.downloadURLAPI+htmlParams, info)
249
          .subscribe(data => this.funct(data),
250
                      error => console.log("Error downloading the file."),
251
                      () => console.log('Completed file download.'));
252
     }
253
     funct(data) {
254
         var win = window.open(window.URL.createObjectURL(data));
255
     }
256

    
257
    public metricsResults($event) {
258
      this.totalViews = $event.totalViews;
259
      this.totalDownloads = $event.totalDownloads;
260
      this.pageViews = $event.pageViews;
261
    }
262
    updateDescription(description:string){
263
      this._meta.updateMeta("description", description);
264
      this._meta.updateProperty("og:description", description);
265
    }
266
    updateTitle(title:string){
267
      var _suffix ="| OpenAIRE";
268
      var _title = ((title.length> 50 ) ?title.substring(0,50):title) + _suffix;
269
      this._meta.setTitle(_title );
270
      this._meta.updateProperty("og:title",_title);
271
    }
272
    updateUrl(url:string){
273
      this._meta.updateProperty("og:url", url);
274
    }
275

    
276
    public openLoading(){
277
      if(this.loading){
278
        this.loading.open();
279
      }
280
    }
281
    public closeLoading(){
282
      if(this.loading){
283
        this.loading.close();
284
      }
285
    }
286
    public setMessageLoading(message: string){
287
      if(this.loading){
288
        this.loading.message = message;
289
      }
290
    }
291

    
292
}
(3-3/6)