Project

General

Profile

1 56644 k.triantaf
import {Component, Input, ViewChild} from '@angular/core';
2
import {ActivatedRoute, Router} from '@angular/router';
3
import {Meta, Title} from '@angular/platform-browser';
4 50169 argiro.kok
5 56644 k.triantaf
import {ProjectService} from './project.service';
6
import {ProjectInfo} from '../../utils/entities/projectInfo';
7
import {RouterHelper} from '../../utils/routerHelper.class';
8 50169 argiro.kok
9 57027 konstantin
import {FetchResearchResults} from '../../utils/fetchEntitiesClasses/fetchResearchResults.class';
10
import {SearchResearchResultsService} from '../../services/searchResearchResults.service';
11 50169 argiro.kok
12 56644 k.triantaf
import {ModalLoading} from '../../utils/modal/loading.component';
13 50169 argiro.kok
14 56644 k.triantaf
import {ReportsService} from '../../services/reports.service';
15
import {ErrorCodes} from '../../utils/properties/errorCodes'
16 50169 argiro.kok
17 56644 k.triantaf
import {PiwikService} from '../../utils/piwik/piwik.service';
18
import {EnvProperties} from '../../utils/properties/env-properties';
19
import {SEOService} from '../../sharedComponents/SEO/SEO.service';
20 55418 konstantin
import {HelperFunctions} from "../../utils/HelperFunctions.class";
21 56644 k.triantaf
import {HelperService} from "../../utils/helper/helper.service";
22 57536 konstantin
import {Location} from "@angular/common";
23 58275 k.triantaf
import {HtmlProjectReportService} from "../htmlProjectReport/htmlProjectReport.service";
24 58656 konstantin
import {StringUtils} from "../../utils/string-utils.class";
25 58724 konstantin
import {ResultPreview} from "../../utils/result-preview/result-preview";
26
import {SearchResult} from "../../utils/entities/searchResult";
27
import {IndexInfoService} from "../../utils/indexInfo.service";
28 59816 argiro.kok
import {Subscriber} from "rxjs";
29 59899 argiro.kok
import {properties} from "../../../../environments/environment";
30 51835 sofia.balt
31 50169 argiro.kok
@Component({
32 56644 k.triantaf
  selector: 'project',
33
  templateUrl: 'project.component.html',
34
})
35 51835 sofia.balt
36 56644 k.triantaf
export class ProjectComponent {
37 51746 argiro.kok
  @Input() piwikSiteId = null;
38 56644 k.triantaf
  @Input() communityId = null;
39 50169 argiro.kok
  public projectInfo: ProjectInfo;
40 56644 k.triantaf
  public projectId: string;
41 50169 argiro.kok
  public projectName: string;
42
43
  // Metrics tab variables
44
  public metricsClicked: boolean;
45
  public viewsFrameUrl: string;
46
  public downloadsFrameUrl: string;
47 59962 k.triantaf
  public totalViews: number;
48
  public totalDownloads: number;
49
  public pageViews: number;
50 50169 argiro.kok
51
  // Statistics tab variables
52
  public statsClicked: boolean;
53
  public chartScientificResultsUrl: string;
54
  public chartAccessModeUrl: string;
55
  public chartDatasourcesUrl: string;
56
57 58275 k.triantaf
  // Clipboard variable for HTML dynamic content
58
  public clipboard;
59 50169 argiro.kok
60 56644 k.triantaf
  public project;
61 50169 argiro.kok
62
  // CSV variables
63
  public downloadURLAPI: string;
64
  public csvParams: string;
65
66 58275 k.triantaf
  // HTML (download) variables
67
  public header1: string = "";
68
  public header2: string = "";
69
  public htmlResultDownload: string = "";
70
71 50169 argiro.kok
  // Message variables
72
  public warningMessage = "";
73
  public errorMessage = "";
74
  public showLoading: boolean = true;
75
76
  // Active tab variable for responsiveness
77 58788 konstantin
  public activeTab: string = "";
78 50169 argiro.kok
79 58275 k.triantaf
  @ViewChild('statisticsModal') statisticsModal;
80 58717 konstantin
  @ViewChild('linkProjectModal') linkProjectModal;
81
  @ViewChild('shareResultsModal') shareResultsModal;
82
  @ViewChild('downloadReportModal') downloadReportModal;
83
84 52401 konstantin
  // Request results for publications, research data and software only the one time (first time tab is clicked)
85
  private reloadPublications: boolean = true;
86 50169 argiro.kok
  private reloadDatasets: boolean = true;
87
  private reloadSoftware: boolean = true;
88 52828 konstantin
  private reloadOrps: boolean = true;
89 60614 k.triantaf
  private reloadDmps: boolean = true;
90 50169 argiro.kok
91 58275 k.triantaf
  // Variables for entity selections on the right column
92 58788 konstantin
  public share_research_results_type: string = "results";
93 58275 k.triantaf
  public download_research_results_type: string = "";
94
95 50169 argiro.kok
  // Variables for publications, research data, software tabs
96 57027 konstantin
  public fetchPublications: FetchResearchResults;
97
  public fetchDatasets: FetchResearchResults;
98
  public fetchSoftware: FetchResearchResults;
99
  public fetchOrps: FetchResearchResults;
100 60614 k.triantaf
  public fetchDmps: FetchResearchResults;
101 58733 konstantin
  public searchNumber: number = 5;
102 50169 argiro.kok
103 56644 k.triantaf
  public routerHelper: RouterHelper = new RouterHelper();
104
  public errorCodes: ErrorCodes = new ErrorCodes();
105
  public pageContents = null;
106
  public divContents = null;
107 50169 argiro.kok
108 58275 k.triantaf
  public indexUpdateDate: Date;
109
  public showFeedback: boolean;
110
  public feedbackFields: string [] = [
111
    'Title', 'Funding Information', 'Duration',
112
    'Organizations', 'Other'];
113 57853 konstantin
114 56644 k.triantaf
  @ViewChild(ModalLoading) loading: ModalLoading;
115 50169 argiro.kok
  // Alert box when something is wrong with CSV requests
116
  @ViewChild('AlertModalCsvError') alertCsvError;
117
118 58275 k.triantaf
  // Description variables for view more/less functionality
119
  public thresholdDescription: number = 670;
120
  public showNumDescription: number = 670;
121
122
  // Organizations variables for view more/less functionality
123
  public thresholdOrganizations: number = 20;
124
  public showNumOrganizations: number = 20;
125
126 59816 argiro.kok
  subscriptions = [];
127 56644 k.triantaf
  properties: EnvProperties;
128 58275 k.triantaf
  constructor(private  route: ActivatedRoute,
129
              private _router: Router,
130
              private _location: Location,
131
              private _meta: Meta,
132
              private _title: Title,
133
              private seoService: SEOService,
134 56644 k.triantaf
              private _piwikService: PiwikService,
135 58275 k.triantaf
              private helper: HelperService,
136
              private _projectService: ProjectService,
137 57027 konstantin
              private _searchResearchResultsService: SearchResearchResultsService,
138 56644 k.triantaf
              private _reportsService: ReportsService,
139 58724 konstantin
              private htmlService: HtmlProjectReportService,
140
              private indexInfoService: IndexInfoService) {}
141 50169 argiro.kok
142
  ngOnInit() {
143 59899 argiro.kok
144
        this.properties = properties;
145 58874 konstantin
        if (typeof document !== 'undefined') {
146 59816 argiro.kok
          this.subscriptions.push(this.indexInfoService.getLastIndexDate(this.properties).subscribe(lastIndexUpdate => {
147 58874 konstantin
            if (lastIndexUpdate) {
148
              this.indexUpdateDate = new Date(lastIndexUpdate);
149
            }
150 59816 argiro.kok
          }));
151 58874 konstantin
        }
152 56644 k.triantaf
        //this.getDivContents();
153
        this.getPageContents();
154 59413 argiro.kok
        this.updateUrl(this.properties.domain + this.properties.baseLink + this._router.url);
155 50586 argiro.kok
156 59899 argiro.kok
157 59816 argiro.kok
    this.subscriptions.push(this.route.queryParams.subscribe(params => {
158 56644 k.triantaf
      this.metricsClicked = false;
159
      this.statsClicked = false;
160 57027 konstantin
      this.fetchPublications = new FetchResearchResults(this._searchResearchResultsService);
161
      this.fetchDatasets = new FetchResearchResults(this._searchResearchResultsService);
162
      this.fetchSoftware = new FetchResearchResults(this._searchResearchResultsService);
163
      this.fetchOrps = new FetchResearchResults(this._searchResearchResultsService);
164 60614 k.triantaf
      this.fetchDmps = new FetchResearchResults(this._searchResearchResultsService);
165 56644 k.triantaf
      var title = "Project";
166
      var description = "";
167 50169 argiro.kok
168 58275 k.triantaf
      this.header1 = "";
169
170 56644 k.triantaf
      this.updateTitle(title);
171
      this.updateDescription(description);
172 50169 argiro.kok
      this.projectId = params['projectId'];
173 51318 argiro.kok
      var grantId = params['grantId'];
174
      var funder = params['funder'];
175 50169 argiro.kok
176
177 58940 argiro.kok
      if (this.projectId  && StringUtils.isOpenAIREID(this.projectId)) {
178 56644 k.triantaf
        this.getProjectInfo(this.projectId);
179
        this.actionsAfterLoadId();
180
      } else if (grantId && funder) {
181
        this.getProjectInfoByGrantId(grantId, funder);
182
      } else {
183 50169 argiro.kok
184 56644 k.triantaf
        this.showLoading = false;
185 57536 konstantin
        this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": "project"}});
186 57494 konstantin
        //this.warningMessage = "No valid project id";
187 50169 argiro.kok
      }
188
189 50586 argiro.kok
      this.downloadURLAPI = this.properties.csvAPIURL;
190 50169 argiro.kok
191
      this.createClipboard();
192 55418 konstantin
      HelperFunctions.scroll();
193 59816 argiro.kok
    }));
194 56644 k.triantaf
  }
195 50169 argiro.kok
196 58275 k.triantaf
  public getFileNameType(type: string) {
197
    if(type == "results") {
198
      return "research-outcomes";
199
    } else if(type == "publications") {
200
      return "publications";
201
    } else if(type == "datasets") {
202
      return "research-data";
203
    } else if(type == "software") {
204
      return "software";
205
    } else if(type == "other") {
206
      return "other-research-products";
207
    }
208
    return "results";
209
  }
210
211
  public getCsvParams(type: string) {
212
    // if(type == "results") {
213
    //   type = "publications&type=datasets&type=software&type=other";
214
    // }
215
    return "?format=csv-special&type="+type+"&fq=(relprojectid exact \"" + this.projectId + "\")";
216
  }
217
218 56644 k.triantaf
  private getPageContents() {
219 59007 k.triantaf
    if(this.communityId) {
220 59816 argiro.kok
      this.subscriptions.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
221 59007 k.triantaf
        this.pageContents = contents;
222 59816 argiro.kok
      }));
