2019-04-08 14:17:39 +02:00
import { Component , Input , Output , EventEmitter } from '@angular/core' ;
import { ViewChild , ChangeDetectionStrategy } from '@angular/core' ;
import { ViewEncapsulation } from '@angular/core' ;
import { ActivatedRoute , Router } from '@angular/router' ;
import { Location } from '@angular/common' ;
import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties' ;
import { ErrorCodes } from '../../openaireLibrary/utils/properties/errorCodes' ;
import { CommunityInfo } from '../../openaireLibrary/connect/community/communityInfo' ;
@Component ( {
selector : 'browse-community' ,
2019-04-16 12:43:08 +02:00
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 ;
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-04-08 14:17:39 +02:00
public thresholdDescription : number = 150 ;
properties :EnvProperties ;
constructor ( private route : ActivatedRoute ,
2019-04-09 20:48:03 +02:00
private router : Router ,
2019-04-08 14:17:39 +02:00
private location : Location ) { }
public ngOnInit() {
this . route . data
. subscribe ( ( data : { envSpecific : EnvProperties } ) = > {
this . properties = data . envSpecific ;
} ) ;
}
public ngOnDestroy() { }
isProduction ( ) : boolean {
return this . properties . environment != "development" ;
}
getProductionPrefix ( ) : string {
return ( this . properties . environment == "beta" ) ? "beta." : ""
}
2019-04-09 20:48:03 +02:00
public confirmModalOpen() {
this . modal . cancelButton = true ;
this . modal . okButton = true ;
this . modal . alertTitle = 'You have selected ' + this . community . title ;
this . modal . alertMessage = false ;
this . modal . okButtonLeft = false ;
this . modal . okButtonText = 'Yes' ;
this . modal . cancelButtonText = 'No' ;
this . modal . open ( ) ;
}
public goToCommunityPage ( data : any ) {
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' ) ;
}
2019-04-08 14:17:39 +02:00
}