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
import {Location} from "@angular/common";
23
import {HtmlProjectReportService} from "../htmlProjectReport/htmlProjectReport.service";
24

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

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

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

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

    
51
  // Clipboard variable for HTML dynamic content
52
  public clipboard;
53

    
54
  public project;
55

    
56
  // CSV variables
57
  public downloadURLAPI: string;
58
  public csvParams: string;
59

    
60
  // HTML (download) variables
61
  public header1: string = "";
62
  public header2: string = "";
63
  public htmlResultDownload: string = "";
64

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

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

    
73
  @ViewChild('statisticsModal') statisticsModal;
74

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

    
81
  // Variables for entity selections on the right column
82
  public share_research_results_type: string = "";
83
  public download_research_results_type: string = "";
84

    
85
  // Variables for publications, research data, software tabs
86
  public fetchPublications: FetchResearchResults;
87
  public linkToSearchPublications = "";
88
  public fetchDatasets: FetchResearchResults;
89
  public linkToSearchDatasets = "";
90
  public fetchSoftware: FetchResearchResults;
91
  public linkToSearchSoftware = "";
92
  public fetchOrps: FetchResearchResults;
93
  public linkToSearchOrps = "";
94

    
95
  public routerHelper: RouterHelper = new RouterHelper();
96
  public errorCodes: ErrorCodes = new ErrorCodes();
97
  public pageContents = null;
98
  public divContents = null;
99

    
100
  public indexUpdateDate: Date;
101
  public showFeedback: boolean;
102

    
103
  @ViewChild(ModalLoading) loading: ModalLoading;
104
  // Alert box when something is wrong with CSV requests
105
  @ViewChild('AlertModalCsvError') alertCsvError;
106

    
107
  // Description variables for view more/less functionality
108
  public thresholdDescription: number = 670;
109
  public showNumDescription: number = 670;
110

    
111
  // Organizations variables for view more/less functionality
112
  public thresholdOrganizations: number = 20;
113
  public showNumOrganizations: number = 20;
114

    
115
  sub: any;
116
  piwiksub: any;
117
  infoSub: any;
118
  downloadFilePiwikSub: any;
119
  downloadHtmlFilePiwikSub: any;
120
  properties: EnvProperties;
121

    
122
  public subHTML: any;
123

    
124
  constructor(private  route: ActivatedRoute,
125
              private _router: Router,
126
              private _location: Location,
127
              private _meta: Meta,
128
              private _title: Title,
129
              private seoService: SEOService,
130
              private _piwikService: PiwikService,
131
              private helper: HelperService,
132
              private _projectService: ProjectService,
133
              private _searchResearchResultsService: SearchResearchResultsService,
134
              private _reportsService: ReportsService,
135
              private htmlService: HtmlProjectReportService) {}
136

    
137
  ngOnInit() {
138
    this.route.data
139
      .subscribe((data: { envSpecific: EnvProperties }) => {
140
        this.properties = data.envSpecific;
141
        if(this.properties.lastIndexUpdate) {
142
          this.indexUpdateDate = new Date(this.properties.lastIndexUpdate);
143
        }
144
        //this.getDivContents();
145
        this.getPageContents();
146
        this.updateUrl(data.envSpecific.baseLink + this._router.url);
147

    
148
      });
149
    this.sub = this.route.queryParams.subscribe(params => {
150
      this.metricsClicked = false;
151
      this.statsClicked = false;
152
      this.fetchPublications = new FetchResearchResults(this._searchResearchResultsService);
153
      this.fetchDatasets = new FetchResearchResults(this._searchResearchResultsService);
154
      this.fetchSoftware = new FetchResearchResults(this._searchResearchResultsService);
155
      this.fetchOrps = new FetchResearchResults(this._searchResearchResultsService);
156

    
157
      var title = "Project";
158
      var description = "";
159

    
160
      this.header1 = "";
161

    
162
      this.updateTitle(title);
163
      this.updateDescription(description);
164
      this.projectId = params['projectId'];
165
      var grantId = params['grantId'];
166
      var funder = params['funder'];
167

    
168

    
169
      if (this.projectId) {
170
        this.getProjectInfo(this.projectId);
171
        this.actionsAfterLoadId();
172
      } else if (grantId && funder) {
173
        this.getProjectInfoByGrantId(grantId, funder);
174
      } else {
175

    
176
        this.showLoading = false;
177
        this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": "project"}});
178
        //this.warningMessage = "No valid project id";
179
      }
180

    
181
      this.downloadURLAPI = this.properties.csvAPIURL;
182

    
183
      this.createClipboard();
184
      HelperFunctions.scroll();
185
    });
186
  }
