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 {Identifier, StringUtils} from "../../utils/string-utils.class";
19
import {properties} from "../../../../environments/environment";
20
import {ISVocabulariesService} from "../../utils/staticAutoComplete/ISVocabularies.service";
21
import {Subscriber} from "rxjs";
22
import {Session} from "../../login/utils/helper.class";
23
import {AnnotationComponent} from "../annotation/annotation.component";
24
import {ParsingFunctions} from "../landing-utils/parsingFunctions.class";
25

    
26

    
27
@Component({
28
  selector: 'result-landing',
29
  templateUrl: 'resultLanding.component.html',
30
})
31
export class ResultLandingComponent {
32
  @Input() type: string = "publication";
33
  @Input() piwikSiteId = properties.piwikSiteId;
34
  @Input() communityId = null;
35
  enermapsId;
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
  @Input() public resultFromInput: boolean = false;
43
  @Input() 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 canonicalUrl: string = null;
55
  public linkToSearchPage: string = null;
56
  
57
  public thresholdDescription: number = 670;
58
  public showNumDescription: number = 670;
59
  
60
  public citeThisClicked: boolean;
61
  
62
  // Metrics tab variables
63
  public metricsClicked: boolean;
64
  public hasAltMetrics: boolean = false;
65
  public viewsFrameUrl: string;
66
  public downloadsFrameUrl: string;
67
  public totalViews: number;
68
  public totalDownloads: number;
69
  public pageViews: number;
70
  
71
  // Custom tab paging variables
72
  public referencesPage: number = 1;
73
  public bioentitiesPage: number = 1;
74
  public relatedPage: number = 1;
75
  public similarPage: number = 1;
76
  public supplementaryPage: number = 1;
77
  public supplementedByPage: number = 1;
78
  public organizationsPage: number = 1;
79
  public openCitationsPage: number = 1;
80
  public pageSize: number = 10;
81
  
82
  // Map counting variables
83
  public bioentitiesNum: number = 0;
84
  public relatedResultsNum: number = 0;
85

    
86
  // Message variables
87
  public warningMessage = "";
88
  public errorMessage = "";
89
  public showLoading: boolean = true;
90
  public dashboard = properties.isDashboard;
91
  
92
  public routerHelper: RouterHelper = new RouterHelper();
93
  public activeTab: string = null;
94
  private reloadEnermapsDetails: boolean = true;
95
  public enermapsDetails: any;
96

    
97
  private doi: string;
98
  subscriptions = [];
99
  properties: EnvProperties = properties;
100
  public indexUpdateDate: Date;
101
  public pageContents = null;
102
  public divContents = null;
103
  public showFeedback: boolean = false;
104
  public feedbackFields: string [] = [
105
    'Title', 'Authors', 'Access rights',
106
    'Publisher information', 'Funding Information',
107
    'Persistent identifiers', 'Other'];
108

    
109
  public pidsArrayString: string = "";
110
  public identifier: Identifier;
111

    
112
  public isLoggedIn: boolean = Session.isLoggedIn();
113
  public pid: string;
114
  @ViewChild("annotation") annotation: AnnotationComponent;
115

    
116
  constructor(private _resultLandingService: ResultLandingService,
117
              private _vocabulariesService: ISVocabulariesService,
118
              private _piwikService: PiwikService,
119
              private route: ActivatedRoute,
120
              private router: Router,
121
              private _meta: Meta,
122
              private _title: Title,
123
              private _router: Router,
124
              private helper: HelperService,
125
              private seoService: SEOService,
126
              private metricsService: MetricsService,
127
              private cdr: ChangeDetectorRef,
128
              private _location: Location,
129
              private indexInfoService: IndexInfoService) {
130
  }
131
  
132
  ngOnInit() {
133
    if (typeof document !== 'undefined') {
134
      this.subscriptions.push(this.indexInfoService.getLastIndexDate(this.properties).subscribe(lastIndexUpdate => {
135
        if (lastIndexUpdate) {
136
          this.indexUpdateDate = new Date(lastIndexUpdate);
137
        }
138
      }));
139
    }
140
    //this.getDivContents();
141
    this.getPageContents();
142
    this.updateUrl(this.properties.domain +this.properties.baseLink +  this._router.url);
143
    this.subscriptions.push(this.route.queryParams.subscribe(data => {
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(decodeURIComponent(data["pid"]),false);
161

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

    
169
      this.metricsClicked = false;
170
      if(this.resultFromInput){
171
        this.id = this.resultLandingInfo.objIdentifier;
172
        this.type="publication";
173
      }
174
      if ((this.id && StringUtils.isOpenAIREID(this.id)) || (this.identifier)) {
175
        this.getProvenanceVocabularyAndResultLandingInfo();
176
      } else {
177
        this.showLoading = false;
178

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

    
187

    
188
      this.scroll();
189
    }));
190
  }
191

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

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

    
242
  ngOnDestroy() {
243
    this.subscriptions.forEach(subscription => {
244
      if (subscription instanceof Subscriber) {
245
        subscription.unsubscribe();
246
      }
247
    });
248
    this._vocabulariesService.clearSubscriptions();
249
  }
250
  
251
  public pidInit(event) {
252
    this.pid = event;
253
    this.cdr.detectChanges();
254
  }
255
  
256
  
257
  public getTypeName(): string {
258
    if (this.type === "dataset") {
259
      return "research data";
260
    } else if (this.type === "orp" || this.type === "other") {
261
      return "research product";
262
    } else {
263
      return this.type;
264
    }
265
  }
266
  
267
  public removeUnknown(array: string[], type: boolean = false): string[] {
268
    if (type) {
269
      return this.removeDuplicates(array).filter(value => value.toLowerCase() !== 'unknown');
270
    } else {
271
      return array.filter(value => value.toLowerCase() !== 'unknown');
272
    }
273
  }
274
  
275
  public removeDuplicates(array: string[]): string[] {
276
    let type = this.getTypeName();
277
    return array.filter(value => value.toLowerCase() !== type);
278
  }
279
  
280
  private getOpenCitations() {
281
    this.subscriptions.push(this._resultLandingService.getOpenCitations(this.id, this.properties).subscribe(
282
      data => {
283
        this.resultLandingInfo.openCitations = data[1];
284
      },
285
      err => {
286
        this.handleError("Error getting open citation for " + this.type + " with id: " + this.id, err);
287
      }
288
    ));
289
  }
290
  
291
  private getProvenanceVocabularyAndResultLandingInfo() {
292
    this.warningMessage = '';
293
    this.errorMessage = '';
294
    this.showLoading = true;
295

    
296
    if (typeof document !== 'undefined') {
297
      this.subscriptions.push(this._vocabulariesService.getProvenanceActionVocabulary(this.properties).subscribe(
298
        provenanceActionVocabulary => {
299
          this.getResultLandingInfo(provenanceActionVocabulary);
300
        }, err => {
301
          this.getResultLandingInfo(null);
302
          this.handleError("Error getting provenance action vocabulary for " + this.type, err);
303
        }
304
      ));
305
    } else {
306
      this.getResultLandingInfo(null);
307
    }
308
    
309
  }
310
  
311
  private setActiveTab() {
312
    if (this.hasPrimaryInfo || this.hasSecondaryInfo) {
313
      this.activeTab = 'summary';
314
    } else if (this.resultLandingInfo.references && this.resultLandingInfo.references.length > 0) {
315
      this.activeTab = 'references';
316
    } else if ((this.resultLandingInfo.supplementaryResearchResults && this.resultLandingInfo.supplementaryResearchResults.length > 0) ||
317
      (this.resultLandingInfo.supplementedByResearchResults && this.resultLandingInfo.supplementedByResearchResults.length > 0)) {
318
      this.activeTab = 'supplementary';
319
    } else if ((this.resultLandingInfo.relatedResearchResults && this.resultLandingInfo.relatedResearchResults.length > 0) ||
320
      (this.resultLandingInfo.similarResearchResults && this.resultLandingInfo.similarResearchResults.length > 0)) {
321
      this.activeTab = 'related';
322
    } else if (this.resultLandingInfo.bioentities && this.bioentitiesNum > 0) {
323
      this.activeTab = 'bioentities';
324
    } else if(this.enermapsId && this.properties.enermapsURL) {
325
      this.activeTab = "enermaps";
326
    }
327
  }
328
  
329
  // private get numberOfTabs(): number {
330
  //   let numberOfTabs = 0;
331
  //   if(this.hasPrimaryInfo || this.hasSecondaryInfo) {
332
  //     numberOfTabs++;
333
  //   }
334
  //   if(this.resultLandingInfo.references && this.resultLandingInfo.references.length > 0) {
335
  //     numberOfTabs++;
336
  //   }
337
  //   if((this.resultLandingInfo.supplementaryResearchResults && this.resultLandingInfo.supplementaryResearchResults.length > 0) ||
338
  //     (this.resultLandingInfo.supplementedByResearchResults && this.resultLandingInfo.supplementedByResearchResults.length > 0)) {
339
  //     numberOfTabs++;
340
  //   }
341
  //   if((this.resultLandingInfo.relatedResearchResults && this.resultLandingInfo.relatedResearchResults.length > 0) ||
342
  //     (this.resultLandingInfo.similarResearchResults && this.resultLandingInfo.similarResearchResults.length > 0)) {
343
  //     numberOfTabs++;
344
  //   }
345
  //   if(this.resultLandingInfo.bioentities && this.bioentitiesNum > 0) {
346
  //     numberOfTabs++;
347
  //   }
348
  //   return numberOfTabs;
349
  // }
350
  
351
  private getResultLandingInfo(provenanceActionVocabulary: any) {
352
    if(this.resultFromInput && this.resultLandingInfo){
353
      this.showLoading = false;
354
      return;
355
    }
356
    this.resultLandingInfo = null;
357
    this.subscriptions.push(this._resultLandingService.getResultLandingInfo(this.id, this.identifier, this.type, provenanceActionVocabulary, this.properties).subscribe(
358
      data => {
359
        this.resultLandingInfo = data;
360
        this.id = this.resultLandingInfo.objIdentifier;
361
        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';
362
        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';
363
        let pid:Identifier = Identifier.getResultPIDFromIdentifiers(this.resultLandingInfo.identifiers);
364
        if (this.type == "result") { // no type was specified - update URL based this.resultLandingInfo.resultType
365
          this.updateUrlWithType(pid);
366
        }
367
        this.canonicalUrl = this.properties.domain+ properties.baseLink  + ( pid ? (this.linkToLandingPage.split("?")[0] + "?pid=" + encodeURIComponent(pid.id)):
368
          (this.linkToLandingPage + this.resultLandingInfo.relcanId));
369
        this.seoService.createLinkForCanonicalURL(this.canonicalUrl);
370
        this.updateUrl(this.canonicalUrl);
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.trackViewForCustomUrl(this.properties, this.resultLandingInfo.title, this.linkToLandingPage.split("?")[1] + this.id ,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
        if(this.communityId && this.communityId == "enermaps" && properties.enermapsURL){
408
          this.enermapsId = ParsingFunctions.getEnermapsConceptId(this.resultLandingInfo.contexts);
409
        }
410
        this.showLoading = false;
411
        this.setActiveTab();
412
      },
413
      err => {
414
        this.handleError("Error getting " + this.type + " for " + (this.id ? ("id: " + this.id) : ("pid: " + this.identifier.id + " ("+this.identifier.class+")")), err);
415
        if (err.status == 404) {
416
          this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": this.type}});
417
        }
418
        
419
        if (this.type == "publication" || this.type == "software") {
420
          this.errorMessage = 'No ' + this.type + ' found';
421
        } else if (this.type == "dataset") {
422
          this.errorMessage += "No research data found";
423
        } else if (this.type == "orp") {
424
          this.errorMessage += "No research product found";
425
        }
426
        this.showLoading = false;
427
        this.seoService.createLinkForCanonicalURL(this.properties.domain+ properties.baseLink  + this.linkToSearchPage);
428
      }
429
    ));
430
  }
431
  
432
  public metricsResults($event) {
433
    this.totalViews = $event.totalViews;
434
    this.totalDownloads = $event.totalDownloads;
435
    this.pageViews = $event.pageViews;
436
  }
437
  
438
  public get hasPrimaryInfo(): boolean {
439
    return !!this.resultLandingInfo && (!!this.resultLandingInfo.description || !!this.resultLandingInfo.identifiers || !!this.resultLandingInfo.subjects);
440
  }
441
  
442
  public get hasSecondaryInfo(): boolean {
443
    return (this.resultLandingInfo.fundedByProjects && this.resultLandingInfo.fundedByProjects.length > 0) ||
444
      (this.resultLandingInfo.contexts && this.resultLandingInfo.contexts.length > 0) ||
445
      (this.resultLandingInfo.hostedBy_collectedFrom && this.resultLandingInfo.hostedBy_collectedFrom.length > 0);
446
  }
447
  
448
  public get hasMetrics(): boolean {
449
    return !(this.totalViews && this.totalDownloads && this.pageViews) || this.totalViews > 0 || this.totalDownloads > 0 || this.pageViews > 0;
450
  }
451
  
452
  private updateDescription(description: string) {
453
    this._meta.updateTag({content: description.substring(0, 160)}, "name='description'");
454
    this._meta.updateTag({content: description.substring(0, 160)}, "property='og:description'");
455
  }
456
  
457
  private updateTitle(title: string) {
458
    var _prefix = "";
459
    // if(!this.communityId) {
460
    //   _prefix = "OpenAIRE | ";
461
    // }
462
    // var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
463
    this._title.setTitle(title);
464
    this._meta.updateTag({content: title}, "property='og:title'");
465
  }
466
  
467
  private updateUrl(url: string) {
468
    this._meta.updateTag({content: url}, "property='og:url'");
469
  }
470
  
471
  public totalPages(totalResults: number): number {
472
    let totalPages: any = totalResults / this.pageSize;
473
    if (!(Number.isInteger(totalPages))) {
474
      totalPages = (parseInt(totalPages, this.pageSize) + 1);
475
    }
476
    return totalPages;
477
  }
478
  
479
  public updateReferencesPage($event) {
480
    this.referencesPage = $event.value;
481
  }
482
  
483
  public updateBioentitiesPage($event) {
484
    this.bioentitiesPage = $event.value;
485
  }
486
  
487
  public updateRelatedPage($event) {
488
    this.relatedPage = $event.value;
489
  }
490
  
491
  public updateSimilarPage($event) {
492
    this.similarPage = $event.value;
493
  }
494
  
495
  public updateSupplementaryPage($event) {
496
    this.supplementaryPage = $event.value;
497
  }
498
  
499
  public updateSupplementedByPage($event) {
500
    this.supplementedByPage = $event.value;
501
  }
502
  
503
  public updateOrganizationsPage($event) {
504
    this.organizationsPage = $event.value;
505
  }
506
  
507
  public updateOpenCitationsPage($event) {
508
    this.openCitationsPage = $event.value;
509
  }
510
  
511
  public accessClass(accessMode: string): string {
512
    if (accessMode.toLowerCase().indexOf('open') !== -1) {
513
      return 'open';
514
    } else if (accessMode.toLowerCase() === 'not available') {
515
      return 'unknown';
516
    } else {
517
      return 'closed';
518
    }
519
  }
520
  
521
  public keysToArray(bioentities: Map<string, string>): string[] {
522
    let keys: string[] = [];
523
    bioentities.forEach(function (value, key, map) {
524
      keys.push(key);
525
    });
526
    return keys;
527
  }
528
  
529
  public getKeys(map) {
530
    return Array.from(map.keys());
531
  }
532
  
533
  public scroll() {
534
    HelperFunctions.scroll();
535
  }
536
  
537
  private handleError(message: string, error) {
538
    if (this.type == "publication") {
539
      console.error("Publication Landing Page: " + message, error);
540
    } else if (this.type == "dataset") {
541
      console.error("Research Data Landing Page: " + message, error);
542
    } else if (this.type == "software") {
543
      console.error("Software Landing Page: " + message, error);
544
    } else if (this.type == "orp") {
545
      console.error("Other Research Product Landing Page: " + message, error);
546
    } else {
547
      console.error("Landing Page: " + message, error);
548
    }
549
  }
550
  
551
  isRouteAvailable(routeToCheck: string) {
552
    for (let i = 0; i < this.router.config.length; i++) {
553
      let routePath: string = this.router.config[i].path;
554
      if (routePath == routeToCheck) {
555
        return true;
556
      }
557
    }
558
    return false;
559
  }
560
  
561
  openDeletedByInference() {
562
    this.deleteByInferenceOpened = true;
563
    this.alertModalDeletedByInference.cancelButton = false;
564
    this.alertModalDeletedByInference.okButton = false;
565
    this.alertModalDeletedByInference.alertTitle = "Other versions of";
566
    this.alertModalDeletedByInference.open();
567
  }
568
  
569
  public getResultPreview(result: RelationResult): ResultPreview {
570
    return ResultPreview.relationResultConvert(result, this.relation);
571
  }
572
  
573
  updateUrlWithType(pid) {
574
    this.type = this.resultLandingInfo.resultType;
575

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

    
654
            || (this.resultLandingInfo.organizations && this.resultLandingInfo.organizations.length > 0)
655
            || this.resultLandingInfo.bioentities || (this.resultLandingInfo.references && this.resultLandingInfo.references.length > 0)
656
            || (this.resultLandingInfo.relatedResearchResults && this.resultLandingInfo.relatedResearchResults.length > 0)
657
            || (this.resultLandingInfo.similarResearchResults && this.resultLandingInfo.similarResearchResults.length > 0)
658
            || (this.resultLandingInfo.supplementaryResearchResults && this.resultLandingInfo.supplementaryResearchResults.length > 0)
659
            || (this.resultLandingInfo.supplementedByResearchResults && this.resultLandingInfo.supplementedByResearchResults.length > 0)
660
          )
661
       );
662
       // console.log("rich content " + allow)
663
       //spam words to exclude
664
        let title_authors_words = ["movie","hd","film","kimetsu", "1080p","4k","call of duty", "mobile hack", "TUBYDI"];
665
        let abstract_words = ["operacao-feliz-natal.blogspot.com", "moviedouban.site", "hack-expert-solution.link"];
666
        allow = allow &&  !(
667
          (this.hasKeyword(this.resultLandingInfo.title,title_authors_words) || (this.resultLandingInfo.authors && this.hasKeyword(this.resultLandingInfo.authors.map(o => o.fullName).join(" "),title_authors_words))
668
            || (this.resultLandingInfo.description && this.hasKeyword(this.resultLandingInfo.description,abstract_words))
669
          ) &&
670
          ((this.resultLandingInfo.publisher && this.resultLandingInfo.publisher.toLowerCase() == "zenodo") ||
671
            this.resultLandingInfo.hostedBy_collectedFrom.filter( value => {return value.downloadName && value.downloadName.toLowerCase().indexOf("zenodo")!=-1}).length > 0));
672
        // console.log("spam content " + allow)
673
        //common titles/ description / authors
674
        let common_titles = ["introduction", "editorial", "book reviews", "preface", "reviews", "none", "book review", "foreword", "conclusion", "review", "reply","einleitung","short notices","erratum","discussion", "letters to the editor","letter to the editor","reviews of books",":{unav)","editorial board"];
675
        let common_abstract = ["international audience","n/a","peer reviewed","national audience","info:eu-repo/semantics/published","-",".","graphical abstract","met lit. opg","international audience; no abstract",'<jats:p>.</jats:p>',"politics","info:eu-repo/semantics/publishedversion","copia digital. madrid : ministerio de educación, cultura y deporte, 2016",'<jats:p />',"peer-reviewed","copia digital. madrid : ministerio de educación, cultura y deporte. subdirección general de coordinación bibliotecaria, 2015","<jats:p>-</jats:p>","imperial users only","yüksek lisans"];
676
        let common_authors = ["[s.n.]","null &na;","nn","(:unap)","(:null)","null anonymous","anonymous"];
677
        allow = allow &&  !(
678
          this.isKeyword(this.resultLandingInfo.title,common_titles) || this.isKeyword(this.resultLandingInfo.description,common_abstract) ||
679
          (this.resultLandingInfo.authors && this.hasKeyword("_"+this.resultLandingInfo.authors.map(o => o.fullName).join("_")+"_",common_authors, "_"))
680
        );
681
        // console.log("common content " + allow)
682
        if(!allow) {
683
          this._meta.updateTag({content: 'noindex'}, "name='robots'");
684
        }
685
      }
686
    } catch (e) {
687
      console.error("Error in passNoIndexFilter()", this.resultLandingInfo.relcanId, e);
688
      return false;
689
    }
690
  }
691
  private hasKeyword(value:string, words:string[], wordSuffix = ""){
692
    return value?words.filter( word => { return value.toLowerCase().indexOf(wordSuffix + word + wordSuffix)!=-1}).length > 0:0;
693
  }
694
  private isKeyword(value:string, words:string[]){
695
    return value?words.filter( word => { return value.toLowerCase() == word}).length > 0:0;
696
  }
697

    
698
  public onSelectActiveTab(activeTabId) {
699
    if (this.activeTab != activeTabId) {   // tab really changed
700
      this.activeTab = activeTabId;
701
      if (activeTabId == 'enermaps' && this.properties.enermapsURL) {
702
        this.getEnermapsDetails(this.enermapsId);
703
      }
704
    }
705
  }
706

    
707
  private getEnermapsDetails(id: string) {
708
    if (this.reloadEnermapsDetails) {
709
      this.subscriptions.push(this._resultLandingService.getEnermapsDetails(id).subscribe(
710
        data => {
711
          this.enermapsDetails = data;
712
          this.reloadEnermapsDetails = false;
713
        },
714
        error => {
715
          console.error("Error in fetching enermaps details ",error);
716
        }
717
      ))
718
    }
719
  }
720
}
(2-2/4)