connect/src/app/communities/browseCommunity/browse-community.component.ts

71 lines
2.5 KiB
TypeScript
Raw Normal View History

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',
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 = 150;
properties:EnvProperties;
constructor ( private route: ActivatedRoute,
private router: Router,
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.":""
}
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');
}
}