187

    
188
  public getFileNameType(type: string) {
189
    if(type == "results") {
190
      return "research-outcomes";
191
    } else if(type == "publications") {
192
      return "publications";
193
    } else if(type == "datasets") {
194
      return "research-data";
195
    } else if(type == "software") {
196
      return "software";
197
    } else if(type == "other") {
198
      return "other-research-products";
199
    }
200
    return "results";
201
  }
202

    
203
  public getCsvParams(type: string) {
204
    // if(type == "results") {
205
    //   type = "publications&type=datasets&type=software&type=other";
206
    // }
207
    return "?format=csv-special&type="+type+"&fq=(relprojectid exact \"" + this.projectId + "\")";
208
  }
209

    
210
  private getPageContents() {
211
    this.helper.getPageHelpContents(this._router.url, this.properties, this.communityId).subscribe(contents => {
212
      this.pageContents = contents;
213
    })
214
  }
215

    
216
  private getDivContents() {
217
    this.helper.getDivHelpContents(this._router.url, this.properties, this.communityId).subscribe(contents => {
218
      this.divContents = contents;
219
    })
220
  }
221

    
222
  getDynamicContent(type: string) {
223
    return  "<script type=\"text/javascript\">"
224
      + "\n<!--"
225
      + "\ndocument.write('<div id=\"oa_widget\"></div>');"
226
      + "\ndocument.write('<script type=\"text/javascript\""
227
      + " src=\"" + this.properties.widgetLink
228
      + this.projectId + "&type="
229
      + type
230
      + "\"></script>');"
231
      + "\n-->"
232
      + "\n</script>";
233
  }
234

    
235
  actionsAfterLoadId() {
236
    this.getProjectInfo(this.projectId);
237
    //this.searchPublications();
238
    this.fetchPublications.getNumForEntity("publication", "project", this.projectId, this.properties);
239
    this.fetchDatasets.getNumForEntity("dataset", "project", this.projectId, this.properties);
240
    this.fetchSoftware.getNumForEntity("software", "project", this.projectId, this.properties);
241
    this.fetchOrps.getNumForEntity("other", "project", this.projectId, this.properties);
242
  }
243

    
244
  ngOnDestroy() {
245
    if (this.sub) {
246
      this.sub.unsubscribe();
247
    }
248
    if (this.piwiksub) {
249
      this.piwiksub.unsubscribe();
250
    }
251
    if (this.infoSub) {
252
      this.infoSub.unsubscribe();
253
    }
254
    if (this.downloadFilePiwikSub) {
255
      this.downloadFilePiwikSub.unsubscribe();
256
    }
257
    if(this.downloadHtmlFilePiwikSub) {
258
      this.downloadHtmlFilePiwikSub.unsubscribe();
259
    }
260
  }
261

    
262
  private createClipboard() {
263
    if (typeof window !== 'undefined') {
264
      delete this.clipboard;
265
      let Clipboard;
266
      Clipboard = require('clipboard');
267
      this.clipboard = new Clipboard('.clipboard_btn');
268
    }
269
  }
270

    
271
  private searchPublications() {
272
    this.fetchPublications.getResultsForEntity("publication", "project", this.projectId, 1, 10, this.properties);
273
    this.linkToSearchPublications = this.properties.searchLinkToAdvancedPublications;// + "?project=" + this.projectId+"&pr=and";
274
    this.reloadPublications = false;
275
  }
