Project

General

Profile

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

    
5
import {EnvProperties} from '../../utils/properties/env-properties';
6
import {Id, ResultLandingInfo} from '../../utils/entities/resultLandingInfo';
7
import {RouterHelper} from '../../utils/routerHelper.class';
8

    
9
import {PiwikService} from '../../utils/piwik/piwik.service';
10
import {ResultLandingService} from './resultLanding.service';
11
import {SEOService} from '../../sharedComponents/SEO/SEO.service';
12
import {HelperFunctions} from '../../utils/HelperFunctions.class';
13
import {HelperService} from '../../utils/helper/helper.service';
14
import {Location} from "@angular/common";
15
import {MetricsService} from "../../services/metrics.service";
16
import {RelationResult, ResultPreview} from "../../utils/result-preview/result-preview";
17
import {IndexInfoService} from "../../utils/indexInfo.service";
18
import {FormBuilder} from "@angular/forms";
19
import {Identifier, StringUtils} from "../../utils/string-utils.class";
20
import {properties} from "../../../../environments/environment";
21
import {ISVocabulariesService} from "../../utils/staticAutoComplete/ISVocabularies.service";
22
import {Subscriber} from "rxjs";
23
import {Session} from "../../login/utils/helper.class";
24
import {AnnotationComponent} from "../annotation/annotation.component";
25
import {User} from "../../login/utils/helper.class";
26

    
27

    
28
@Component({
29
  selector: 'result-landing',
30
  templateUrl: 'resultLanding.component.html',
31
})
32
export class ResultLandingComponent {
33
  @Input() type: string = "publication";
34
  @Input() piwikSiteId = properties.piwikSiteId;
35
  @Input() communityId = null;
36
  @ViewChild('linkModal') linkModal;
37
  @ViewChild('citeModal') citeModal;
38
  @ViewChild('AlertModalDeletedByInference') alertModalDeletedByInference;
39
  @ViewChild('relationModal') relationModal;
40
  @ViewChild('organizationModal') organizationModal;
41
  public deleteByInferenceOpened: boolean = false;
42
  
43
  public resultLandingInfo: ResultLandingInfo;
44
  public supplementaryResults: RelationResult[];
45
  public relation: string = 'trust';
46
  public id: string;
47
  public title: string;
48
  
49
  /*Show all organizations*/
50
  public showAll: boolean = false;
51
  
52
  // Links for SEO
53
  public linkToLandingPage: string = null;
54
  public linkToSearchPage: string = null;
55
  
56
  public thresholdDescription: number = 670;
57
  public showNumDescription: number = 670;
58
  
59
  public citeThisClicked: boolean;
60
  
61
  // Metrics tab variables
62
  public metricsClicked: boolean;
63
  public hasAltMetrics: boolean = false;
64
  public viewsFrameUrl: string;
65
  public downloadsFrameUrl: string;
66
  public totalViews: number;
67
  public totalDownloads: number;
68
  public pageViews: number;
69
  
70
  // Custom tab paging variables
71
  public referencesPage: number = 1;
72
  public bioentitiesPage: number = 1;
73
  public relatedPage: number = 1;
74
  public similarPage: number = 1;
75
  public supplementaryPage: number = 1;
76
  public supplementedByPage: number = 1;
77
  public organizationsPage: number = 1;
78
  public openCitationsPage: number = 1;
79
  public pageSize: number = 10;
80
  
81
  // Map counting variables
82
  public bioentitiesNum: number = 0;
83
  public relatedResultsNum: number = 0;
84

    
85
  // Message variables
86
  public warningMessage = "";
87
  public errorMessage = "";
88
  public showLoading: boolean = true;
89
  public dashboard = properties.isDashboard;
90
  
91
  public routerHelper: RouterHelper = new RouterHelper();
92
  public activeTab: string = null;
93
  private doi: string;
94
  subscriptions = [];
95
  properties: EnvProperties = properties;
96
  public indexUpdateDate: Date;
97
  public pageContents = null;
98
  public divContents = null;
99
  public showFeedback: boolean = false;
100
  public feedbackFields: string [] = [
101
    'Title', 'Authors', 'Access rights',
102
    'Publisher information', 'Funding Information',
103
    'Persistent identifiers', 'Other'];
104
  public loggedIn: boolean = false;
105
  public pidsArrayString: string = "";
106
  public identifier: Identifier;
107

    
108
  public user: User;
109
  public pid: string;
110
  @ViewChild("annotation") annotation: AnnotationComponent;
111

    
112
  constructor(private _resultLandingService: ResultLandingService,
113
              private _vocabulariesService: ISVocabulariesService,
114
              private _piwikService: PiwikService,
115
              private route: ActivatedRoute,
116
              private router: Router,
117
              private _meta: Meta,
118
              private _title: Title,
119
              private _router: Router,
120
              private helper: HelperService,
121
              private seoService: SEOService,
122
              private metricsService: MetricsService,
123
              private cdr: ChangeDetectorRef,
124
              private _location: Location,
125
              private indexInfoService: IndexInfoService) {
126
  }
127
  
128
  ngOnInit() {
129
    if (typeof document !== 'undefined') {
130
      this.subscriptions.push(this.indexInfoService.getLastIndexDate(this.properties).subscribe(lastIndexUpdate => {
131
        if (lastIndexUpdate) {
132
          this.indexUpdateDate = new Date(lastIndexUpdate);
133
        }
134
      }));
135
    }
136
    //this.getDivContents();
137
    this.getPageContents();
138
    this.updateUrl(this.properties.domain +this.properties.baseLink +  this._router.url);
139
    this.subscriptions.push(this.route.queryParams.subscribe(async data => {
140
      if (Session.isLoggedIn()) {
141
        this.loggedIn = true;
142
      }
143
      this.resultLandingInfo = null;
144
      if (data['articleId']) {
145
        this.id = data['articleId'];
146
        this.initMetaAndLinks("publication");
147
      } else if (data['datasetId']) {
148
        this.id = data['datasetId'];
149
        this.initMetaAndLinks("dataset");
150
      } else if (data['softwareId']) {
151
        this.id = data['softwareId'];
152
        this.initMetaAndLinks("software");
153
      } else if (data['orpId']) {
154
        this.id = data['orpId'];
155
        this.initMetaAndLinks("orp");
156
      } else if (data["id"]) {
157
        this.id = data["id"];
158
        this.initMetaAndLinks("result");
159
      } else if (data["pid"]) {
160
        this.identifier = Identifier.getIdentifierFromString(data["pid"]);
161
        console.debug(this.identifier);
162

    
163
        if(!this.type) {
164
          this.type = "result";
165
        }
166
        this.initMetaAndLinks(this.type);
167
      }
168
      this.updateDescription("");
169

    
170
      this.metricsClicked = false;
171

    
172
      if ((this.id && StringUtils.isOpenAIREID(this.id)) || (this.identifier)) {
173
        this.getProvenanceVocabularyAndResultLandingInfo();
174
      } else {
175
        this.showLoading = false;
176

    
177
        this._router.navigate(['/error'], {
178
          queryParams: {
179
            "page": this._location.path(true),
180
            "page_type": this.type
181
          }
182
        });
183
      }
184

    
185
      if(this.id) {
186
        this.viewsFrameUrl = this.properties.framesAPIURL + 'merge.php?com=query&data=[{"query":"resRepoViews", "resTitle":"' + this.id + '", "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":"Repository","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column"]&stacking=normal&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(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';
187
        this.downloadsFrameUrl = this.properties.framesAPIURL + 'merge.php?com=query&data=[{"query":"resRepoDownloads", "resTitle":"' + this.id + '", "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":"Repository","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column"]&stacking=normal&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(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';
188
      }
189

    
190
      this.scroll();
191
    }));
192
  }
193

    
194
  private initMetaAndLinks(type: string) {
195
    if (type == "publication") {
196
      this.type = "publication";
197
      this.updateTitle("Publication");
198
      this.linkToLandingPage = this.properties.searchLinkToPublication;
199
      this.linkToSearchPage = this.properties.searchLinkToPublications;
200
      this.title = "Publication";
201
    } else if (type == "dataset") {
202
      this.updateTitle("Dataset");
203
      this.type = "dataset";
204
      this.linkToLandingPage = this.properties.searchLinkToDataset;
205
      this.linkToSearchPage = this.properties.searchLinkToDatasets;
206
      this.title = "Research Data";
207
    } else if (type == "software") {
208
      this.updateTitle("Software");
209
      this.type = "software";
210
      this.linkToLandingPage = this.properties.searchLinkToSoftwareLanding;
211
      this.linkToSearchPage = this.properties.searchLinkToSoftware;
212
      this.title = "Software";
213
    } else if (type == "orp") {
214
      this.type = "orp";
215
      this.updateTitle("Other Research Product");
216
      this.linkToLandingPage = this.properties.searchLinkToOrp;
217
      this.linkToSearchPage = this.properties.searchLinkToOrps;
218
      this.title = "Other Research Product";
219
    } else if (type == "result") {
220
      this.type = "result";
221
      this.updateTitle("Research Result");
222
      this.linkToLandingPage = this.properties.searchLinkToResult;
223
      this.linkToSearchPage = this.properties.searchLinkToResults;
224
      this.title = "Research Result";
225
    }
226
  }
227

    
228
  private getPageContents() {
229
    if (this.communityId) {
230
      this.subscriptions.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
231
        this.pageContents = contents;
232
      }));
