Project

General

Profile

1
import {Component, Input, OnInit} from '@angular/core';
2
import {ActivatedRoute, Router} from '@angular/router';
3

    
4
import {EnvProperties} from '../../../openaireLibrary/utils/properties/env-properties';
5
import {User} from '../../../openaireLibrary/login/utils/helper.class';
6
import {HelperService} from "../../../openaireLibrary/utils/helper/helper.service";
7
import {Meta, Title} from "@angular/platform-browser";
8
import {SEOService} from "../../../openaireLibrary/sharedComponents/SEO/SEO.service";
9
import {PiwikService} from "../../../openaireLibrary/utils/piwik/piwik.service";
10
import {UserManagementService} from "../../../openaireLibrary/services/user-management.service";
11
import {Breadcrumb} from "../../../openaireLibrary/utils/breadcrumbs/breadcrumbs.component";
12
import {Subscriber, Subscription} from "rxjs";
13
import {properties} from "../../../../environments/environment";
14

    
15
declare var UIkit;
16

    
17
@Component({
18
  selector: 'invite',
19
  templateUrl: './invite.component.html',
20
})
21
export class InviteComponent implements OnInit {
22
  @Input() longView: boolean = true;
23
  @Input() communityId = null;
24
  public properties: EnvProperties = properties;
25
  public pageTitle: string = "Invite";
26
  public user: User;
27
  public url: string;
28
  public pageContents;
29
  public divContents
30
  public breadcrumbs: Breadcrumb[] = [{name: 'home', route: '/'}, {name: 'invite'}];
31
  private subs: Subscription[] = [];
32
  
33
  constructor(
34
    private route: ActivatedRoute,
35
    private _router: Router,
36
    private _meta: Meta,
37
    private helper: HelperService,
38
    private _title: Title,
39
    private seoService: SEOService,
40
    private _piwikService: PiwikService,
41
    private userManageService: UserManagementService) {
42
  }
43
  
44
  public ngOnInit() {
45
    this.subs.push(this.userManageService.getUserInfo().subscribe(
46
      user => {
47
        this.user = user;
48
    }));
49
    this.getPageContents();
50
    this.url = this.properties.domain + this._router.url;
51
    if(this.longView) {
52
      this.seoService.createLinkForCanonicalURL(this.url);
53
      this.updateUrl(this.url);
54
      this.updateTitle(this.pageTitle);
55
      this.updateDescription("OpenAIRE - Connect, Community Gateway, research community, invite");
56
    }
57
  }
58
  
59
  ngOnDestroy() {
60
    for (let sub of this.subs) {
61
      if (sub instanceof Subscriber) {
62
        sub.unsubscribe();
63
      }
64
    }
65
  }
66
  
67
  private getPageContents() {
68
    this.subs.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
69
      this.pageContents = contents;
70
    }));
71
  }
72
  
73
  private getDivContents() {
74
    this.subs.push(this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
75
      this.divContents = contents;
76
    }));
77
  }
78
  
79
  private updateDescription(description: string) {
80
    this._meta.updateTag({content: description}, "name='description'");
81
    this._meta.updateTag({content: description}, "property='og:description'");
82
  }
83
  
84
  private updateTitle(title: string) {
85
    var _title = ((title.length > 50) ? title.substring(0, 50) : title);
86
    this._title.setTitle(_title);
87
    this._meta.updateTag({content: _title}, "property='og:title'");
88
  }
89
  
90
  private updateUrl(url: string) {
91
    this._meta.updateTag({content: url}, "property='og:url'");
92
  }
93
  
94
  close(element) {
95
    UIkit.dropdown(element).hide();
96
    this
97
  }
98
}
(3-3/5)