import {Component, Input, ViewChild} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; import {Location} from '@angular/common'; import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties'; import {CommunityInfo} from '../../openaireLibrary/connect/community/communityInfo'; import {LocalStorageService} from "../../openaireLibrary/services/localStorage.service"; @Component({ selector: 'browse-community', templateUrl: 'browse-community.component.html' }) export class BrowseCommunityComponent { @Input() public community: CommunityInfo = null; @Input() public showDescription: boolean = true; @ViewChild('AlertModal') modal; public hiddenMessage: string = "Community is hidden to registered users. It is visible only to users that have privileges to manage community; delay: 100"; // cut title too // check title length, if is manager, if is private and cut description accordingly public thresholdTitle: number = 50; public thresholdDescription: number = 120; properties: EnvProperties; public directLink: boolean = true; constructor(private route: ActivatedRoute, private router: Router, private location: Location, private localStorageService: LocalStorageService) { } public ngOnInit() { this.route.data .subscribe((data: { envSpecific: EnvProperties }) => { this.properties = data.envSpecific; this.localStorageService.get().subscribe(value => { this.directLink = value; }); }); } public ngOnDestroy() { } isProduction(): boolean { return this.properties.environment != "development"; } getProductionPrefix(): string { return (this.properties.environment == "beta") ? "beta." : "" } public confirmModalOpen() { this.modal.cancelButton = true; this.modal.okButton = true; this.modal.alertTitle = 'You are going to visit ' + ((this.community.title) ? this.community.title : this.community.shortTitle) + ' Gateway'; this.modal.alertMessage = false; this.modal.okButtonLeft = false; this.modal.okButtonText = 'Yes'; this.modal.cancelButtonText = 'No'; this.modal.choice = true; this.modal.open(); } public getCommunityPageUrl(): string { let url = ''; if (this.isProduction()) { url = 'https://' + this.getProductionPrefix() + this.community.communityId + '.openaire.eu'; } else { url = this.router.createUrlTree(['/'], { queryParams: {'communityId': this.community.communityId} }).toString(); } return url; } public goToCommunityPage(data: any) { if (data.value == true) { this.localStorageService.setCommunityDirectLink(data.choice); let url = ''; if (this.isProduction()) { url = 'https://' + this.getProductionPrefix() + this.community.communityId + '.openaire.eu'; } else { url = this.router.createUrlTree(['/'], { queryParams: {'communityId': this.community.communityId} }).toString(); } window.open(url, '_blank'); } } }