223 59007 k.triantaf
    }
224 56644 k.triantaf
  }
225 50169 argiro.kok
226 56644 k.triantaf
  private getDivContents() {
227 59007 k.triantaf
    if(this.communityId) {
228 59816 argiro.kok
      this.subscriptions.push(this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
229 59007 k.triantaf
        this.divContents = contents;
230 59816 argiro.kok
      }));
231 59007 k.triantaf
    }
232 56644 k.triantaf
  }
233 51318 argiro.kok
234 58275 k.triantaf
  getDynamicContent(type: string) {
235
    return  "<script type=\"text/javascript\">"
236 56644 k.triantaf
      + "\n<!--"
237
      + "\ndocument.write('<div id=\"oa_widget\"></div>');"
238
      + "\ndocument.write('<script type=\"text/javascript\""
239
      + " src=\"" + this.properties.widgetLink
240 58275 k.triantaf
      + this.projectId + "&type="
241
      + type
242
      + "\"></script>');"
243 56644 k.triantaf
      + "\n-->"
244
      + "\n</script>";
245 58275 k.triantaf
  }
246 51318 argiro.kok
247 58275 k.triantaf
  actionsAfterLoadId() {
248 58874 konstantin
    //this.getProjectInfo(this.projectId);
249 56644 k.triantaf
    //this.searchPublications();
250 58874 konstantin
251
    if (typeof document !== 'undefined') {
252
      this.fetchPublications.getNumForEntity("publication", "project", this.projectId, this.properties);
253
      this.fetchDatasets.getNumForEntity("dataset", "project", this.projectId, this.properties);
254
      this.fetchSoftware.getNumForEntity("software", "project", this.projectId, this.properties);
255
      this.fetchOrps.getNumForEntity("other", "project", this.projectId, this.properties);
256 60614 k.triantaf
      this.searchDmps(1, this.searchNumber);
257 58874 konstantin
    }
258 56644 k.triantaf
  }
