Project

General

Profile

1
import {Component, Input, ViewChild} from '@angular/core';
2
import {ActivatedRoute, Router} from '@angular/router';
3
import {Meta, Title} from '@angular/platform-browser';
4
import {EnvProperties} from '../../utils/properties/env-properties';
5
import {ClaimEntity, ShowOptions} from '../claim-utils/claimHelper.class';
6
import {EntitiesSearchService} from '../../utils/entitiesAutoComplete/entitySearch.service';
7
import {SEOService} from '../../sharedComponents/SEO/SEO.service';
8
import {AlertModal} from "../../utils/modal/alert";
9
import {HelperFunctions} from "../../utils/HelperFunctions.class";
10
import {HelperService} from "../../utils/helper/helper.service";
11
import {PiwikService} from "../../utils/piwik/piwik.service";
12
import {Subscriber} from "rxjs";
13
import {properties} from "../../../../environments/environment";
14

    
15
declare var UIkit:any;
16

    
17
@Component({
18
    selector: 'linking-generic',
19
    templateUrl: 'linkingGeneric.component.html'
20

    
21
})
22
export class LinkingGenericComponent {
23
  @Input() piwikSiteId = null;
24
  @Input() pageTitle: string = " Create links between research objects";
25
  piwiksub:any;
26

    
27
  @Input() communityId:string= null;
28
  sourceType:string;
29
  targetType:string;
30
  step:number = 1;
31
  @Input() results:ClaimEntity[] = [];
32
  @Input() inlineEntity:ClaimEntity = null;
33
  basketLimit =100;
34

    
35
  @Input() showOptions:ShowOptions = new ShowOptions();
36
  //show values: source, result, project, context, claim
37
  // linkTo /values: result, project, context
38
  // show linkToEntities /values: result, project, context
39

    
40
  @Input() sources:ClaimEntity[] =[];
41
  properties:EnvProperties;
42
  @Input() localStoragePrefix:string = "linking_";
43
  url=null;
44
  @ViewChild(AlertModal) alert;
45
  public pageContents = null;
46

    
47

    
48
  constructor (private _router: Router,  private route: ActivatedRoute, private entitySearch:EntitiesSearchService,
49
               private _meta: Meta, private _title: Title,  private _piwikService:PiwikService,
50
               private seoService: SEOService, private helper: HelperService ) {
51
  }
52
  subscriptions = [];
53

    
54
  ngOnInit() {
55
    this.showOptions.show = 'source';
56
    if(this.inlineEntity){
57
      this.showOptions.basketShowSources  = false;
58
      this.showOptions.basketShowLinksTo = true;
59
      this.showOptions.show = this.showOptions.linkTo;
60
    }
61

    
62
       this.properties = properties;
63
       this.url = this.properties.domain + this.properties.baseLink+this._router.url;
64

    
65
        var description = "Linking is a functionality provided by OpenAIRE, in order to link research results with a project, a research community or other research results.";
66
        this.updateTitle(this.pageTitle);
67
        this.updateDescription(description);
68
        this.updateUrl(this.url);
69

    
70
        this.seoService.createLinkForCanonicalURL(this.url, false);
71

    
72
        if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
73
          this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe());
74
        }
75

    
76
        this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
77
          this.pageContents = contents;
78
        })
79

    
80

    
81
      if( typeof localStorage !== 'undefined') {
82
        this.localStoragePrefix +=(this.communityId?this.communityId+"_":"");
83
        if(localStorage.getItem(this.localStoragePrefix + "results")){
84
          this.results  = JSON.parse(localStorage.getItem(this.localStoragePrefix + "results"));
85
        }
86

    
87
        if(localStorage.getItem(this.localStoragePrefix + "sources")){
88
          this.sources  = JSON.parse(localStorage.getItem(this.localStoragePrefix + "sources"));
89
        }
90
    }
91
  }
92

    
93
  ngOnDestroy() {
94
    this.subscriptions.forEach(subscription => {
95
      if (subscription instanceof Subscriber) {
96
        subscription.unsubscribe();
97
      }
98
    });
99
  }
100

    
101
  openSelectionModal() {
102
    this.alert.cancelButton = false;
103
    this.alert.okButton = false;
104
    this.alert.alertTitle = "Select the type of Entity to Link to your sources";
105
    // this.alert.message = "<div>All the links you provided will be published in the OpenAIRE platform. " +
106
    //   "<br>Make sure you have checked all the information you provided. In some cases some links take more time to be published. " +
107
    //   "<br>For more information please check the linking status in My-Links page. " +
108
    //   "<br><br>Do you confirm the information you provide are valid?</div>";
109

    
110
    this.alert.open();
111
  }
112

    
113
  closeSelectionModal(show:string=null) {
114
    if(show){
115
      this.showOptions.show = show;
116
      this.showOptions.basketShowSources=false;
117
      this.showOptions.basketShowLinksTo=true;
118
    }
119
    this.alert.cancel();
120
    this.scrollUp();
121

    
122
  }
123
  scrollUp(){
124
    HelperFunctions.scroll();
125
  }
126

    
127

    
128
  private updateDescription(description:string) {
129
    this._meta.updateTag({content:description},"name='description'");
130
    this._meta.updateTag({content:description},"property='og:description'");
131
  }
132
  private updateTitle(title:string) {
133
    var _prefix ="";
134
    if(!this.communityId) {
135
      _prefix ="OpenAIRE | ";
136
    }
137
    var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
138
    this._title.setTitle(_title);
139
    this._meta.updateTag({content:_title},"property='og:title'");
140
  }
141
  private updateUrl(url:string) {
142
    this._meta.updateTag({content:url},"property='og:url'");
143
  }
144
}
(2-2/3)