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 {SearchPublicationsService} from '../../services/searchPublications.service';
8
import {SearchDatasetsService} from '../../services/searchDatasets.service';
9
import {SEOService} from '../../sharedComponents/SEO/SEO.service';
10
import {AlertModal} from "../../utils/modal/alert";
11
import {HelperFunctions} from "../../utils/HelperFunctions.class";
12
import {HelperService} from "../../utils/helper/helper.service";
13
import {PiwikService} from "../../utils/piwik/piwik.service";
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() title: string = null;
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
  sub:any =null;
42
  properties:EnvProperties;
43
  @Input() localStoragePrefix:string = "linking_";
44
  url=null;
45
  @ViewChild(AlertModal) alert;
46
  public pageContents = null;
47

    
48

    
49
  constructor (private _router: Router,  private route: ActivatedRoute, private entitySearch:EntitiesSearchService,
50
               private publicationsSearch:SearchPublicationsService, private datasetsSearch:SearchDatasetsService,
51
               private _meta: Meta, private _title: Title,  private _piwikService:PiwikService,
52
               private seoService: SEOService, private helper: HelperService ) {
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
    this.route.data
62
      .subscribe((data: { envSpecific: EnvProperties }) => {
63
         this.properties = data.envSpecific;
64
         this.url = data.envSpecific.baseLink+this._router.url;
65

    
66
        var description = "Openaire, linking, claim, publication, research data, software, other research product, project, community";
67
        this.updateTitle(this.title);
68
        this.updateDescription(description);
69
        this.updateUrl(this.url);
70

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

    
73
        if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
74
          this.piwiksub = this._piwikService.trackView(this.properties, this.title, this.piwikSiteId).subscribe();
75
        }
76

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

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

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

    
94
  ngOnDestroy() {
95
    if(this.piwiksub){
96
      this.piwiksub.unsubscribe();
97
    }
98
  }
99

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

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

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

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

    
126

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