259
260 50169 argiro.kok
  ngOnDestroy() {
261 59816 argiro.kok
    this.subscriptions.forEach(subscription => {
262
      if (subscription instanceof Subscriber) {
263
        subscription.unsubscribe();
264
      }
265
    });
266
    this.fetchDatasets.clearSubscriptions();
267
    this.fetchPublications.clearSubscriptions();
268
    this.fetchSoftware.clearSubscriptions();
269 60614 k.triantaf
    this.fetchOrps.clearSubscriptions();
270
    this.fetchDmps.clearSubscriptions();
271 50169 argiro.kok
  }
272
273
  private createClipboard() {
274 56644 k.triantaf
    if (typeof window !== 'undefined') {
275 58275 k.triantaf
      delete this.clipboard;
276 56644 k.triantaf
      let Clipboard;
277
      Clipboard = require('clipboard');
278 58275 k.triantaf
      this.clipboard = new Clipboard('.clipboard_btn');
279 56644 k.triantaf
    }
280 50169 argiro.kok
  }
281
282 58812 konstantin
  public searchPublications(page: number, size: number) {
283
    if (this.reloadPublications &&
284
      (this.fetchPublications.searchUtils.status == this.errorCodes.LOADING ||
285
        (this.fetchPublications.searchUtils.status == this.errorCodes.DONE && this.fetchPublications.searchUtils.totalResults > 0)
286
      )
287
    ) {
288
      this.fetchPublications.getResultsForEntity("publication", "project", this.projectId, page, size, this.properties);
289
    }
290 52401 konstantin
    this.reloadPublications = false;
291 50169 argiro.kok
  }
292 60614 k.triantaf
293
  public searchDmps(page: number, size: number) {
294
    if (this.reloadDmps &&
295
      (this.fetchDmps.searchUtils.status == this.errorCodes.LOADING ||
296
        (this.fetchDmps.searchUtils.status == this.errorCodes.DONE && this.fetchDmps.searchUtils.totalResults > 0)
297
      )
298
    ) {
299
      this.fetchDmps.getDmps("project", this.projectId, page, size, this.properties);
300
    }
301
    this.reloadDmps = false;
302
  }
303 50169 argiro.kok
304 58812 konstantin
  public searchDatasets(page: number, size: number) {
305
    if (this.reloadDatasets &&
306
      (this.fetchDatasets.searchUtils.status == this.errorCodes.LOADING ||
307
        (this.fetchDatasets.searchUtils.status == this.errorCodes.DONE && this.fetchDatasets.searchUtils.totalResults > 0)
308
      )
309
    ) {
310
      this.fetchDatasets.getResultsForEntity("dataset", "project", this.projectId, page, size, this.properties);
311
    }
312 56644 k.triantaf
    this.reloadDatasets = false;
313 50169 argiro.kok
  }