233
    }
234
  }
235
  
236
  private getDivContents() {
237
    if (this.communityId) {
238
      this.subscriptions.push(this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
239
        this.divContents = contents;
240
      }));
241
    }
242
  }
243

    
244
  ngOnDestroy() {
245
    this.subscriptions.forEach(subscription => {
246
      if (subscription instanceof Subscriber) {
247
        subscription.unsubscribe();
248
      }
249
    });
250
    this._vocabulariesService.clearSubscriptions();
251
  }
252
  
253
  public userInit(event) {
254
    this.user = event;
255
    this.cdr.detectChanges();
256
  }
257
  
258
  public pidInit(event) {
259
    this.pid = event;
260
    this.cdr.detectChanges();
261
  }
262
  
263
  
264
  public getTypeName(): string {
265
    if (this.type === "dataset") {
266
      return "research data";
267
    } else if (this.type === "orp" || this.type === "other") {
268
      return "research product";
269
    } else {
270
      return this.type;
271
    }
272
  }
273
  
274
  public removeUnknown(array: string[], type: boolean = false): string[] {
275
    if (type) {
276
      return this.removeDuplicates(array).filter(value => value.toLowerCase() !== 'unknown');
277
    } else {
278
      return array.filter(value => value.toLowerCase() !== 'unknown');
279
    }
280
  }
