Project

General

Profile

1
import {Component, Input, ViewChild} from '@angular/core';
2
import {ActivatedRoute, Router} from '@angular/router';
3
import {Meta, Title} from '@angular/platform-browser';
4

    
5
import {ProjectService} from './project.service';
6
import {ProjectInfo} from '../../utils/entities/projectInfo';
7
import {RouterHelper} from '../../utils/routerHelper.class';
8

    
9
import {FetchResearchResults} from '../../utils/fetchEntitiesClasses/fetchResearchResults.class';
10
import {SearchResearchResultsService} from '../../services/searchResearchResults.service';
11

    
12
import {ModalLoading} from '../../utils/modal/loading.component';
13

    
14
import {ReportsService} from '../../services/reports.service';
15
import {ErrorCodes} from '../../utils/properties/errorCodes'
16

    
17
import {PiwikService} from '../../utils/piwik/piwik.service';
18
import {EnvProperties} from '../../utils/properties/env-properties';
19
import {SEOService} from '../../sharedComponents/SEO/SEO.service';
20
import {HelperFunctions} from "../../utils/HelperFunctions.class";
21
import {HelperService} from "../../utils/helper/helper.service";
22

    
23
@Component({
24
  selector: 'project',
25
  templateUrl: 'project.component.html',
26
})
27

    
28
export class ProjectComponent {
29
  @Input() piwikSiteId = null;
30
  @Input() communityId = null;
31
  public projectInfo: ProjectInfo;
32
  public projectId: string;
33
  public projectName: string;
34

    
35
  // Metrics tab variables
36
  public metricsClicked: boolean;
37
  public viewsFrameUrl: string;
38
  public downloadsFrameUrl: string;
39
  private totalViews: number;
40
  private totalDownloads: number;
41
  private pageViews: number;
42

    
43
  // Statistics tab variables
44
  public statsClicked: boolean;
45
  public chartScientificResultsUrl: string;
46
  public chartAccessModeUrl: string;
47
  public chartDatasourcesUrl: string;
48

    
49
  // HTML variables in APP BOX
50
  public publications_dynamic: string;
51
  public datasets_dynamic: string;
52
  public software_dynamic: string;
53
  public orps_dynamic: string;
54

    
55
  public project;
56

    
57
  // CSV variables
58
  public downloadURLAPI: string;
59
  public csvParams: string;
60
  public csvParamsDatasets: string;
61
  public csvParamsSoftware: string;
62
  public csvParamsOrps: string;
63

    
64
  // Message variables
65
  public warningMessage = "";
66
  public errorMessage = "";
67
  public showLoading: boolean = true;
68

    
69
  // Active tab variable for responsiveness
70
  public activeTab: string = "Publications";
71

    
72
  // Request results for publications, research data and software only the one time (first time tab is clicked)
73
  private reloadPublications: boolean = true;
74
  private reloadDatasets: boolean = true;
75
  private reloadSoftware: boolean = true;
76
  private reloadOrps: boolean = true;
77

    
78
  // Variables for publications, research data, software tabs
79
  public fetchPublications: FetchResearchResults;
80
  public linkToSearchPublications = "";
81
  public fetchDatasets: FetchResearchResults;
82
  public linkToSearchDatasets = "";
83
  public fetchSoftware: FetchResearchResults;
84
  public linkToSearchSoftware = "";
85
  public fetchOrps: FetchResearchResults;
86
  public linkToSearchOrps = "";
87

    
88
  public routerHelper: RouterHelper = new RouterHelper();
89
  public errorCodes: ErrorCodes = new ErrorCodes();
90
  public pageContents = null;
91
  public divContents = null;
92

    
93
  @ViewChild(ModalLoading) loading: ModalLoading;
94
  // Alert box when something is wrong with CSV requests
95
  @ViewChild('AlertModalCsvError') alertCsvError;
96

    
97
  sub: any;
98
  piwiksub: any;
99
  infoSub: any;
100
  downloadFilePiwikSub: any;
101
  properties: EnvProperties;
102

    
103
  constructor(private _projectService: ProjectService,
104
              private _piwikService: PiwikService,
105
              private  route: ActivatedRoute,
106
              private router: Router,
107
              private _searchResearchResultsService: SearchResearchResultsService,
108
              private _reportsService: ReportsService,
109
              private _meta: Meta,
110
              private _title: Title,
111
              private _router: Router,
112
              private helper: HelperService,
113
              private seoService: SEOService) {
114
  }
115

    
116
  ngOnInit() {
117
    this.route.data
118
      .subscribe((data: { envSpecific: EnvProperties }) => {
119
        this.properties = data.envSpecific;
120
        //this.getDivContents();
121
        this.getPageContents();
122
        this.updateUrl(data.envSpecific.baseLink + this._router.url);
123

    
124
      });
125
    this.sub = this.route.queryParams.subscribe(params => {
126
      this.metricsClicked = false;
127
      this.statsClicked = false;
128
      this.fetchPublications = new FetchResearchResults(this._searchResearchResultsService);
129
      this.fetchDatasets = new FetchResearchResults(this._searchResearchResultsService);
130
      this.fetchSoftware = new FetchResearchResults(this._searchResearchResultsService);
131
      this.fetchOrps = new FetchResearchResults(this._searchResearchResultsService);
132

    
133
      var title = "Project";
134
      var description = "";
135

    
136
      this.updateTitle(title);
137
      this.updateDescription(description);
138
      this.projectId = params['projectId'];
139
      var grantId = params['grantId'];
140
      var funder = params['funder'];
141

    
142

    
143
      if (this.projectId) {
144
        this.getProjectInfo(this.projectId);
145
        this.actionsAfterLoadId();
146
      } else if (grantId && funder) {
147
        this.getProjectInfoByGrantId(grantId, funder);
148
      } else {
149

    
150
        this.showLoading = false;
151
        this._router.navigate(['/error'], {queryParams: {"page": this.properties.searchLinkToProject + this.projectId, "page_type": "project"}});
152
        //this.warningMessage = "No valid project id";
153
      }
154

    
155
      this.downloadURLAPI = this.properties.csvAPIURL;
156

    
157
      this.createClipboard();
158
      this.csvParams = "?format=csv-special&type=publications&fq=(((oaftype exact result) and (resulttypeid exact publication)) and (relprojectid exact \"" + this.projectId + "\"))";
159
      this.csvParamsDatasets = "?format=csv-special&type=datasets&fq=(((oaftype exact result) and (resulttypeid exact dataset)) and (relprojectid exact \"" + this.projectId + "\"))";
160
      this.csvParamsSoftware = "?format=csv-special&type=software&fq=(((oaftype exact result) and (resulttypeid exact software)) and (relprojectid exact \"" + this.projectId + "\"))";
161
      this.csvParamsOrps = "?format=csv-special&type=other&fq=(((oaftype exact result) and (resulttypeid exact other)) and (relprojectid exact \"" + this.projectId + "\"))";
162

    
163
      HelperFunctions.scroll();
164
    });
165
  }
166

    
167
  private getPageContents() {
168
    this.helper.getPageHelpContents(this._router.url, this.properties, this.communityId).subscribe(contents => {
169
      this.pageContents = contents;
170
    })
171
  }
172

    
173
  private getDivContents() {
174
    this.helper.getDivHelpContents(this._router.url, this.properties, this.communityId).subscribe(contents => {
175
      this.divContents = contents;
176
    })
177
  }
178

    
179
  actionsAfterLoadId() {
180
    this.publications_dynamic =
181
      "<script type=\"text/javascript\">"
182
      + "\n<!--"
183
      + "\ndocument.write('<div id=\"oa_widget\"></div>');"
184
      + "\ndocument.write('<script type=\"text/javascript\""
185
      + " src=\"" + this.properties.widgetLink
186
      + this.projectId + "&type=publication\"></script>');"
187
      + "\n-->"
188
      + "\n</script>";
189

    
190
    this.datasets_dynamic =
191
      "<script type=\"text/javascript\">"
192
      + "\n<!--"
193
      + "\ndocument.write('<div id=\"oa_widget\"></div>');"
194
      + "\ndocument.write('<script type=\"text/javascript\""
195
      + " src=\"" + this.properties.widgetLink
196
      + this.projectId + "&type=dataset\"></script>');"
197
      + "\n-->"
198
      + "\n</script>";
199

    
200
    this.software_dynamic =
201
      "<script type=\"text/javascript\">"
202
      + "\n<!--"
203
      + "\ndocument.write('<div id=\"oa_widget\"></div>');"
204
      + "\ndocument.write('<script type=\"text/javascript\""
205
      + "\nsrc=\"" + this.properties.widgetLink
206
      + this.projectId + "&type=software\"></script>');"
207
      + "\n-->"
208
      + "\n</script>";
209

    
210
    this.orps_dynamic =
211
      "<script type=\"text/javascript\">"
212
      + "\n<!--"
213
      + "\ndocument.write('<div id=\"oa_widget\"></div>');"
214
      + "\ndocument.write('<script type=\"text/javascript\""
215
      + "\nsrc=\"" + this.properties.widgetLink
216
      + this.projectId + "&type=other\"></script>');"
217
      + "\n-->"
218
      + "\n</script>";
219

    
220
    this.getProjectInfo(this.projectId);
221
    //this.searchPublications();
222
    this.fetchPublications.getNumForEntity("publication", "project", this.projectId, this.properties);
223
    this.fetchDatasets.getNumForEntity("dataset", "project", this.projectId, this.properties);
224
    this.fetchSoftware.getNumForEntity("software", "project", this.projectId, this.properties);
225
    this.fetchOrps.getNumForEntity("other", "project", this.projectId, this.properties);
226
  }
227

    
228
  ngOnDestroy() {
229
    if (this.sub) {
230
      this.sub.unsubscribe();
231
    }
232
    if (this.piwiksub) {
233
      this.piwiksub.unsubscribe();
234
    }
235
    if (this.infoSub) {
236
      this.infoSub.unsubscribe();
237
    }
238
    if (this.downloadFilePiwikSub) {
239
      this.downloadFilePiwikSub.unsubscribe();
240
    }
241
  }
242

    
243
  private createClipboard() {
244
    if (typeof window !== 'undefined') {
245

    
246
      let publ_clipboard, datasets_clipboard, software_clipboard, orps_clipboard;
247
      let Clipboard;
248
      Clipboard = require('clipboard');
249
      publ_clipboard = new Clipboard('.publ_clipboard_btn');
250
      datasets_clipboard = new Clipboard('.datasets_clipboard_btn');
251
      software_clipboard = new Clipboard('.software_clipboard_btn');
252
      orps_clipboard = new Clipboard('.orps_clipboard_btn');
253
    }
254
  }
255

    
256
  private searchPublications() {
257
    this.fetchPublications.getResultsForEntity("publication", "project", this.projectId, 1, 10, this.properties);
258
    this.linkToSearchPublications = this.properties.searchLinkToAdvancedPublications;// + "?project=" + this.projectId+"&pr=and";
259
    //if(this.fetchPublications.searchUtils.totalResults > 0) {
260
    //this.activeTab = "Publications";
261
    //} else {
262
    //this.searchDatasetsInit();
263
    //}
264
    this.reloadPublications = false;
265
  }
266

    
267
  private searchDatasets() {
268
    this.fetchDatasets.getResultsForEntity("dataset", "project", this.projectId, 1, 10, this.properties);
269
    this.linkToSearchDatasets = this.properties.searchLinkToAdvancedDatasets;// + "?project=" + this.projectId+"&pr=and";
270

    
271
    this.reloadDatasets = false;
272
    //this.activeTab = "Research Data";
273
  }
274

    
275
  private searchSoftware() {
276
    this.fetchSoftware.getResultsForEntity("software", "project", this.projectId, 1, 10, this.properties);
277
    this.linkToSearchSoftware = this.properties.searchLinkToAdvancedSoftware;
278
    this.reloadSoftware = false;
279
  }
280

    
281
  private searchOrps() {
282
    this.fetchOrps.getResultsForEntity("other", "project", this.projectId, 1, 10, this.properties);
283
    this.linkToSearchOrps = this.properties.searchLinkToAdvancedOrps;
284
    this.reloadOrps = false;
285
  }
286

    
287
  public searchPublicationsInit() {
288
    if (this.reloadPublications && this.fetchPublications.searchUtils.totalResults > 0) {
289
      this.searchPublications();
290
    } else if (this.fetchPublications.searchUtils.totalResults == 0) {
291
      //this.statsClicked=true;
292
      //this.activeTab = "Statistics";
293
    }
294
  }
295

    
296
  public searchDatasetsInit() {
297
    if (this.reloadDatasets && this.fetchDatasets.searchUtils.totalResults > 0) {
298
      this.searchDatasets();
299
    } else if (this.fetchDatasets.searchUtils.totalResults == 0) {
300
      //this.statsClicked=true;
301
      //this.activeTab = "Statistics";
302
    }
303
  }
304

    
305
  public searchSoftwareInit() {
306
    if (this.reloadSoftware && this.fetchSoftware.searchUtils.totalResults > 0) {
307
      this.searchSoftware();
308
    }
309
  }
310

    
311
  public searchOrpsInit() {
312
    if (this.reloadOrps && this.fetchOrps.searchUtils.totalResults > 0) {
313
      this.searchOrps();
314
    }
315
  }
316

    
317
  private getProjectInfo(id: string) {
318
    this.warningMessage = '';
319
    this.errorMessage = ""
320
    this.showLoading = true;
321

    
322
    this.projectInfo = null;
323

    
324
    this.infoSub = this._projectService.getProjectInfo(id, this.properties).subscribe(
325
      data => {
326
        this.projectInfo = data;
327

    
328
        this.actionsAfterGettingProjectInfo();
329
      },
330
      err => {
331
        //console.log(err);
332
        this.handleError("Error getting project for id: " + this.projectId, err);
333
        if(err.status == 404) {
334
          this._router.navigate(['/error'], {queryParams: {"page": this.properties.searchLinkToProject + this.projectId, "page_type": "project"}});
335
        }
336
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToProjects);
337
        //this.errorMessage = 'No project found';
338
        this.showLoading = false;
339
      }
340
    );
341
  }
