Project

General

Profile

1
import {Component, Input, ViewChild} from '@angular/core';
2
import {ActivatedRoute, Router} from '@angular/router';
3
import {Location} from '@angular/common';
4

    
5
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
6
import {CommunityInfo} from '../../openaireLibrary/connect/community/communityInfo';
7
import {LocalStorageService} from "../../openaireLibrary/services/localStorage.service";
8
import {Subscriber} from "rxjs";
9
import {properties} from "../../../environments/environment";
10
import {StringUtils} from "../../openaireLibrary/utils/string-utils.class";
11

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

    
17
export class BrowseCommunityComponent {
18
  @Input() public community: CommunityInfo = null;
19
  @Input() public showDescription: boolean = true;
20
  @Input() public smallTitle: boolean = false;
21
  @ViewChild('AlertModal', { static: true }) modal;
22

    
23
  public hiddenMessage: string = "Community is hidden to registered users. It is visible only to users that have privileges to  manage community; delay: 100";
24
  // cut title too
25
  // check title length, if is manager, if is private and cut description accordingly
26
  public thresholdTitle: number = 50;
27
  public thresholdDescription: number = 120;
28
  properties: EnvProperties;
29
  public directLink: boolean = true;
30

    
31
  constructor(private route: ActivatedRoute,
32
              private router: Router,
33
              private location: Location,
34
              private localStorageService: LocalStorageService) {
35
  }
36

    
37

    
38
  public ngOnInit() {
39
    this.properties = properties;
40
    this.subscriptions.push(this.localStorageService.get().subscribe(value => {
41
      this.directLink = value;
42
    }));
43

    
44
  }
45

    
46
  subscriptions = [];
47
  ngOnDestroy() {
48
    this.subscriptions.forEach(subscription => {
49
      if (subscription instanceof Subscriber) {
50
        subscription.unsubscribe();
51
      }
52
    });
53
  }
54

    
55

    
56
  isProduction(): boolean {
57
    return this.properties.environment != "development";
58
  }
59

    
60
  getProductionPrefix(id:string): string {
61
    return (this.properties.environment == "production") ? "" : "beta.";
62
  }
63

    
64
  public confirmModalOpen() {
65
    this.modal.cancelButton = true;
66
    this.modal.okButton = true;
67
    this.modal.alertTitle = 'You are going to visit ' +
68
      ((this.community.title) ? this.community.title : this.community.shortTitle) + ' Gateway';
69
    this.modal.alertMessage = false;
70
    this.modal.okButtonLeft = false;
71
    this.modal.okButtonText = 'Yes';
72
    this.modal.cancelButtonText = 'No';
73
    this.modal.choice = true;
74
    this.modal.open();
75
  }
76

    
77
  public getCommunityPageUrl(): string {
78
    let url = '';
79
    if (this.isProduction()) {
80
      url = 'https://' + this.getProductionPrefix(this.community.communityId) + this.community.communityId + '.openaire.eu';
81
    } else {
82
      url = this.router.createUrlTree(['/'], {
83
        queryParams: {'communityId': this.community.communityId}
84
      }).toString();
85
    }
86
    return url;
87
  }
88

    
89
  public goToCommunityPage(data: any) {
90
    if (data.value == true) {
91
      this.localStorageService.setCommunityDirectLink(data.choice);
92
      let url = '';
93
      if (this.isProduction()) {
94
        url = 'https://' + this.getProductionPrefix(this.community.communityId) + this.community.communityId + '.openaire.eu';
95
      } else {
96
        url = this.router.createUrlTree(['/'], {
97
          queryParams: {'communityId': this.community.communityId}
98
        }).toString();
99
      }
100
      window.open(url, '_blank');
101
    }
102
  }
103

    
104
  public _formatDescription(description) {
105
    let descr: string = StringUtils.HTMLToString(description);
106
    return (((descr).length > this.thresholdDescription) ? (descr.substring(0, (this.thresholdDescription - ('...').length)) + "...") : descr);
107
  }
108
}
(2-2/3)