281
  
282
  public removeDuplicates(array: string[]): string[] {
283
    let type = this.getTypeName();
284
    return array.filter(value => value.toLowerCase() !== type);
285
  }
286
  
287
  private getOpenCitations() {
288
    this.subscriptions.push(this._resultLandingService.getOpenCitations(this.id, this.properties).subscribe(
289
      data => {
290
        this.resultLandingInfo.openCitations = data[1];
291
      },
292
      err => {
293
        this.handleError("Error getting open citation for " + this.type + " with id: " + this.id, err);
294
      }
295
    ));
296
  }
297
  
298
  private getProvenanceVocabularyAndResultLandingInfo() {
299
    this.warningMessage = '';
300
    this.errorMessage = '';
301
    this.showLoading = true;
302
    
303
    this.resultLandingInfo = null;
304
    
305
    if (typeof document !== 'undefined') {
306
      this.subscriptions.push(this._vocabulariesService.getProvenanceActionVocabulary(this.properties).subscribe(
307
        provenanceActionVocabulary => {
308
          this.getResultLandingInfo(provenanceActionVocabulary);
309
        }, err => {
310
          this.getResultLandingInfo(null);
311
          this.handleError("Error getting provenance action vocabulary for " + this.type, err);
312
        }
313
      ));
314
    } else {
315
      this.getResultLandingInfo(null);
316
    }
317
    
318
  }