342

    
343
  private getProjectInfoByGrantId(grantId: string, funder: string) {
344
    this.warningMessage = '';
345
    this.errorMessage = ""
346
    this.showLoading = true;
347

    
348
    this.projectInfo = null;
349

    
350
    this._projectService.getProjectInfoByGrantId(grantId, funder, this.properties).subscribe(
351
      data => {
352

    
353
        this.projectInfo = data;
354

    
355
        this.actionsAfterGettingProjectInfo();
356
        this.projectId = this.projectInfo.id;
357
        this.actionsAfterLoadId();
358
      },
359
      err => {
360
        //console.log(err);
361
        this.handleError("Error getting project for grant id: " + grantId + " and funder: " + funder, err);
362
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToProjects);
363
        this.errorMessage = 'No project found';
364
        this.showLoading = false;
365
      }
366
    );
367
  }
368

    
369
  actionsAfterGettingProjectInfo() {
370
    this.projectName = this.projectInfo.acronym;
371
    if (this.projectName == undefined || this.projectName == '') {
372
      this.projectName = this.projectInfo.title;
373
    }
374
    this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this._router.url);
375
    this.updateTitle(this.projectName);
376
    this.updateDescription("project, " + this.projectName + "," + this.projectInfo.funder + "," + this.projectInfo.acronym);
