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
  
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

    
105
  public pidsArrayString: string = "";
106
  public identifier: Identifier;
107

    
108
  public isLoggedIn: boolean = Session.isLoggedIn();
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(data => {
140
      this.resultLandingInfo = null;
141
      if (data['articleId']) {
142
        this.id = data['articleId'];
143
        this.initMetaAndLinks("publication");
144
      } else if (data['datasetId']) {
145
        this.id = data['datasetId'];
146
        this.initMetaAndLinks("dataset");
147
      } else if (data['softwareId']) {
148
        this.id = data['softwareId'];
149
        this.initMetaAndLinks("software");
150
      } else if (data['orpId']) {
151
        this.id = data['orpId'];
152
        this.initMetaAndLinks("orp");
153
      } else if (data["id"]) {
154
        this.id = data["id"];
155
        this.initMetaAndLinks("result");
156
      } else if (data["pid"]) {
157
        this.identifier = Identifier.getIdentifierFromString(decodeURIComponent(data["pid"]));
158

    
159
        if(!this.type) {
160
          this.type = "result";
161
        }
162
        this.initMetaAndLinks(this.type);
163
      }
164
      this.updateDescription("");
165

    
166
      this.metricsClicked = false;
167

    
168
      if ((this.id && StringUtils.isOpenAIREID(this.id)) || (this.identifier)) {
169
        this.getProvenanceVocabularyAndResultLandingInfo();
170
      } else {
171
        this.showLoading = false;
172

    
173
        this._router.navigate(['/error'], {
174
          queryParams: {
175
            "page": this._location.path(true),
176
            "page_type": this.type
177
          }
178
        });
179
      }
180

    
181

    
182
      this.scroll();
183
    }));
184
  }
185

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

    
220
  private getPageContents() {
221
    if (this.communityId) {
222
      this.subscriptions.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
223
        this.pageContents = contents;
224
      }));
225
    }
226
  }
227
  
228
  private getDivContents() {
229
    if (this.communityId) {
230
      this.subscriptions.push(this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
231
        this.divContents = contents;
232
      }));
233
    }
234
  }
235

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

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

    
641
            || (this.resultLandingInfo.organizations && this.resultLandingInfo.organizations.length > 0)
642
            || this.resultLandingInfo.bioentities || (this.resultLandingInfo.references && this.resultLandingInfo.references.length > 0)
643
            || (this.resultLandingInfo.relatedResearchResults && this.resultLandingInfo.relatedResearchResults.length > 0)
644
            || (this.resultLandingInfo.similarResearchResults && this.resultLandingInfo.similarResearchResults.length > 0)
645
            || (this.resultLandingInfo.supplementaryResearchResults && this.resultLandingInfo.supplementaryResearchResults.length > 0)
646
            || (this.resultLandingInfo.supplementedByResearchResults && this.resultLandingInfo.supplementedByResearchResults.length > 0)
647
          )
648
       );
649
       //spam words to exclude
650
        let title_authors_words = ["movie","hd","film","kimetsu", "1080p","4k","call of duty", "mobile hack", "TUBYDI"];
651
        let abstract_words = ["operacao-feliz-natal.blogspot.com", "moviedouban.site", "hack-expert-solution.link"];
652
        allow = allow &&  !(
653
          (this.hasKeyword(this.resultLandingInfo.title,title_authors_words) || (this.resultLandingInfo.authors && this.hasKeyword(this.resultLandingInfo.authors.map(o => o.fullName).join(" "),title_authors_words))
654
            || (this.resultLandingInfo.description && this.hasKeyword(this.resultLandingInfo.description,abstract_words))
655
          ) &&
656
          (this.resultLandingInfo.publisher == "Zenodo" ||
657
            this.resultLandingInfo.hostedBy_collectedFrom.filter( value => {return value.downloadName && value.downloadName.indexOf("zenodo")!=-1}).length > 0));
658
        //common titles/ description / authors
659
        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"];
660
        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"];
661
        let common_authors = ["[s.n.]","null &na;","nn","(:unap)","(:null)","null anonymous","anonymous"];
662
        allow = allow &&  !(
663
          this.isKeyword(this.resultLandingInfo.title,common_titles) || this.isKeyword(this.resultLandingInfo.description,common_abstract) ||
664
          (this.resultLandingInfo.authors && this.hasKeyword(this.resultLandingInfo.authors.map(o => o.fullName).join(" "),common_authors))
665
        );
666
        if(!allow) {
667
          this._meta.updateTag({content: 'noindex'}, "name='robots'");
668
        }
669
      }
670
    } catch (e) {
671
      console.error("Error in passNoIndexFilter()", this.resultLandingInfo.relcanId, e);
672
      return false;
673
    }
674
  }
675
  private hasKeyword(value:string, words:string[]){
676
    return words.filter( word => { return value.toLowerCase().indexOf(word)!=-1}).length > 0;
677
  }
678
  private isKeyword(value:string, words:string[]){
679
    return words.filter( word => { return value.toLowerCase() == word}).length > 0;
680
  }
681
}
(2-2/4)