319
  
320
  private setActiveTab() {
321
    if (this.hasPrimaryInfo || this.hasSecondaryInfo) {
322
      this.activeTab = 'summary';
323
    } else if (this.resultLandingInfo.references && this.resultLandingInfo.references.length > 0) {
324
      this.activeTab = 'references';
325
    } else if ((this.resultLandingInfo.supplementaryResearchResults && this.resultLandingInfo.supplementaryResearchResults.length > 0) ||
326
      (this.resultLandingInfo.supplementedByResearchResults && this.resultLandingInfo.supplementedByResearchResults.length > 0)) {
327
      this.activeTab = 'supplementary';
328
    } else if ((this.resultLandingInfo.relatedResearchResults && this.resultLandingInfo.relatedResearchResults.length > 0) ||
329
      (this.resultLandingInfo.similarResearchResults && this.resultLandingInfo.similarResearchResults.length > 0)) {
330
      this.activeTab = 'related';
331
    } else if (this.resultLandingInfo.bioentities && this.bioentitiesNum > 0) {
332
      this.activeTab = 'bioentities';
333
    }
334
  }
335
  
336
  // private get numberOfTabs(): number {
337
  //   let numberOfTabs = 0;
338
  //   if(this.hasPrimaryInfo || this.hasSecondaryInfo) {
339
  //     numberOfTabs++;
340
  //   }
341
  //   if(this.resultLandingInfo.references && this.resultLandingInfo.references.length > 0) {
342
  //     numberOfTabs++;
343
  //   }
344
  //   if((this.resultLandingInfo.supplementaryResearchResults && this.resultLandingInfo.supplementaryResearchResults.length > 0) ||
345
  //     (this.resultLandingInfo.supplementedByResearchResults && this.resultLandingInfo.supplementedByResearchResults.length > 0)) {
346
  //     numberOfTabs++;
347
  //   }
348
  //   if((this.resultLandingInfo.relatedResearchResults && this.resultLandingInfo.relatedResearchResults.length > 0) ||
349
  //     (this.resultLandingInfo.similarResearchResults && this.resultLandingInfo.similarResearchResults.length > 0)) {
350
  //     numberOfTabs++;
351
  //   }
352
  //   if(this.resultLandingInfo.bioentities && this.bioentitiesNum > 0) {
353
  //     numberOfTabs++;
354
  //   }
355
  //   return numberOfTabs;
356
  // }
357
  