377
    if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
378
      this.piwiksub = this._piwikService.trackView(this.properties, this.projectName, this.piwikSiteId).subscribe();
379
    }
380

    
381
    this.project = {
382
      funderId: "",
383
      funderName: this.projectInfo.funder,
384
      projectId: this.projectId,
385
      projectName: this.projectInfo.title,
386
      projectAcronym: this.projectInfo.acronym,
387
      startDate: this.projectInfo.startDate,
388
      endDate: this.projectInfo.endDate
389
    };
390

    
391
    this.viewsFrameUrl = this.properties.framesAPIURL + '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';
392

    
393
    this.downloadsFrameUrl = this.properties.framesAPIURL + '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';
394

    
395
    //stats tab charts
396
    this.chartScientificResultsUrl = this.properties.statisticsFrameAPIURL + '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=90%&h=90%';
397
    this.chartAccessModeUrl = this.properties.statisticsFrameAPIURL + '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=90%&h=90%';
398
    this.chartDatasourcesUrl = this.properties.statisticsFrameAPIURL + '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=90%&h=90%';
399

    
400
    this.showLoading = false;
401
  }
402

    
403
  public downloadfile(url: string, filename: string) {
404
    this.openLoading();
405
    this.setMessageLoading("Downloading CSV file");
406

    
407
    this._reportsService.downloadCSVFile(url).subscribe(
408
      data => {
409
        this.closeLoading();
410

    
411
        var url = window.URL.createObjectURL(data);
412
        var a = window.document.createElement('a');
413
        window.document.body.appendChild(a);
414
        a.setAttribute('style', 'display: none');
415
        a.href = url;
416
        a.download = filename + ".csv";
417
        a.click();
418
        window.URL.revokeObjectURL(url);
419
        a.remove(); // remove the element
420

    
421
        //window.open(window.URL.createObjectURL(data));
422
        if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
423
          this.downloadFilePiwikSub = this._piwikService.trackDownload(this.properties, url).subscribe();
424
        }
425
      },
426
      error => {
427
        //console.log("Error downloading the file.");
428
        this.handleError("Error downloading file: " + filename, error);
429

    
430
        this.closeLoading();
431
        this.confirmOpenCsvError();
432
      }/*,
433
            () => console.log('Completed file download.')*/
434
    );