276

    
277
  private searchDatasets() {
278
    this.fetchDatasets.getResultsForEntity("dataset", "project", this.projectId, 1, 10, this.properties);
279
    this.linkToSearchDatasets = this.properties.searchLinkToAdvancedDatasets;// + "?project=" + this.projectId+"&pr=and";
280

    
281
    this.reloadDatasets = false;
282
    //this.activeTab = "Research Data";
283
  }
284

    
285
  private searchSoftware() {
286
    this.fetchSoftware.getResultsForEntity("software", "project", this.projectId, 1, 10, this.properties);
287
    this.linkToSearchSoftware = this.properties.searchLinkToAdvancedSoftware;
288
    this.reloadSoftware = false;
289
  }
290

    
291
  private searchOrps() {
292
    this.fetchOrps.getResultsForEntity("other", "project", this.projectId, 1, 10, this.properties);
293
    this.linkToSearchOrps = this.properties.searchLinkToAdvancedOrps;
294
    this.reloadOrps = false;
295
  }
296

    
297
  public searchPublicationsInit() {
298
    if (this.reloadPublications && this.fetchPublications.searchUtils.totalResults > 0) {
299
      this.searchPublications();
300
    } else if (this.fetchPublications.searchUtils.totalResults == 0) {
301
      //this.statsClicked=true;
302
      //this.activeTab = "Statistics";
303
    }
304
  }
305

    
306
  public searchDatasetsInit() {
307
    if (this.reloadDatasets && this.fetchDatasets.searchUtils.totalResults > 0) {
308
      this.searchDatasets();
309
    } else if (this.fetchDatasets.searchUtils.totalResults == 0) {
310
      //this.statsClicked=true;
311
      //this.activeTab = "Statistics";
312
    }
313
  }
314

    
315
  public searchSoftwareInit() {
316
    if (this.reloadSoftware && this.fetchSoftware.searchUtils.totalResults > 0) {
317
      this.searchSoftware();
318
    }
319
  }
320

    
321
  public searchOrpsInit() {
322
    if (this.reloadOrps && this.fetchOrps.searchUtils.totalResults > 0) {
323
      this.searchOrps();
324
    }
325
  }
326

    
327
  private getProjectInfo(id: string) {
328
    this.warningMessage = '';
329
    this.errorMessage = ""
330
    this.showLoading = true;
331

    
332
    this.projectInfo = null;
333

    
334
    this.infoSub = this._projectService.getProjectInfo(id, this.properties).subscribe(
335
      data => {
336
        this.projectInfo = data;
337

    
338
        this.actionsAfterGettingProjectInfo();
339
      },
340
      err => {
341
        //console.log(err);
342
        this.handleError("Error getting project for id: " + this.projectId, err);
343
        if(err.status == 404) {
344
          this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": "project"}});
345
        }
346
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToProjects);
347
        //this.errorMessage = 'No project found';
348
        this.showLoading = false;
349
      }
350
    );
351
  }
352

    
353
  private getProjectInfoByGrantId(grantId: string, funder: string) {
354
    this.warningMessage = '';
355
    this.errorMessage = ""
356
    this.showLoading = true;
357

    
358
    this.projectInfo = null;
359

    
360
    this._projectService.getProjectInfoByGrantId(grantId, funder, this.properties).subscribe(
361
      data => {
362

    
363
        this.projectInfo = data;
364

    
365
        this.actionsAfterGettingProjectInfo();
366
        this.projectId = this.projectInfo.id;
367
        this.actionsAfterLoadId();
368
      },
369
      err => {
370
        //console.log(err);
371
        this.handleError("Error getting project for grant id: " + grantId + " and funder: " + funder, err);
372
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToProjects);
373
        this.errorMessage = 'No project found';
374
        this.showLoading = false;
375
      }
376
    );