358
  private getResultLandingInfo(provenanceActionVocabulary: any) {
359
    this.subscriptions.push(this._resultLandingService.getResultLandingInfo(this.id, this.identifier, this.type, provenanceActionVocabulary, this.properties).subscribe(
360
      data => {
361
        this.resultLandingInfo = data;
362
        if(!this.id) {
363
          this.id = this.resultLandingInfo.relcanId;
364
          this.viewsFrameUrl = this.properties.framesAPIURL + 'merge.php?com=query&data=[{"query":"resRepoViews", "resTitle":"' + this.id + '", "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":"Repository","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column"]&stacking=normal&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(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';
365
          this.downloadsFrameUrl = this.properties.framesAPIURL + 'merge.php?com=query&data=[{"query":"resRepoDownloads", "resTitle":"' + this.id + '", "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":"Repository","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column"]&stacking=normal&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(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';
366
        }
367
        if (this.type == "result") { // no type was specified - update URL based this.resultLandingInfo.resultType
368
          this.updateUrlWithType();
369
        }
370
        this.seoService.createLinkForCanonicalURL(this.properties.domain+ properties.baseLink  + this.linkToLandingPage + this.resultLandingInfo.relcanId);
371
        if ((this.type == "publication") && (this.properties.environment == "beta" || this.properties.environment == "development") && (typeof document !== 'undefined')) {
372
          this.getOpenCitations();
373
        }
374
        this.addNoIndexFilter();
375
        if (this.resultLandingInfo.title) {
376
          this.updateTitle(this.resultLandingInfo.title);
377
          this.updateDescription((this.resultLandingInfo.description ? (this.resultLandingInfo.description) : ("," + this.resultLandingInfo.title)));
378
        }
379
        if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
380
          this.subscriptions.push(this._piwikService.trackView(this.properties, this.resultLandingInfo.title/*.name*/, this.piwikSiteId).subscribe());
381
        }
382
        
383
        let bioentitiesNum = 0;
384
        if (this.resultLandingInfo.bioentities != undefined) {
385
          this.resultLandingInfo.bioentities.forEach(function (value, key, map) {
386
            bioentitiesNum += value.size;
387
          });
388
        }
389
        this.bioentitiesNum = bioentitiesNum;
390
        if (typeof document !== 'undefined') {
391
          if(this.resultLandingInfo.identifiers) {
392
            let pidsArray: string[] = [];
393
            for(let key of Array.from(this.resultLandingInfo.identifiers.keys())) {
394
              pidsArray = pidsArray.concat(this.resultLandingInfo.identifiers.get(key));
395
              this.pidsArrayString = pidsArray.join();
396
            }
397
            if (this.resultLandingInfo.identifiers.has('doi')) {
398
              this.doi = this.resultLandingInfo.identifiers.get('doi')[0];
399
              this.subscriptions.push(this.metricsService.hasAltMetrics(this.properties.altMetricsAPIURL, this.doi).subscribe(hasAltMetrics => {
400
                this.hasAltMetrics = hasAltMetrics;
401
              }, error => {
402
                this.hasAltMetrics = false;
403
              }));
404
            }
405
          }
406
        }
407
        this.showLoading = false;
408
        this.setActiveTab();
409
      },
410
      err => {
411
        this.handleError("Error getting " + this.type + " for " + (this.id ? ("id: " + this.id) : ("pid: " + this.identifier.id + " ("+this.identifier.class+")")), err);
412
        if (err.status == 404) {
413
          this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": this.type}});
414
        }
415
        
416
        if (this.type == "publication" || this.type == "software") {
417
          this.errorMessage = 'No ' + this.type + ' found';
418
        } else if (this.type == "dataset") {
419
          this.errorMessage += "No research data found";
420
        } else if (this.type == "orp") {
421
          this.errorMessage += "No research product found";
422
        }
423
        this.showLoading = false;
424
        this.seoService.createLinkForCanonicalURL(this.properties.domain+ properties.baseLink  + this.linkToSearchPage);
425
      }
426
    ));
427
  }
428
  
429
  public metricsResults($event) {
430
    this.totalViews = $event.totalViews;
431
    this.totalDownloads = $event.totalDownloads;
432
    this.pageViews = $event.pageViews;
433
  }
434
  
435
  public get hasPrimaryInfo(): boolean {
436
    return !!this.resultLandingInfo && (!!this.resultLandingInfo.description || !!this.resultLandingInfo.identifiers || !!this.resultLandingInfo.subjects);
437
  }
438
  
439
  public get hasSecondaryInfo(): boolean {
440
    return (this.resultLandingInfo.fundedByProjects && this.resultLandingInfo.fundedByProjects.length > 0) ||
441
      (this.resultLandingInfo.contexts && this.resultLandingInfo.contexts.length > 0) ||
442
      (this.resultLandingInfo.hostedBy_collectedFrom && this.resultLandingInfo.hostedBy_collectedFrom.length > 0);
443
  }
444
  
445
  public get hasMetrics(): boolean {
446
    return !(this.totalViews && this.totalDownloads && this.pageViews) || this.totalViews > 0 || this.totalDownloads > 0 || this.pageViews > 0;
447
  }
448
  
449
  private updateDescription(description: string) {
450
    this._meta.updateTag({content: description.substring(0, 160)}, "name='description'");
451
    this._meta.updateTag({content: description.substring(0, 160)}, "property='og:description'");
452
  }
453
  