314
315 58812 konstantin
  private searchSoftware(page: number, size: number) {
316
    if (this.reloadSoftware &&
317
      (this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING ||
318
        (this.fetchSoftware.searchUtils.status == this.errorCodes.DONE && this.fetchSoftware.searchUtils.totalResults > 0)
319
      )
320
    ) {
321
      this.fetchSoftware.getResultsForEntity("software", "project", this.projectId, page, size, this.properties);
322
    }
323 56644 k.triantaf
    this.reloadSoftware = false;
324 50169 argiro.kok
  }
325
326 58812 konstantin
  private searchOrps(page: number, size: number) {
327
    if (this.reloadOrps &&
328
      (this.fetchOrps.searchUtils.status == this.errorCodes.LOADING ||
329
        (this.fetchOrps.searchUtils.status == this.errorCodes.DONE && this.fetchOrps.searchUtils.totalResults > 0)
330
      )
331
    ) {
332
      this.fetchOrps.getResultsForEntity("other", "project", this.projectId, page, size, this.properties);
333
    }
334 56644 k.triantaf
    this.reloadOrps = false;
335 52828 konstantin
  }
336
337 56644 k.triantaf
  private getProjectInfo(id: string) {
338
    this.warningMessage = '';
339 58286 konstantin
    this.errorMessage = "";
340 50169 argiro.kok
    this.showLoading = true;
341
342 52606 konstantin
    this.projectInfo = null;
343
344 59816 argiro.kok
    this.subscriptions.push(this._projectService.getProjectInfo(id, this.properties).subscribe(
345 50169 argiro.kok
      data => {
346 56644 k.triantaf
        this.projectInfo = data;
347 50169 argiro.kok
348 56644 k.triantaf
        this.actionsAfterGettingProjectInfo();
349 50169 argiro.kok
      },
350
      err => {
351 56644 k.triantaf
        //console.log(err);
352
        this.handleError("Error getting project for id: " + this.projectId, err);
353 57494 konstantin
        if(err.status == 404) {
354 57536 konstantin
          this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": "project"}});
355 57494 konstantin
        }
356 59411 argiro.kok
        this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink + this.properties.searchLinkToProjects);
357 58286 konstantin
        this.errorMessage = 'No project found';
358 56644 k.triantaf
        this.showLoading = false;
359
      }
360 59816 argiro.kok
    ));
361 56644 k.triantaf
  }
362 50169 argiro.kok
363 56644 k.triantaf
  private getProjectInfoByGrantId(grantId: string, funder: string) {
364
    this.warningMessage = '';
365 58286 konstantin
    this.errorMessage = "";
366 56644 k.triantaf
    this.showLoading = true;
367 52606 konstantin
368 56644 k.triantaf
    this.projectInfo = null;
369 51318 argiro.kok
370 59816 argiro.kok
    this.subscriptions.push(this._projectService.getProjectInfoByGrantId(grantId, funder, this.properties).subscribe(
371 56644 k.triantaf
      data => {
372 51318 argiro.kok
373 56644 k.triantaf
        this.projectInfo = data;
374
375
        this.actionsAfterGettingProjectInfo();
376
        this.projectId = this.projectInfo.id;
377
        this.actionsAfterLoadId();
378
      },
379
      err => {
380
        //console.log(err);
381
        this.handleError("Error getting project for grant id: " + grantId + " and funder: " + funder, err);
382 58286 konstantin
        if(err.status == 404) {
383
          this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": "project"}});
384
        }
385 59411 argiro.kok
        this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink + this.properties.searchLinkToProjects);
386 56644 k.triantaf
        this.errorMessage = 'No project found';
387
        this.showLoading = false;
388
      }
389 59816 argiro.kok
    ));
390 51318 argiro.kok
  }
391
392 56644 k.triantaf
  actionsAfterGettingProjectInfo() {
393
    this.projectName = this.projectInfo.acronym;
394
    if (this.projectName == undefined || this.projectName == '') {
395
      this.projectName = this.projectInfo.title;
396
    }
397 59411 argiro.kok
    this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink + this._router.url);
398 56644 k.triantaf
    this.updateTitle(this.projectName);
399 59375 argiro.kok
    this.updateDescription(this.projectInfo.description?this.projectInfo.description: ("project" + (this.projectInfo.title?"," + this.projectInfo.title:"") + (this.projectInfo.funding && this.projectInfo.funding.funderName?", funder: " + this.projectInfo.funding.funderName:"") + (this.projectInfo.acronym?"," + this.projectInfo.acronym:"")));
400 56644 k.triantaf
    if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
401 59816 argiro.kok
      this.subscriptions.push(this._piwikService.trackView(this.properties, this.projectName, this.piwikSiteId).subscribe());
402 56644 k.triantaf
    }
403 51318 argiro.kok
404 56644 k.triantaf
    this.project = {
405
      funderId: "",
406 58275 k.triantaf
      funderName: ((this.projectInfo.funding) ? this.projectInfo.funding.funderShortName: ''),
407 56644 k.triantaf
      projectId: this.projectId,
408
      projectName: this.projectInfo.title,
409
      projectAcronym: this.projectInfo.acronym,
410
      startDate: this.projectInfo.startDate,
411
      endDate: this.projectInfo.endDate
412
    };
