2019-07-30 15:27:12 +02:00
import { Component , Input , ViewChild } from '@angular/core' ;
import { ActivatedRoute , Router } from '@angular/router' ;
import { Location } from '@angular/common' ;
2019-04-08 14:17:39 +02:00
2019-07-30 15:27:12 +02:00
import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties' ;
2020-06-30 18:00:24 +02:00
import { CommunityInfo , prodReadyCommunities } from '../../openaireLibrary/connect/community/communityInfo' ;
2019-07-30 15:27:12 +02:00
import { LocalStorageService } from "../../openaireLibrary/services/localStorage.service" ;
2019-04-08 14:17:39 +02:00
@Component ( {
2019-07-30 15:27:12 +02:00
selector : 'browse-community' ,
templateUrl : 'browse-community.component.html'
2019-04-08 14:17:39 +02:00
} )
export class BrowseCommunityComponent {
@Input ( ) public community : CommunityInfo = null ;
@Input ( ) public showDescription : boolean = true ;
2020-04-30 12:35:12 +02:00
@Input ( ) public smallTitle : boolean = false ;
2019-04-09 20:48:03 +02:00
@ViewChild ( 'AlertModal' ) modal ;
2019-04-08 14:17:39 +02:00
2019-04-09 20:48:03 +02:00
public hiddenMessage : string = "Community is hidden to registered users. It is visible only to users that have privileges to manage community; delay: 100" ;
2019-04-08 14:17:39 +02:00
// cut title too
// check title length, if is manager, if is private and cut description accordingly
2019-04-15 12:06:58 +02:00
public thresholdTitle : number = 50 ;
2019-07-04 15:09:48 +02:00
public thresholdDescription : number = 120 ;
2019-07-30 15:27:12 +02:00
properties : EnvProperties ;
public directLink : boolean = true ;
2019-04-08 14:17:39 +02:00
2019-07-30 15:27:12 +02:00
constructor ( private route : ActivatedRoute ,
private router : Router ,
private location : Location ,
private localStorageService : LocalStorageService ) {
}
2019-04-08 14:17:39 +02:00
public ngOnInit() {
this . route . data
2019-07-30 15:27:12 +02:00
. subscribe ( ( data : { envSpecific : EnvProperties } ) = > {
this . properties = data . envSpecific ;
this . localStorageService . get ( ) . subscribe ( value = > {
this . directLink = value ;
} ) ;
} ) ;
2019-04-08 14:17:39 +02:00
}
2019-07-30 15:27:12 +02:00
public ngOnDestroy() {
}
2019-04-08 14:17:39 +02:00
2019-07-30 15:27:12 +02:00
isProduction ( ) : boolean {
return this . properties . environment != "development" ;
2019-04-08 14:17:39 +02:00
}
2019-07-30 15:27:12 +02:00
2020-06-30 18:00:24 +02:00
getProductionPrefix ( id :string ) : string {
return ( this . properties . environment == "production" && prodReadyCommunities . indexOf ( id ) != - 1 ) ? "" : "beta." ;
2019-04-08 14:17:39 +02:00
}
2019-04-09 20:48:03 +02:00
public confirmModalOpen() {
2019-07-30 15:27:12 +02:00
this . modal . cancelButton = true ;
this . modal . okButton = true ;
this . modal . alertTitle = 'You are going to visit ' +
2019-07-30 15:29:34 +02:00
( ( this . community . title ) ? this . community.title : this.community.shortTitle ) + ' Gateway' ;
2019-07-30 15:27:12 +02:00
this . modal . alertMessage = false ;
this . modal . okButtonLeft = false ;
this . modal . okButtonText = 'Yes' ;
this . modal . cancelButtonText = 'No' ;
this . modal . choice = true ;
this . modal . open ( ) ;
2019-04-09 20:48:03 +02:00
}
2019-07-30 15:27:12 +02:00
public getCommunityPageUrl ( ) : string {
2019-04-09 20:48:03 +02:00
let url = '' ;
2019-07-30 15:27:12 +02:00
if ( this . isProduction ( ) ) {
2020-06-30 18:00:24 +02:00
url = 'https://' + this . getProductionPrefix ( this . community . communityId ) + this . community . communityId + '.openaire.eu' ;
2019-04-09 20:48:03 +02:00
} else {
url = this . router . createUrlTree ( [ '/' ] , {
2019-07-30 15:27:12 +02:00
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 ( ) ) {
2020-06-30 18:00:24 +02:00
url = 'https://' + this . getProductionPrefix ( this . community . communityId ) + this . community . communityId + '.openaire.eu' ;
2019-07-30 15:27:12 +02:00
} else {
url = this . router . createUrlTree ( [ '/' ] , {
queryParams : { 'communityId' : this . community . communityId }
} ) . toString ( ) ;
}
window . open ( url , '_blank' ) ;
2019-04-09 20:48:03 +02:00
}
}
2019-04-08 14:17:39 +02:00
}