377
  }
378

    
379
  actionsAfterGettingProjectInfo() {
380
    this.projectName = this.projectInfo.acronym;
381
    if (this.projectName == undefined || this.projectName == '') {
382
      this.projectName = this.projectInfo.title;
383
    }
384
    this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this._router.url);
385
    this.updateTitle(this.projectName);
386
    this.updateDescription("project, " + this.projectName + "," + this.projectInfo.funding.funderShortName + "," + this.projectInfo.acronym);
387
    if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
388
      this.piwiksub = this._piwikService.trackView(this.properties, this.projectName, this.piwikSiteId).subscribe();
389
    }
390

    
391
    this.project = {
392
      funderId: "",
393
      funderName: ((this.projectInfo.funding) ? this.projectInfo.funding.funderShortName: ''),
394
      projectId: this.projectId,
395
      projectName: this.projectInfo.title,
396
      projectAcronym: this.projectInfo.acronym,
397
      startDate: this.projectInfo.startDate,
398
      endDate: this.projectInfo.endDate
399
    };
400

    
401
    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":80,"sort":"xaxis","xStyle":{"r":-30,"s":"6","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';
402

    
403
    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":80,"sort":"xaxis","xStyle":{"r":-30,"s":"6","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';
404

    
405
    //stats tab charts
406
    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%';
407
    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%';
408
    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%';
409

    
410
    this.showLoading = false;
411
  }
412

    
413
  public downloadCsvFile(url: string, filename: string) {
414
    this.openLoading();
415
    this.setMessageLoading("Downloading CSV file");
416

    
417
    this._reportsService.downloadCSVFile(url).subscribe(
418
      data => {
419
        this.closeLoading();
420

    
421
        let url = window.URL.createObjectURL(data);
422
        this.download(url, filename+".csv");
423

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

    
432
        this.closeLoading();
433
        this.confirmOpenFileDownloadError("CSV");
434
      }/*,
435
            () => console.log('Completed file download.')*/
436
    );
437
  }
438

    
439
  public metricsResults($event) {
440
    this.totalViews = $event.totalViews;
441
    this.totalDownloads = $event.totalDownloads;
442
    this.pageViews = $event.pageViews;
443
  }
444

    
445
  public openStatistics() {
446
    this.statsClicked = true;
447
    this.statisticsModal.cancelButton = false;
448
    this.statisticsModal.okButton = false;
449
    this.statisticsModal.alertTitle = "Statistics of";
450
    this.statisticsModal.open();
451
  }
452

    
453
  private createHeaders(type: string) {
454
    this.openLoading();
455
    this.setMessageLoading("Downloading HTML file");
456

    
457
    if(!this.header1) {
458
      this.createHeader1();
459
    }
460

    
461
    if (type == "publications") {
462
      this.header2 = this.fetchPublications.searchUtils.totalResults.toLocaleString('en-US') + " publications";
463
    } else if (type == "datasets") {
464
      this.header2 = this.fetchDatasets.searchUtils.totalResults.toLocaleString('en-US') + " research data";
465
    } else if (type == "software") {
466
      this.header2 = this.fetchSoftware.searchUtils.totalResults.toLocaleString('en-US') + " software";
467
    } else if (type == "other") {
468
      this.header2 = this.fetchOrps.searchUtils.totalResults.toLocaleString('en-US') + " other research products";
469
    } else if (type == "results") {
470
      let totalResults: number = (+this.fetchPublications.searchUtils.totalResults) +
471
        (+this.fetchDatasets.searchUtils.totalResults) +
472
        (+this.fetchSoftware.searchUtils.totalResults) +
473
        (+this.fetchOrps.searchUtils.totalResults);
474

    
475
      this.header2 = totalResults.toLocaleString('en-US') + " research outcomes";
476
    }
477
  }
