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-11-30 18:04:05 +01:00
import { CommunityInfo } from '../../openaireLibrary/connect/community/communityInfo' ;
2019-07-30 15:27:12 +02:00
import { LocalStorageService } from "../../openaireLibrary/services/localStorage.service" ;
2020-11-12 16:59:26 +01:00
import { Subscriber } from "rxjs" ;
2020-11-30 18:04:05 +01:00
import { properties } from "../../../environments/environment" ;
2021-05-11 11:26:14 +02:00
import { StringUtils } from "../../openaireLibrary/utils/string-utils.class" ;
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 ;
2021-07-14 16:51:20 +02:00
@ViewChild ( 'AlertModal' , { static : true } ) 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() {
2020-11-30 18:04:05 +01:00
this . properties = properties ;
this . subscriptions . push ( this . localStorageService . get ( ) . subscribe ( value = > {
this . directLink = value ;
} ) ) ;
2019-04-08 14:17:39 +02:00
}
2020-11-12 16:59:26 +01:00
subscriptions = [ ] ;
ngOnDestroy() {
this . subscriptions . forEach ( subscription = > {
if ( subscription instanceof Subscriber ) {
subscription . unsubscribe ( ) ;
}
} ) ;
2019-07-30 15:27:12 +02:00
}
2019-04-08 14:17:39 +02:00
2020-11-12 16:59:26 +01: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 {
2020-11-30 18:04:05 +01:00
return ( this . properties . environment == "production" ) ? "" : "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
}
}
2021-05-11 11:26:14 +02:00
public _formatDescription ( description ) {
let descr : string = StringUtils . HTMLToString ( description ) ;
return ( ( ( descr ) . length > this . thresholdDescription ) ? ( descr . substring ( 0 , ( this . thresholdDescription - ( '...' ) . length ) ) + "..." ) : descr ) ;
}
2019-04-08 14:17:39 +02:00
}