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
|
@ViewChild('AlertModal') modal;
|
18
|
|
19
|
public hiddenMessage: string = "Community is hidden to registered users. It is visible only to users that have privileges to manage community; delay: 100";
|
20
|
// cut title too
|
21
|
// check title length, if is manager, if is private and cut description accordingly
|
22
|
public thresholdTitle: number = 50;
|
23
|
public thresholdDescription: number = 120;
|
24
|
properties: EnvProperties;
|
25
|
public directLink: boolean = true;
|
26
|
|
27
|
constructor(private route: ActivatedRoute,
|
28
|
private router: Router,
|
29
|
private location: Location,
|
30
|
private localStorageService: LocalStorageService) {
|
31
|
}
|
32
|
|
33
|
|
34
|
public ngOnInit() {
|
35
|
this.route.data
|
36
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
37
|
this.properties = data.envSpecific;
|
38
|
this.localStorageService.get().subscribe(value => {
|
39
|
this.directLink = value;
|
40
|
});
|
41
|
});
|
42
|
}
|
43
|
|
44
|
public ngOnDestroy() {
|
45
|
}
|
46
|
|
47
|
isProduction(): boolean {
|
48
|
return this.properties.environment != "development";
|
49
|
}
|
50
|
|
51
|
getProductionPrefix(): string {
|
52
|
return (this.properties.environment == "beta") ? "beta." : ""
|
53
|
}
|
54
|
|
55
|
public confirmModalOpen() {
|
56
|
this.modal.cancelButton = true;
|
57
|
this.modal.okButton = true;
|
58
|
this.modal.alertTitle = 'You are going to visit ' +
|
59
|
((this.community.title) ? this.community.title : this.community.shortTitle) + ' Gateway';
|
60
|
this.modal.alertMessage = false;
|
61
|
this.modal.okButtonLeft = false;
|
62
|
this.modal.okButtonText = 'Yes';
|
63
|
this.modal.cancelButtonText = 'No';
|
64
|
this.modal.choice = true;
|
65
|
this.modal.open();
|
66
|
}
|
67
|
|
68
|
public getCommunityPageUrl(): string {
|
69
|
let url = '';
|
70
|
if (this.isProduction()) {
|
71
|
url = 'https://' + this.getProductionPrefix() + this.community.communityId + '.openaire.eu';
|
72
|
} else {
|
73
|
url = this.router.createUrlTree(['/'], {
|
74
|
queryParams: {'communityId': this.community.communityId}
|
75
|
}).toString();
|
76
|
}
|
77
|
return url;
|
78
|
}
|
79
|
|
80
|
public goToCommunityPage(data: any) {
|
81
|
if (data.value == true) {
|
82
|
this.localStorageService.setCommunityDirectLink(data.choice);
|
83
|
let url = '';
|
84
|
if (this.isProduction()) {
|
85
|
url = 'https://' + this.getProductionPrefix() + this.community.communityId + '.openaire.eu';
|
86
|
} else {
|
87
|
url = this.router.createUrlTree(['/'], {
|
88
|
queryParams: {'communityId': this.community.communityId}
|
89
|
}).toString();
|
90
|
}
|
91
|
window.open(url, '_blank');
|
92
|
}
|
93
|
}
|
94
|
}
|