Project

General

Profile

1
import {Component, Input}          from '@angular/core';
2
import {Router, ActivatedRoute}    from '@angular/router';
3
import {Title, Meta}               from '@angular/platform-browser';
4

    
5
import {Observable}                from 'rxjs/Observable';
6

    
7
import {EnvProperties}             from '../utils/properties/env-properties';
8

    
9
import {PiwikService}              from '../utils/piwik/piwik.service';
10

    
11

    
12
@Component({
13
    selector: 'deposit',
14
    templateUrl: 'deposit.component.html'
15
})
16

    
17
export class DepositComponent {
18
  @Input() compatibility: string = '';
19
  @Input() mapUrl: string = null; // optional  in case i-frame is needed
20
  @Input() searchBySubjects: boolean = false; // optional: in case search by subjects is needed
21
  @Input() piwikSiteId = null;
22

    
23
  public status: number;
24

    
25
  // Type of entity: Publication or Research Data
26
  @Input() requestFor: string = "Publications";
27

    
28
  // url's needed for information text
29
  public openAccess: string;
30
  public openAccessRepo: string;
31
  public fp7Guidlines: string;
32
  public h2020Guidlines: string;
33
  public ercGuidlines: string;
34
  public helpdesk: string;
35

    
36
  // Id of the new selected organization to be searched
37
  public selectedId: string = "";
38

    
39
  public warningMessage: string = "";
40

    
41
  piwiksub:any;
42
  properties:EnvProperties;
43

    
44
  constructor (private  route: ActivatedRoute, private _router: Router,
45
               private _meta: Meta, private _title: Title,
46
               private _piwikService:PiwikService) {
47

    
48
      var title = "Deposit "+this.requestFor;
49
      var description = "Openaire,  repositories, open access,  content provider, compatibility, organization, deposit "+ this.requestFor;
50

    
51
      this.updateTitle(title);
52
      this.updateDescription(description);
53
  }
54
  ngOnInit() {
55
    this.route.data
56
      .subscribe((data: { envSpecific: EnvProperties }) => {
57
         this.properties = data.envSpecific;
58
         this.openAccess = this.properties.openAccess;
59
         this.openAccessRepo = this.properties.openAccessRepo;
60
         this.fp7Guidlines = this.properties.fp7Guidlines
61
         this.h2020Guidlines = this.properties.h2020Guidlines
62
         this.ercGuidlines = this.properties.ercGuidlines
63
         this.helpdesk = this.properties.helpdesk;
64
         this.updateUrl(data.envSpecific.baseLink+this._router.url);
65

    
66
         if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
67
           this.piwiksub = this._piwikService.trackView(this.properties, "Deposit "+this.requestFor, this.piwikSiteId).subscribe();
68
         }
69
      });
70
    }
71
  ngOnDestroy() {
72
    if(this.piwiksub){
73
      this.piwiksub.unsubscribe();
74
    }
75
  }
76

    
77
  public organizationSelected(id: string) {
78
      console.info("organization selected");
79
      if(id && id.length > 0){
80
          if(this.requestFor == "Publications") {
81
              this._router.navigate( ['participate/deposit-publications-result'], { queryParams: { "organizationId": id } } );
82
          } else if(this.requestFor == "Research Data") {
83
              this._router.navigate( ['participate/deposit-datasets-result'], { queryParams: { "organizationId": id } } );
84
          }
85
      } else {
86
          this.warningMessage = "No organization selected";
87
      }
88
  }
89

    
90
  public valueChanged($event) {
91
    this.selectedId = $event.value;
92
  }
93

    
94
  private updateDescription(description:string) {
95
    this._meta.updateTag({content:description},"name='description'");
96
    this._meta.updateTag({content:description},"property='og:description'");
97
  }
98
  private updateTitle(title:string) {
99
    var _prefix ="OpenAIRE | ";
100
    var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
101
    this._title.setTitle(_title);
102
    this._meta.updateTag({content:_title},"property='og:title'");
103
  }
104
  private updateUrl(url:string) {
105
    this._meta.updateTag({content:url},"property='og:url'");
106
  }
107
}
(2-2/4)