478

    
479
  private createHtmlFile(type: string, filename: string) {
480
    let intro: string = '<!doctype html>';
481
    intro += '<html lang="en-gb" dir="ltr" vocab="http://schema.org/">';
482
    intro += '<head>';
483
    intro += '<title>' + this.header1 + '</title>';
484
    intro += '</head>';
485

    
486
    if (typeof window !== 'undefined') {
487
      this.subHTML = this.htmlService.getHTML(this.projectId, type, this.properties.csvAPIURL).subscribe(
488
        data => {
489
          //console.info(data);
490
          this.htmlResultDownload = intro + '<body><div>' + this.header1 + '</div><div><h4>' + this.header2 + '</h4></div>';
491
          this.htmlResultDownload += "<table><thead><tr> <th>Type</th><th>Title</th><th>Authors</th><th>Publication Year</th><th>DOI</th><th>Permanent Identifier</th><th>Publication type</th><th>Journal</th><th>Project Name (GA Number)</th><th>Access Mode</th></tr></thead><tbody>" + data + "</tbody></table>";
492
          this.htmlResultDownload += '</body></html>';
493

    
494
          //console.info(this.htmlResultDownload);
495
          this.closeLoading();
496

    
497
          let url = window.URL.createObjectURL(new Blob([this.htmlResultDownload], { type: 'text/html' }));
498
          this.download(url, filename+".html");
499

    
500
          if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
501
            this.downloadHtmlFilePiwikSub = this._piwikService.trackDownload(this.properties, url).subscribe();
502
          }
503
        },
504
        err => {
505
          this.handleError("Error getting html for id: " + this.projectId, err);
506
          //this.errorMessage = 'Service not available';
507
          this.closeLoading();
508
          this.confirmOpenFileDownloadError("HTML");
509
        }
510
      );
511
    } else {
512
      this.closeLoading();
513
      this.confirmOpenFileDownloadError("HTML");
514
    }
515
  }
516

    
517
  downloadHtmlFile(type: string, filename: string) {
518
    this.createHeaders(type);
519
    this.createHtmlFile(type, filename);
520
  }
521

    
522
  createHeader1() {
523
    // if (title != undefined && title != "") {
524
    //   this.header1 += title;
525
    // }
526
    // if ((title != undefined && title != "") &&
527
    //   ((acronym != undefined && acronym != "") ||
528
    //     (code != undefined && code != ""))) {
529
    //   this.header1 += "(";
530
    // }
531
    // if (acronym != undefined && acronym != "") {
532
    //   this.header1 += acronym + " - ";
533
    // }
534
    // if (code != undefined && code != "") {
535
    //   this.header1 += code;
536
    // }
537
    // if ((title != undefined && title != "") &&
538
    //   ((acronym != undefined && acronym != "") ||
539
    //     (code != undefined && code != ""))) {
540
    //   this.header1 += ")";
541
    // }
542

    
543
    this.header1 = "<div style=\"font-size:12px;\"><span>Project</span>";
544

    
545
    if(this.projectInfo.startDate || this.projectInfo.endDate) {
546
      this.header1 += "<span> . "
547
    }
548
    if(this.projectInfo.startDate && !this.projectInfo.endDate) {
549
      this.header1 += "from ";
550
    }
551
    if(!this.projectInfo.startDate && this.projectInfo.endDate) {
552
      this.header1 += "until ";
553
    }
554
    if(this.projectInfo.startDate) {
555
      let startYear = (new Date(this.projectInfo.startDate)).getFullYear();
556
      this.header1 += startYear;
557
    }
558
    if(this.projectInfo.startDate && this.projectInfo.endDate) {
559
      this.header1 += " - ";
560
    }
561
    if(this.projectInfo.endDate) {
562
      let endYear = (new Date(this.projectInfo.endDate)).getFullYear();
563
      this.header1 += endYear;
564
    }
565
    if(this.projectInfo.startDate || this.projectInfo.endDate) {
566
      this.header1 += "</span>"
567
    }
568

    
569
    if(this.projectInfo.status) {
570
      this.header1 += "<span> . "+this.projectInfo.status+"</span>";
571
    }
572

    
573
    if(this.projectInfo.funding && this.projectInfo.funding.code) {
574
      this.header1 += "<span> . "+this.projectInfo.funding.code+"</span>";
575
    }
576
    this.header1 += "</div>";
577

    
578
    this.header1 += "<h1 style=\"margin:0;\"><div><a href=\""+window.location.href +"\">";
579
    if(this.projectInfo.acronym) {
580
      this.header1 += this.projectInfo.acronym;
581
    } else {
582
      this.header1 += "[no title available]";
583
    }
584
    this.header1 += "</a></div></h2>";
585
    //<showTitle [titleName]="title" classNames="uk-margin-remove-bottom"></showTitle>
586
    if(this.projectInfo.title) {
587
      this.header1 += "<div><span>"+this.projectInfo.title+"</span></div>";
588
    }
589
  }