435
  }
436

    
437
  /*
438
      showHTML(){
439
        let info:string = "<h1>Publications of Project ";
440

    
441
        if(this.projectInfo.title != undefined && this.projectInfo.title != "") {
442
            info += this.projectInfo.title;
443
        }
444
        if((this.projectInfo.title != undefined && this.projectInfo.title != "") &&
445
           ((this.projectInfo.acronym != undefined && this.projectInfo.acronym != "") ||
446
            (this.projectInfo.callIdentifier != undefined && this.projectInfo.callIdentifier != ""))) {
447
                  info += "(";
448
        }
449
        if(this.projectInfo.acronym != undefined && this.projectInfo.acronym != "") {
450
            info += this.projectInfo.acronym + " - ";
451
        }
452
        if(this.projectInfo.callIdentifier != undefined && this.projectInfo.callIdentifier != "") {
453
            info += this.projectInfo.callIdentifier;
454
        }
455
        if((this.projectInfo.title != undefined && this.projectInfo.title != "") &&
456
           ((this.projectInfo.acronym != undefined && this.projectInfo.acronym != "") ||
457
            (this.projectInfo.callIdentifier != undefined && this.projectInfo.callIdentifier != ""))) {
458
                  info += ")";
459
        }
460
        info +="</h1>";
461
        info += "<h3>"+this.fetchPublications.searchUtils.totalResults+" publications</h3>";
462

    
463
        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+'"))';
464
        this._reportsService.downloadHTMLFile(this.downloadURLAPI+htmlParams, info)
465
            .subscribe(data => this.funct(data),
466
                        error => console.log("Error downloading the file."),
467
                        () => console.log('Completed file download.'));
468
       }
469

    
470
       funct(data) {
471
           var win = window.open(window.URL.createObjectURL(data));
472
       }
473
  */