454
  private updateTitle(title: string) {
455
    var _prefix = "";
456
    // if(!this.communityId) {
457
    //   _prefix = "OpenAIRE | ";
458
    // }
459
    // var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
460
    this._title.setTitle(title);
461
    this._meta.updateTag({content: title}, "property='og:title'");
462
  }
463
  
464
  private updateUrl(url: string) {
465
    this._meta.updateTag({content: url}, "property='og:url'");
466
  }
467
  
468
  public totalPages(totalResults: number): number {
469
    let totalPages: any = totalResults / this.pageSize;
470
    if (!(Number.isInteger(totalPages))) {
471
      totalPages = (parseInt(totalPages, this.pageSize) + 1);
472
    }
473
    return totalPages;
474
  }
475
  
476
  public updateReferencesPage($event) {
477
    this.referencesPage = $event.value;
478
  }
479
  
480
  public updateBioentitiesPage($event) {
481
    this.bioentitiesPage = $event.value;
482
  }
483
  
484
  public updateRelatedPage($event) {
485
    this.relatedPage = $event.value;
486
  }
487
  
488
  public updateSimilarPage($event) {
489
    this.similarPage = $event.value;
490
  }
491
  
492
  public updateSupplementaryPage($event) {
493
    this.supplementaryPage = $event.value;
494
  }
495
  
496
  public updateSupplementedByPage($event) {
497
    this.supplementedByPage = $event.value;
498
  }
499
  
500
  public updateOrganizationsPage($event) {
501
    this.organizationsPage = $event.value;
502
  }
503
  
504
  public updateOpenCitationsPage($event) {
505
    this.openCitationsPage = $event.value;
506
  }
507
  
508
  public accessClass(accessMode: string): string {
509
    if (accessMode.toLowerCase().indexOf('open') !== -1) {
510
      return 'open';
511
    } else if (accessMode.toLowerCase() === 'not available') {
512
      return 'unknown';
513
    } else {
514
      return 'closed';
515
    }
516
  }
517
  
518
  public keysToArray(bioentities: Map<string, string>): string[] {
519
    let keys: string[] = [];
520
    bioentities.forEach(function (value, key, map) {
521
      keys.push(key);
522
    });
523
    return keys;
524
  }
525
  
526
  public getKeys(map) {
527
    return Array.from(map.keys());
528
  }
529
  
530
  public scroll() {
531
    HelperFunctions.scroll();
532
  }
533
  
534
  private handleError(message: string, error) {
535
    if (this.type == "publication") {
536
      console.error("Publication Landing Page: " + message, error);
537
    } else if (this.type == "dataset") {
538
      console.error("Research Data Landing Page: " + message, error);
539
    } else if (this.type == "software") {
540
      console.error("Software Landing Page: " + message, error);
541
    } else if (this.type == "orp") {
542
      console.error("Other Research Product Landing Page: " + message, error);
543
    } else {
544
      console.error("Landing Page: " + message, error);
545
    }
546
  }
547
  
548
  isRouteAvailable(routeToCheck: string) {
549
    for (let i = 0; i < this.router.config.length; i++) {
550
      let routePath: string = this.router.config[i].path;
551
      if (routePath == routeToCheck) {
552
        return true;
553
      }
554
    }
555
    return false;
556
  }
557
  
558
  openDeletedByInference() {
559
    this.deleteByInferenceOpened = true;
560
    this.alertModalDeletedByInference.cancelButton = false;
561
    this.alertModalDeletedByInference.okButton = false;
562
    this.alertModalDeletedByInference.alertTitle = "Other versions of";
563
    this.alertModalDeletedByInference.open();
564
  }
565
  
566
  public getResultPreview(result: RelationResult): ResultPreview {
567
    return ResultPreview.relationResultConvert(result, this.relation);
568
  }
569
  