413 51318 argiro.kok
414 59063 argiro.kok
    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":200,"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';
415 51318 argiro.kok
416 59063 argiro.kok
    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":200,"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';
417 51318 argiro.kok
418 56644 k.triantaf
    //stats tab charts
419 58656 konstantin
    if (this.properties.useNewStatistisTool) {
420
      this.chartScientificResultsUrl = this.properties.statisticsFrameNewAPIURL +
421 58669 argiro.kok
        'chart?json='+StringUtils.URIEncode('{"library":"HighCharts","chartDescription":{"queries":[{"name":"Research outcomes","type":"column","query":{"name":"projScient","parameters":["'+this.projectId+'"]}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"Produced research outcomes per year"},"subtitle":{},"yAxis":{"title":{"text":"Research outcomes"}},"xAxis":{"title":{"text":"Year"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}');
422 58656 konstantin
      this.chartAccessModeUrl =  this.properties.statisticsFrameNewAPIURL +
423
        'chart?json='+StringUtils.URIEncode(
424 58678 argiro.kok
        '{"library":"HighCharts","chartDescription":{"queries":[{"name":"Research outcomes","type":"pie","query":{"name":"projOA","parameters":["'+this.projectId+'"]}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"Access mode of research outcomes"},"subtitle":{},"yAxis":{"title":{"text":"Research outcomes"}},"xAxis":{"title":{"text":"Access mode"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}');
425 58656 konstantin
      this.chartDatasourcesUrl =  this.properties.statisticsFrameNewAPIURL +
426
        'chart?json='+StringUtils.URIEncode(
427 58799 konstantin
        '{"library":"HighCharts","chartDescription":{"queries":[{"name":"Research outcomes","type":"bar","query":{"name":"projPubsRepos","parameters":["'+this.projectId+'"]}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"Research outcomes per datasource"},"subtitle":{},"yAxis":{"title":{"text":"Research outcomes"}},"xAxis":{"title":{"text":"Datasource"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"plotOptions":{"series":{"dataLabels":{"enabled":true}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}');
428 58656 konstantin
    } else {
429
      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 Outcomes"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [" "], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=90%&h=90%';
430
      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 Outcomes"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [" "], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=90%&h=90%';
431
      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 Outcomes"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [" "], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=90%&h=90%';
432
    }
433 50169 argiro.kok
434 56644 k.triantaf
    this.showLoading = false;
435
  }
436 53731 konstantin
437 58275 k.triantaf
  public downloadCsvFile(url: string, filename: string) {
438 56644 k.triantaf
    this.openLoading();
439
    this.setMessageLoading("Downloading CSV file");
440 53731 konstantin
441 59816 argiro.kok
    this.subscriptions.push(this._reportsService.downloadCSVFile(url).subscribe(
442 56644 k.triantaf
      data => {
443
        this.closeLoading();
444 54825 konstantin
445 58275 k.triantaf
        let url = window.URL.createObjectURL(data);
446
        this.download(url, filename+".csv");
447 56644 k.triantaf
448
        if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
449 60406 argiro.kok
          this.subscriptions.push(this._piwikService.trackDownload(this.properties, "DownloadCSV"+filename, this.piwikSiteId).subscribe());
450 56644 k.triantaf
        }
451
      },
452
      error => {
453
        //console.log("Error downloading the file.");
454
        this.handleError("Error downloading file: " + filename, error);
455
456
        this.closeLoading();
457 58275 k.triantaf
        this.confirmOpenFileDownloadError("CSV");
458 56644 k.triantaf
      }/*,
459 54778 konstantin
            () => console.log('Completed file download.')*/
460 59816 argiro.kok
    ));
461 56644 k.triantaf
  }
462 50169 argiro.kok
463 56644 k.triantaf
  public metricsResults($event) {
464
    this.totalViews = $event.totalViews;
465
    this.totalDownloads = $event.totalDownloads;
466
    this.pageViews = $event.pageViews;
467
  }
468 58598 k.triantaf
469
  public get hasMetrics(): boolean {
470 60826 argiro.kok
    return !(this.totalViews && this.totalDownloads && this.pageViews) || this.totalViews > 0 || this.totalDownloads > 0||this.pageViews > 0;
471 58598 k.triantaf
  }
472 50169 argiro.kok
473 58275 k.triantaf
  public openStatistics() {
474
    this.statsClicked = true;
475
    this.statisticsModal.cancelButton = false;
476
    this.statisticsModal.okButton = false;
477
    this.statisticsModal.alertTitle = "Statistics of";
478
    this.statisticsModal.open();
479
  }
480
481 58717 konstantin
  public openLinkProjectModal() {
482
    this.linkProjectModal.cancelButton = false;
483
    this.linkProjectModal.okButton = false;
484
    this.linkProjectModal.alertTitle = "Link this project to";
485 58733 konstantin
    //this.linkProjectModal.alertHeader = false;
486 58717 konstantin
    this.linkProjectModal.open();
487
  }
488
489
  public openShareResultsModal() {
490
    this.shareResultsModal.cancelButton = false;
491
    this.shareResultsModal.okButton = false;
492
    this.shareResultsModal.alertTitle = "Share results";
493
    this.shareResultsModal.open();
494
  }
