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

    
9
@Component({
10
  selector: 'browse-community',
11
  templateUrl: 'browse-community.component.html'
12
})
13

    
14
export class BrowseCommunityComponent {
15
  @Input() public community: CommunityInfo = null;
16
  @Input() public showDescription: boolean = true;
17
  @Input() public smallTitle: boolean = false;
18
  @ViewChild('AlertModal') modal;
19

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

    
28
  constructor(private route: ActivatedRoute,
29
              private router: Router,
30
              private location: Location,
31
              private localStorageService: LocalStorageService) {
32
  }
33

    
34

    
35
  public ngOnInit() {
36
    this.route.data
37
      .subscribe((data: { envSpecific: EnvProperties }) => {
38
        this.properties = data.envSpecific;
39
        this.localStorageService.get().subscribe(value => {
40
          this.directLink = value;
41
        });
42
      });
43
  }
44

    
45
  public ngOnDestroy() {
46
  }
47

    
48
  isProduction(): boolean {
49
    return this.properties.environment != "development";
50
  }
51

    
52
  getProductionPrefix(): string {
53
    //return (this.properties.environment == "beta") ? "beta." : ""
54
    return "beta.";
55
  }
56

    
57
  public confirmModalOpen() {
58
    this.modal.cancelButton = true;
59
    this.modal.okButton = true;
60
    this.modal.alertTitle = 'You are going to visit ' +
61
      ((this.community.title) ? this.community.title : this.community.shortTitle) + ' Gateway';
62
    this.modal.alertMessage = false;
63
    this.modal.okButtonLeft = false;
64
    this.modal.okButtonText = 'Yes';
65
    this.modal.cancelButtonText = 'No';
66
    this.modal.choice = true;
67
    this.modal.open();
68
  }
69

    
70
  public getCommunityPageUrl(): string {
71
    let url = '';
72
    if (this.isProduction()) {
73
      url = 'https://' + this.getProductionPrefix() + this.community.communityId + '.openaire.eu';
74
    } else {
75
      url = this.router.createUrlTree(['/'], {
76
        queryParams: {'communityId': this.community.communityId}
77
      }).toString();
78
    }
79
    return url;
80
  }
81

    
82
  public goToCommunityPage(data: any) {
83
    if (data.value == true) {
84
      this.localStorageService.setCommunityDirectLink(data.choice);
85
      let url = '';
86
      if (this.isProduction()) {
87
        url = 'https://' + this.getProductionPrefix() + this.community.communityId + '.openaire.eu';
88
      } else {
89
        url = this.router.createUrlTree(['/'], {
90
          queryParams: {'communityId': this.community.communityId}
91
        }).toString();
92
      }
93
      window.open(url, '_blank');
94
    }
95
  }
96
}
(2-2/3)