570
  updateUrlWithType() {
571
    this.type = this.resultLandingInfo.resultType;
572

    
573
    if (this.type == "publication") {
574
      this.linkToLandingPage = this.properties.searchLinkToPublication;
575
      this.linkToSearchPage = this.properties.searchLinkToPublications;
576
    } else if (this.type == "dataset") {
577
      this.linkToLandingPage = this.properties.searchLinkToDataset;
578
      this.linkToSearchPage = this.properties.searchLinkToDatasets;
579
    } else if (this.type == "software") {
580
      this.linkToLandingPage = this.properties.searchLinkToSoftwareLanding;
581
      this.linkToSearchPage = this.properties.searchLinkToSoftware;
582
    } else if (this.type == "other") {
583
      this.type = "orp";
584
      this.linkToLandingPage = this.properties.searchLinkToOrp;
585
      this.linkToSearchPage = this.properties.searchLinkToOrps;
586
    }
587
    if(!this.identifier) {
588
      this._location.go(this.linkToLandingPage + this.id);
589
    }
590
    // else {
591
    //   this._location.go(this.linkToLandingPage.split("?")[0] + "?pid=" + this.identifier.id);
592
    // }
593
  }
594
  
595
  public getReferenceUrl(id: Id): string {
596
    if (id.type === "doi") {
597
      return this.properties.doiURL + id.value;
598
    } else if (id.type === "pmc") {
599
      return this.properties.pmcURL + id.value;
600
    } else if (id.type === "pmid") {
601
      return this.properties.pmidURL + id.value;
602
    } else if (id.type === "handle") {
603
      return this.properties.handleURL + id.value;
604
    } else {
605
      return null;
606
    }
607
  }
608
  
609
  public getReferenceIdName(id: Id): string {
610
    if (id.type === "doi") {
611
      return 'DOI'
612
    } else if (id.type === "pmc") {
613
      return 'Europe PMC'
614
    } else if (id.type === "pmid") {
615
      return 'PubMed';
616
    } else if (id.type === "handle") {
617
      return 'Handle.NET';
618
    } else {
619
      return null;
620
    }
621
  }
622
  
623
  public openLinkModal() {
624
    this.linkModal.cancelButton = false;
625
    this.linkModal.okButton = false;
626
    this.linkModal.alertTitle = "Link this " + this.getTypeName() + " to";
627
    this.linkModal.open();
628
  }
629
  
630
  public openCiteModal() {
631
    this.citeThisClicked = true;
632
    this.citeModal.cancelButton = false;
633
    this.citeModal.okButton = false;
634
    this.citeModal.alertTitle = "Cite this " + this.getTypeName();
635
    this.citeModal.open();
636
  }
637
  addNoIndexFilter() {
638
    try {
639
      if(!(this.properties.environment == "production" || this.properties.environment == "development") ) {
640
        return ;
641
      }else {
642
       let allow =  !!(!this.resultLandingInfo.underCurationMessage &&
643
          ((this.resultLandingInfo.fundedByProjects && this.resultLandingInfo.fundedByProjects.length > 0)
644
            || this.resultLandingInfo.journal
645
            || (this.resultLandingInfo.classifiedSubjects && this.resultLandingInfo.classifiedSubjects.size > 0)
646
            || (this.resultLandingInfo.organizations && this.resultLandingInfo.organizations.length > 0)
647
            || this.resultLandingInfo.bioentities || (this.resultLandingInfo.references && this.resultLandingInfo.references.length > 0)
648
            || (this.resultLandingInfo.relatedResearchResults && this.resultLandingInfo.relatedResearchResults.length > 0)
649
            || (this.resultLandingInfo.similarResearchResults && this.resultLandingInfo.similarResearchResults.length > 0)
650
            || (this.resultLandingInfo.supplementaryResearchResults && this.resultLandingInfo.supplementaryResearchResults.length > 0)
651
            || (this.resultLandingInfo.supplementedByResearchResults && this.resultLandingInfo.supplementedByResearchResults.length > 0)
652
          ));
653
        if(!allow) {
654
          this._meta.updateTag({content: 'noindex'}, "name='robots'");
655
        }
656
      }
657
    } catch (e) {
658
      console.error("Error in passNoIndexFilter()", this.resultLandingInfo.relcanId, e);
659
      return false;
660
    }
661
  }
662
}
(2-2/4)