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

    
13
declare var UIkit:any;
14

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

    
19
})
20
export class LinkingGenericComponent {
21
  @Input() piwikSiteId = null;
22
  @Input() pageTitle: string = null;
23
  piwiksub:any;
24

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

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

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

    
46

    
47
  constructor (private _router: Router,  private route: ActivatedRoute, private entitySearch:EntitiesSearchService,
48
               private _meta: Meta, private _title: Title,  private _piwikService:PiwikService,
49
               private seoService: SEOService, private helper: HelperService ) {
50
  }
51
  ngOnInit() {
52
    this.showOptions.show = 'source';
53
    if(this.inlineEntity){
54
      this.showOptions.basketShowSources  = false;
55
      this.showOptions.basketShowLinksTo = true;
56
      this.showOptions.show = this.showOptions.linkTo;
57
    }
58
    this.route.data
59
      .subscribe((data: { envSpecific: EnvProperties }) => {
60
         this.properties = data.envSpecific;
61
         this.url = data.envSpecific.baseLink+this._router.url;
62

    
63
        var description = "Openaire, linking, claim, publication, research data, software, other research product, project, community";
64
        this.updateTitle(this.pageTitle);
65
        this.updateDescription(description);
66
        this.updateUrl(this.url);
67

    
68
        this.seoService.createLinkForCanonicalURL(this.url, false);
69

    
70
        if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
71
          this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe();
72
        }
73

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

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

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

    
91
  ngOnDestroy() {
92
    if(this.piwiksub){
93
      this.piwiksub.unsubscribe();
94
    }
95
  }
96

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

    
106
    this.alert.open();
107
  }
108

    
109
  closeSelectionModal(show:string=null) {
110
    if(show){
111
      this.showOptions.show = show;
112
      this.showOptions.basketShowSources=false;
113
      this.showOptions.basketShowLinksTo=true;
114
    }
115
    this.alert.cancel();
116
    this.scrollUp();
117

    
118
  }
119
  scrollUp(){
120
    HelperFunctions.scroll();
121
  }
122

    
123

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