495
496
  public openDownloadReportModal() {
497 58788 konstantin
    if(this.fetchPublications.searchUtils.totalResults > 0 || this.fetchDatasets.searchUtils.totalResults > 0 ||
498
       this.fetchSoftware.searchUtils.totalResults > 0 || this.fetchOrps.searchUtils.totalResults > 0) {
499
      this.download_research_results_type = "results";
500
    }
501 58717 konstantin
    this.downloadReportModal.cancelButton = false;
502
    this.downloadReportModal.okButton = false;
503
    this.downloadReportModal.alertTitle = "Download report";
504
    this.downloadReportModal.open();
505
  }
506
507 58275 k.triantaf
  private createHeaders(type: string) {
508
    this.openLoading();
509
    this.setMessageLoading("Downloading HTML file");
510
511
    if(!this.header1) {
512
      this.createHeader1();
513
    }
514
515
    if (type == "publications") {
516
      this.header2 = this.fetchPublications.searchUtils.totalResults.toLocaleString('en-US') + " publications";
517
    } else if (type == "datasets") {
518
      this.header2 = this.fetchDatasets.searchUtils.totalResults.toLocaleString('en-US') + " research data";
519
    } else if (type == "software") {
520
      this.header2 = this.fetchSoftware.searchUtils.totalResults.toLocaleString('en-US') + " software";
521
    } else if (type == "other") {
522
      this.header2 = this.fetchOrps.searchUtils.totalResults.toLocaleString('en-US') + " other research products";
523
    } else if (type == "results") {
524
      let totalResults: number = (+this.fetchPublications.searchUtils.totalResults) +
525
        (+this.fetchDatasets.searchUtils.totalResults) +
526
        (+this.fetchSoftware.searchUtils.totalResults) +
527
        (+this.fetchOrps.searchUtils.totalResults);
528
529
      this.header2 = totalResults.toLocaleString('en-US') + " research outcomes";
530
    }
531
  }
532
533
  private createHtmlFile(type: string, filename: string) {
534
    let intro: string = '<!doctype html>';
535
    intro += '<html lang="en-gb" dir="ltr" vocab="http://schema.org/">';
536
    intro += '<head>';
537
    intro += '<title>' + this.header1 + '</title>';
538
    intro += '</head>';
539
540
    if (typeof window !== 'undefined') {
541 59816 argiro.kok
      this.subscriptions.push(this.htmlService.getHTML(this.projectId, type, this.properties.csvAPIURL).subscribe(
542 58275 k.triantaf
        data => {
543
          //console.info(data);
544
          this.htmlResultDownload = intro + '<body><div>' + this.header1 + '</div><div><h4>' + this.header2 + '</h4></div>';
545
          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>";
546
          this.htmlResultDownload += '</body></html>';
547
548
          //console.info(this.htmlResultDownload);
549
          this.closeLoading();
550
551
          let url = window.URL.createObjectURL(new Blob([this.htmlResultDownload], { type: 'text/html' }));
552
          this.download(url, filename+".html");
553
554
          if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
555 60406 argiro.kok
            this.subscriptions.push(this._piwikService.trackDownload(this.properties, "DownloadHTML"+filename,  this.piwikSiteId).subscribe());
556 58275 k.triantaf
          }
557
        },
558
        err => {
559
          this.handleError("Error getting html for id: " + this.projectId, err);
560
          //this.errorMessage = 'Service not available';
561
          this.closeLoading();
562
          this.confirmOpenFileDownloadError("HTML");
563
        }
564 59816 argiro.kok
      ));
565 58275 k.triantaf
    } else {
566
      this.closeLoading();
567
      this.confirmOpenFileDownloadError("HTML");
568
    }
569
  }
570
571
  downloadHtmlFile(type: string, filename: string) {
572
    this.createHeaders(type);
573
    this.createHtmlFile(type, filename);
574
  }
575
576
  createHeader1() {
577
    // if (title != undefined && title != "") {
578
    //   this.header1 += title;
579
    // }
580
    // if ((title != undefined && title != "") &&
581
    //   ((acronym != undefined && acronym != "") ||
582
    //     (code != undefined && code != ""))) {
583
    //   this.header1 += "(";
584
    // }
585
    // if (acronym != undefined && acronym != "") {
586
    //   this.header1 += acronym + " - ";
587
    // }
588
    // if (code != undefined && code != "") {
589
    //   this.header1 += code;
590
    // }
591
    // if ((title != undefined && title != "") &&
592
    //   ((acronym != undefined && acronym != "") ||
593
    //     (code != undefined && code != ""))) {
594
    //   this.header1 += ")";
595
    // }
596
597
    this.header1 = "<div style=\"font-size:12px;\"><span>Project</span>";
598
599
    if(this.projectInfo.startDate || this.projectInfo.endDate) {
600
      this.header1 += "<span> . "
601
    }
602
    if(this.projectInfo.startDate && !this.projectInfo.endDate) {
603
      this.header1 += "from ";
604
    }
605
    if(!this.projectInfo.startDate && this.projectInfo.endDate) {
606
      this.header1 += "until ";
607
    }
608
    if(this.projectInfo.startDate) {
609
      let startYear = (new Date(this.projectInfo.startDate)).getFullYear();
610
      this.header1 += startYear;
611
    }
612
    if(this.projectInfo.startDate && this.projectInfo.endDate) {
613
      this.header1 += " - ";
614
    }
615
    if(this.projectInfo.endDate) {
616
      let endYear = (new Date(this.projectInfo.endDate)).getFullYear();
617
      this.header1 += endYear;
618
    }
619
    if(this.projectInfo.startDate || this.projectInfo.endDate) {
620
      this.header1 += "</span>"
621
    }
622
623
    if(this.projectInfo.status) {
624
      this.header1 += "<span> . "+this.projectInfo.status+"</span>";
625
    }
626
627
    if(this.projectInfo.funding && this.projectInfo.funding.code) {
628
      this.header1 += "<span> . "+this.projectInfo.funding.code+"</span>";
629
    }
630
    this.header1 += "</div>";
631
632
    this.header1 += "<h1 style=\"margin:0;\"><div><a href=\""+window.location.href +"\">";
633
    if(this.projectInfo.acronym) {
634
      this.header1 += this.projectInfo.acronym;
635
    } else {
636
      this.header1 += "[no title available]";
637
    }
638
    this.header1 += "</a></div></h2>";
639
    //<showTitle [titleName]="title" classNames="uk-margin-remove-bottom"></showTitle>
640
    if(this.projectInfo.title) {
641
      this.header1 += "<div><span>"+this.projectInfo.title+"</span></div>";
642
    }
643
  }
