openaire-library/searchPages/searchUtils/communitySearchResults.comp...

70 lines
2.2 KiB
TypeScript

import {Component, Input, ViewChild} from '@angular/core';
import {ErrorCodes} from '../../utils/properties/errorCodes';
import {RouterHelper} from '../../utils/routerHelper.class';
import{EnvProperties} from '../../utils/properties/env-properties';
import {CommunityInfo} from "../../connect/community/communityInfo";
import {Router} from "@angular/router";
@Component({
selector: 'community-search-result',
templateUrl:'communitySearchResults.component.html'
})
export class CommunitySearchResultsComponent {
@Input() results: CommunityInfo[];
@Input() status: number;
@Input() type: string;
@Input() showLoading: boolean = false;
@Input() custom_class: string = "search-results";
@Input() properties: EnvProperties;
@Input() maxCharacters: number = 150;
@ViewChild('AlertModal') modal;
public urlParam: string;
public errorCodes:ErrorCodes = new ErrorCodes();
public routerHelper:RouterHelper = new RouterHelper();
public errorMessage: string = "No results found";
public selectedCommunityId: string;
constructor(private router: Router) {}
ngOnInit() {
}
getProductionPrefix():string{
return (this.properties.environment == "beta")?"beta.":""
}
isProduction():boolean{
return this.properties.environment!="development";
}
public _formatDescription(description){
return (((description).length > this.maxCharacters)?(description.substring(0,(this.maxCharacters - ('...').length))+"..."):description);
}
public confirmModalOpen(community: CommunityInfo) {
this.selectedCommunityId = community.communityId;
this.modal.cancelButton = true;
this.modal.okButton = true;
this.modal.alertTitle = 'You have selected ' + 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.selectedCommunityId +'.openaire.eu';
} else {
url = this.router.createUrlTree(['/'], {
queryParams: { 'communityId': this.selectedCommunityId} }).toString();
}
window.open(url, '_blank');
}
}