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
  public showLoading: boolean = true;
52

    
53
  sub: any;
54

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

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

    
65
  @ViewChild (ModalLoading) loading : ModalLoading ;
66

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

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

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

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

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

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

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

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

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

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

    
130

    
131
  ngOnDestroy() {
132
    this.sub.unsubscribe();
133
  }
134

    
135
  createClipboard() {
136
      if(typeof window !== 'undefined') {
137

    
138
          let publ_clipboard, datasets_clipboard;
139
          let Clipboard;
140
          Clipboard = require('clipboard');
141
          publ_clipboard = new Clipboard('.publ_clipboard_btn');
142
          datasets_clipboard = new Clipboard('.datasets_clipboard_btn');
143
      }
144
  }
145

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

    
156
  private searchDatasets() {
157
      this.fetchDatasets.getResultsForEntity("project", this.projectId, 1, 10);
158
      this.linkToSearchDatasets = OpenaireProperties.getLinkToAdvancedSearchDatasets();// + "?project=" + this.projectId+"&pr=and";
159

    
160
      this.reloadDatasets = false;
161
      //this.activeTab = "Research Data";
162
  }
163

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

    
174
  getProjectInfo (id:string)  {
175
	  this.warningMessage = '';
176
    this.errorMessage=""
177
    this.showLoading = true;
178

    
179
    this._projectService.getProjectInfo(id).subscribe(
180
      data => {
181
          this.projectInfo = data;
182
console.info(this.projectInfo.title);
183
          this.projectName = this.projectInfo.acronym;
184
          if(this.projectName == undefined || this.projectName == '') {
185
              this.projectName = this.projectInfo.title;
186
          }
187
          this.updateTitle(this.projectName);
188
          this.updateDescription("project, funding, open access, publications, datasets, "+this.projectName+ ","+this.projectInfo.funder);
189
          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 };
190

    
191
          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';
192
          /*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';
193
          */
194

    
195
          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';
196
          /*
197
          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';
198
          */
199

    
200
          //stats tab charts
201
          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';
202
          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';
203
          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';
204

    
205
          this.showLoading = false;
206
      },
207
      err => {
208
		      console.log(err);
209
		      this.errorMessage = 'No project found';
210
          this.showLoading = false;
211
		}
212
    );
213
   }
214
   downloadfile(url:string){
215
       this.openLoading();
216
       this.setMessageLoading("Downloading CSV file");
217

    
218
       this._reportsService.downloadCSVFile(url).subscribe(
219
            data => {
220
                this.closeLoading();
221
                window.open(window.URL.createObjectURL(data));
222
            },
223
            error => console.log("Error downloading the file."),
224
            () => console.log('Completed file download.')
225
        );
226
    }
227

    
228
    showHTML(){
229
      let info:string = "<h1>Publications of Project ";
230

    
231
      if(this.projectInfo.title != undefined && this.projectInfo.title != "") {
232
          info += this.projectInfo.title;
233
      }
234
      if((this.projectInfo.title != undefined && this.projectInfo.title != "") &&
235
         ((this.projectInfo.acronym != undefined && this.projectInfo.acronym != "") ||
236
          (this.projectInfo.callIdentifier != undefined && this.projectInfo.callIdentifier != ""))) {
237
                info += "(";
238
      }
239
      if(this.projectInfo.acronym != undefined && this.projectInfo.acronym != "") {
240
          info += this.projectInfo.acronym + " - ";
241
      }
242
      if(this.projectInfo.callIdentifier != undefined && this.projectInfo.callIdentifier != "") {
243
          info += this.projectInfo.callIdentifier;
244
      }
245
      if((this.projectInfo.title != undefined && this.projectInfo.title != "") &&
246
         ((this.projectInfo.acronym != undefined && this.projectInfo.acronym != "") ||
247
          (this.projectInfo.callIdentifier != undefined && this.projectInfo.callIdentifier != ""))) {
248
                info += ")";
249
      }
250
      info +="</h1>";
251
      info += "<h3>"+this.fetchPublications.searchUtils.totalResults+" publications</h3>";
252

    
253
      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+'"))';
254
      this._reportsService.downloadHTMLFile(this.downloadURLAPI+htmlParams, info)
255
          .subscribe(data => this.funct(data),
256
                      error => console.log("Error downloading the file."),
257
                      () => console.log('Completed file download.'));
258
     }
259
     funct(data) {
260
         var win = window.open(window.URL.createObjectURL(data));
261
     }
262

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

    
282
    public openLoading(){
283
      if(this.loading){
284
        this.loading.open();
285
      }
286
    }
287
    public closeLoading(){
288
      if(this.loading){
289
        this.loading.close();
290
      }
291
    }
292
    public setMessageLoading(message: string){
293
      if(this.loading){
294
        this.loading.message = message;
295
      }
296
    }
297

    
298
}
(3-3/6)