644
645
  public download(url, filename) {
646
    //var url = window.URL.createObjectURL(new Blob([this.htmlResultDownload], { type: 'text/html' }));
647
    var a = window.document.createElement('a');
648
    window.document.body.appendChild(a);
649
    a.setAttribute('style', 'display: none');
650
    a.href = url;
651
    a.download = filename;
652
    a.click();
653
    window.URL.revokeObjectURL(url);
654
    a.remove(); // remove the element
655
  }
656
657
658 58717 konstantin
  public onSelectActiveTab(activeTabId) {
659 58735 k.triantaf
    if(this.activeTab != activeTabId) {   // tab really changed
660 58717 konstantin
      if (activeTabId == 'summary') {
661
        this.activeTab = 'summary';
662
      } else if (activeTabId == 'publications') {
663
        this.activeTab = 'publications';
664 58812 konstantin
        this.searchPublications(1, this.searchNumber);
665 58717 konstantin
      } else if (activeTabId == 'datasets') {
666
        this.activeTab = 'datasets';
667 58812 konstantin
        this.searchDatasets(1, this.searchNumber);
668 58717 konstantin
      } else if (activeTabId == 'software') {
669
        this.activeTab = 'software';
670 58812 konstantin
        this.searchSoftware(1, this.searchNumber);
671 58717 konstantin
      } else if (activeTabId == 'other') {
672
        this.activeTab = "other";
673 58812 konstantin
        this.searchOrps(1, this.searchNumber);
674 58717 konstantin
      } else if (activeTabId == 'statistics') {
675
        this.activeTab = 'statistics';
676
        this.statsClicked = true;
677 60614 k.triantaf
      } else if (activeTabId == 'dmps') {
678
        this.activeTab = 'dmps';
679
        this.searchDmps(1, this.searchNumber);
680 58717 konstantin
      }
681
    }
682
  }
683
684 56644 k.triantaf
  private updateDescription(description: string) {
685 57820 argiro.kok
    this._meta.updateTag({content: description.substring(0, 160)}, "name='description'");
686
    this._meta.updateTag({content: description.substring(0, 160)}, "property='og:description'");
687 56644 k.triantaf
  }
688
689
  private updateTitle(title: string) {
690 56840 konstantin
    var _prefix = "";
691 57820 argiro.kok
    // if(!this.communityId) {
692
    //   _prefix = "OpenAIRE | ";
693
    // }
694
    // var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
695
    this._title.setTitle(title);
696
    this._meta.updateTag({content: title}, "property='og:title'");
697 56644 k.triantaf
  }
698
699
  private updateUrl(url: string) {
700
    this._meta.updateTag({content: url}, "property='og:url'");
701
  }
702
703
  private openLoading() {
704
    if (this.loading) {
705
      this.loading.open();
706 50169 argiro.kok
    }
707 56644 k.triantaf
  }
708 50169 argiro.kok
709 56644 k.triantaf
  private closeLoading() {
710
    if (this.loading) {
711
      this.loading.close();
712 50169 argiro.kok
    }
713 56644 k.triantaf
  }
714 50169 argiro.kok
715 56644 k.triantaf
  private setMessageLoading(message: string) {
716
    if (this.loading) {
717
      this.loading.message = message;
718 50169 argiro.kok
    }
719 56644 k.triantaf
  }
720 54825 konstantin
721 58275 k.triantaf
  public confirmOpenFileDownloadError(fileType: string) {
722 56644 k.triantaf
    this.alertCsvError.cancelButton = false;
723
    this.alertCsvError.okButton = true;
724 58275 k.triantaf
    this.alertCsvError.alertTitle = "ERROR DOWNLOADING "+fileType+" FILE";
725 56644 k.triantaf
    this.alertCsvError.message = "There was an error in csv downloading. Please try again later.";
726
    this.alertCsvError.okButtonText = "OK";
727
    this.alertCsvError.open();
728
  }
