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

    
14
declare var UIkit:any;
15

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

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

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

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

    
39
  @Input() sources:ClaimEntity[] =[];
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
  subscriptions = [];
52

    
53
  ngOnInit() {
54
    this.showOptions.show = 'source';
55
    if(this.inlineEntity){
56
      this.showOptions.basketShowSources  = false;
57
      this.showOptions.basketShowLinksTo = true;
58
      this.showOptions.show = this.showOptions.linkTo;
59
    }
60
    this.subscriptions.push(this.route.data
61
      .subscribe((data: { envSpecific: EnvProperties }) => {
62
         this.properties = data.envSpecific;
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)