474
  public metricsResults($event) {
475
    this.totalViews = $event.totalViews;
476
    this.totalDownloads = $event.totalDownloads;
477
    this.pageViews = $event.pageViews;
478
  }
479

    
480
  private updateDescription(description: string) {
481
    this._meta.updateTag({content: description}, "name='description'");
482
    this._meta.updateTag({content: description}, "property='og:description'");
483
  }
484

    
485
  private updateTitle(title: string) {
486
    var _prefix = "";
487
    if(!this.communityId) {
488
      _prefix = "OpenAIRE | ";
489
    }
490
    var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
491
    this._title.setTitle(_title);
492
    this._meta.updateTag({content: _title}, "property='og:title'");
493
  }
494

    
495
  private updateUrl(url: string) {
496
    this._meta.updateTag({content: url}, "property='og:url'");
497
  }
498

    
499
  private openLoading() {
500
    if (this.loading) {
501
      this.loading.open();
502
    }
503
  }
504

    
505
  private closeLoading() {
506
    if (this.loading) {
507
      this.loading.close();
508
    }
509
  }
510

    
511
  private setMessageLoading(message: string) {
512
    if (this.loading) {
513
      this.loading.message = message;
514
    }
515
  }
516

    
517
  public confirmOpenCsvError() {
518
    this.alertCsvError.cancelButton = false;
519
    this.alertCsvError.okButton = true;
520
    this.alertCsvError.alertTitle = "ERROR DOWNLOADING CSV FILE";
521
    this.alertCsvError.message = "There was an error in csv downloading. Please try again later.";
522
    this.alertCsvError.okButtonText = "OK";
523
    this.alertCsvError.open();
524
  }
525

    
526
  private handleError(message: string, error) {
527
    console.error("Project Landing Page: " + message, error);
528
  }
529

    
530
  isRouteAvailable(routeToCheck: string) {
531
    for (let i = 0; i < this.router.config.length; i++) {
532
      let routePath: string = this.router.config[i].path;
533
      if (routePath == routeToCheck) {
534
        return true;
535
      }
536
    }
537
    return false;
538
  }
539
}
(2-2/5)