590

    
591
  public download(url, filename) {
592
    //var url = window.URL.createObjectURL(new Blob([this.htmlResultDownload], { type: 'text/html' }));
593
    var a = window.document.createElement('a');
594
    window.document.body.appendChild(a);
595
    a.setAttribute('style', 'display: none');
596
    a.href = url;
597
    a.download = filename;
598
    a.click();
599
    window.URL.revokeObjectURL(url);
600
    a.remove(); // remove the element
601
  }
602

    
603
  // copyToClipboard(element: HTMLElement) {
604
  //   if (typeof document !== 'undefined') {
605
  //     if (window.getSelection) {
606
  //       const selection = window.getSelection();
607
  //       const range = document.createRange();
608
  //       range.selectNodeContents(element);
609
  //       selection.removeAllRanges();
610
  //       selection.addRange(range);
611
  //       document.execCommand('copy');
612
  //     } else {
613
  //       console.warn("Could not select text in node: Unsupported browser.");
614
  //     }
615
  //   }
616
  // }
617

    
618
  private updateDescription(description: string) {
619
    this._meta.updateTag({content: description.substring(0, 160)}, "name='description'");
620
    this._meta.updateTag({content: description.substring(0, 160)}, "property='og:description'");
621
  }
622

    
623
  private updateTitle(title: string) {
624
    var _prefix = "";
625
    // if(!this.communityId) {
626
    //   _prefix = "OpenAIRE | ";
627
    // }
628
    // var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
629
    this._title.setTitle(title);
630
    this._meta.updateTag({content: title}, "property='og:title'");
631
  }
632

    
633
  private updateUrl(url: string) {
634
    this._meta.updateTag({content: url}, "property='og:url'");
635
  }
636

    
637
  private openLoading() {
638
    if (this.loading) {
639
      this.loading.open();
640
    }
641
  }
642

    
643
  private closeLoading() {
644
    if (this.loading) {
645
      this.loading.close();
646
    }
647
  }
648

    
649
  private setMessageLoading(message: string) {
650
    if (this.loading) {
651
      this.loading.message = message;
652
    }
653
  }
654

    
655
  public confirmOpenFileDownloadError(fileType: string) {
656
    this.alertCsvError.cancelButton = false;
657
    this.alertCsvError.okButton = true;
658
    this.alertCsvError.alertTitle = "ERROR DOWNLOADING "+fileType+" FILE";
659
    this.alertCsvError.message = "There was an error in csv downloading. Please try again later.";
660
    this.alertCsvError.okButtonText = "OK";
661
    this.alertCsvError.open();
662
  }
663

    
664
  private handleError(message: string, error) {
665
    console.error("Project Landing Page: " + message, error);
666
  }
667

    
668
  isRouteAvailable(routeToCheck: string) {
669
    for (let i = 0; i < this._router.config.length; i++) {
670
      let routePath: string = this._router.config[i].path;
671
      if (routePath == routeToCheck) {
672
        return true;
673
      }
674
    }
675
    return false;
676
  }
677
}
(2-2/5)