729
730
  private handleError(message: string, error) {
731
    console.error("Project Landing Page: " + message, error);
732
  }
733
734
  isRouteAvailable(routeToCheck: string) {
735 58275 k.triantaf
    for (let i = 0; i < this._router.config.length; i++) {
736
      let routePath: string = this._router.config[i].path;
737 56644 k.triantaf
      if (routePath == routeToCheck) {
738 56059 argiro.kok
        return true;
739
      }
740
    }
741
    return false;
742
  }
743 58717 konstantin
744
  private getEntityName (entityType:string, plural:boolean, full:boolean): string {
745
    if(entityType == "publication") {
746
      return "publication" + (plural ? "s" : "");
747
    } else if(entityType == "dataset") {
748
      return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
749
    } else if(entityType == "software") {
750
      return "software";
751
    } else if(entityType == "other") {
752
      return (full ? ("other research product" + (plural ? "s" : "")) : "other");
753
    } else if(entityType == "dataprovider") {
754
      return (full ? ("content provider" + (plural ? "s" : "")) : "dataprovider" + (plural ? "s" : ""));
755
    } else {
756
      return entityType + (plural ? "s" : "");
757
    }
758
  }
759 58724 konstantin
760
  public getResultPreview(result: SearchResult, type: string): ResultPreview {
761
    return ResultPreview.searchResultConvert(result, type);
762
  }
763 58737 k.triantaf
764
  public scroll() {
765
    HelperFunctions.scroll();
766
  }
767 58788 konstantin
768 60614 k.triantaf
  public getParamsForSearchLink(type: string = null, subtype: string = null) {
769 58799 konstantin
    if(type) {
770 60614 k.triantaf
      if(subtype) {
771
        return this.routerHelper.createQueryParams(['f0', 'fv0', 'type', 'instancetypename', 'qf', 'sortBy'], ['relprojectid', this.projectId, type, subtype, 'false', 'resultdateofacceptance,descending']);
772
      } else {
773
        return this.routerHelper.createQueryParams(['f0', 'fv0', 'type', 'qf', 'sortBy'], ['relprojectid', this.projectId, type, 'false', 'resultdateofacceptance,descending']);
774
      }
775 58799 konstantin
    } else {
776
      return this.routerHelper.createQueryParams(['f0', 'fv0'], ['relprojectid', this.projectId]);
777
    }
778
  }
779
780 58788 konstantin
  public get hasPrimaryInfo(): boolean {
781
    return !!this.projectInfo && (
782
      !!this.projectInfo.description
783
    );
784
  }
785
786
  public get hasSecondaryInfo(): boolean {
787
    return !!this.projectInfo && (
788
      (!!this.projectInfo.organizations && this.projectInfo.organizations.length > 0)
789
    );
790
  }
791
792 58807 konstantin
  // public get numberOfTabs(): number {
793
  //   if(this.tabsAreInitialized) {
794
  //     return this._numberOfTabs;
795
  //   }
796
  //
797
  //   if(!this.projectInfo
798
  //     || this.fetchPublications.searchUtils.status == this.errorCodes.LOADING
799
  //     || this.fetchDatasets.searchUtils.status == this.errorCodes.LOADING
800
  //     || this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING
801
  //     || this.fetchOrps.searchUtils.status == this.errorCodes.LOADING) {
802
  //     return 0;
803
  //   }
804
  //
805
  //   if (this.hasPrimaryInfo || this.hasSecondaryInfo) {
806
  //     this.firstTab = "summary";
807
  //     this._numberOfTabs++;
808
  //   }
809
  //   if(this.fetchPublications.searchUtils.totalResults > 0 || this.fetchDatasets.searchUtils.totalResults > 0
810
  //     || this.fetchSoftware.searchUtils.totalResults > 0 || this.fetchOrps.searchUtils.totalResults > 0) {
811
  //     if(this.fetchPublications.searchUtils.totalResults > 0) {
812
  //       if(this._numberOfTabs == 0) {
813
  //         this.firstTab = 'publications';
814
  //         this.searchPublicationsInit();
815
  //       }
816
  //       this._numberOfTabs++;
817
  //     }
818
  //     if(this.fetchDatasets.searchUtils.totalResults > 0) {
819
  //       if(this._numberOfTabs == 0) {
820
  //         this.firstTab = 'datasets';
821
  //         this.searchDatasetsInit();
822
  //       }
823
  //       this._numberOfTabs++;
824
  //     }
825
  //     if(this.fetchSoftware.searchUtils.totalResults > 0) {
826
  //       if(this._numberOfTabs == 0) {
827
  //         this.firstTab = 'software';
828
  //         this.searchSoftwareInit();
829
  //       }
830
  //       this._numberOfTabs++;
831
  //     }
832
  //     if(this.fetchOrps.searchUtils.totalResults > 0) {
833
  //       if(this._numberOfTabs == 0) {
834
  //         this.firstTab = 'other';
835
  //         this.searchOrpsInit();
836
  //       }
837
  //       this._numberOfTabs++;
838
  //     }
839
  //     this._numberOfTabs++;
840
  //   }
841
  //   this.activeTab = this.firstTab;
842
  //   this.tabsAreInitialized = true;
843
  //   return this._numberOfTabs;
844
  // }
845 50169 argiro.kok
}