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

98 lines
3.1 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";
import {LocalStorageService} from "../../services/localStorage.service";
@Component({
selector: 'community-search-result',
templateUrl: 'communitySearchResults.component.html'
})
export class CommunitySearchResultsComponent {
@Input() results: CommunityInfo[];
@Input() status: number;
@Input() type: string;
@Input() showType = false;
@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;
public directLink: boolean = true;
constructor(private router: Router,
private localStorageService: LocalStorageService) {
}
ngOnInit() {
this.localStorageService.get().subscribe(value => {
this.directLink = value;
});
}
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 are going to visit ' +
((community.title) ? community.title : community.shortTitle) + ' Gateway';
this.modal.alertMessage = false;
this.modal.okButtonLeft = false;
this.modal.okButtonText = 'Yes';
this.modal.cancelButtonText = 'No';
this.modal.choice = true;
this.modal.open();
}
public getCommunityPageUrl(communityId: string): string {
let url = '';
if (this.isProduction()) {
url = 'https://' + this.getProductionPrefix() + communityId + '.openaire.eu';
} else {
url = this.router.createUrlTree(['/'], {
queryParams: {'communityId': communityId}
}).toString();
}
return url;
}
public goToCommunityPage(data: any) {
if (data.value == true) {
this.localStorageService.setCommunityDirectLink(data.choice);
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');
}
}
}