2019-04-05 19:21:23 +02:00
|
|
|
import {Component, Input, ViewChild} from '@angular/core';
|
|
|
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
|
|
|
import {RouterHelper} from '../../utils/routerHelper.class';
|
2019-07-30 15:26:31 +02:00
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
2019-04-05 19:21:23 +02:00
|
|
|
import {CommunityInfo} from "../../connect/community/communityInfo";
|
|
|
|
import {Router} from "@angular/router";
|
2019-07-30 15:26:31 +02:00
|
|
|
import {LocalStorageService} from "../../services/localStorage.service";
|
|
|
|
|
2019-04-05 19:21:23 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'community-search-result',
|
2019-07-30 15:26:31 +02:00
|
|
|
templateUrl: 'communitySearchResults.component.html'
|
2019-04-05 19:21:23 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
export class CommunitySearchResultsComponent {
|
2019-04-13 20:26:46 +02:00
|
|
|
@Input() results: CommunityInfo[];
|
2019-04-05 19:21:23 +02:00
|
|
|
@Input() status: number;
|
|
|
|
@Input() type: string;
|
|
|
|
@Input() showLoading: boolean = false;
|
|
|
|
@Input() custom_class: string = "search-results";
|
|
|
|
@Input() properties: EnvProperties;
|
2019-04-08 16:53:09 +02:00
|
|
|
@Input() maxCharacters: number = 150;
|
2019-04-05 19:21:23 +02:00
|
|
|
@ViewChild('AlertModal') modal;
|
|
|
|
|
|
|
|
|
|
|
|
public urlParam: string;
|
2019-07-30 15:26:31 +02:00
|
|
|
public errorCodes: ErrorCodes = new ErrorCodes();
|
|
|
|
public routerHelper: RouterHelper = new RouterHelper();
|
2019-04-05 19:21:23 +02:00
|
|
|
public errorMessage: string = "No results found";
|
|
|
|
public selectedCommunityId: string;
|
2019-07-30 15:26:31 +02:00
|
|
|
public directLink: boolean = true;
|
2019-04-05 19:21:23 +02:00
|
|
|
|
|
|
|
|
2019-07-30 15:26:31 +02:00
|
|
|
constructor(private router: Router,
|
|
|
|
private localStorageService: LocalStorageService) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.localStorageService.get().subscribe(value => {
|
|
|
|
this.directLink = value;
|
|
|
|
});
|
2019-04-05 19:21:23 +02:00
|
|
|
}
|
|
|
|
|
2019-07-30 15:26:31 +02:00
|
|
|
getProductionPrefix(): string {
|
|
|
|
return (this.properties.environment == "beta") ? "beta." : ""
|
2019-04-05 19:21:23 +02:00
|
|
|
}
|
|
|
|
|
2019-07-30 15:26:31 +02:00
|
|
|
isProduction(): boolean {
|
|
|
|
return this.properties.environment != "development";
|
2019-04-05 19:21:23 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-30 15:26:31 +02:00
|
|
|
public _formatDescription(description) {
|
|
|
|
return (((description).length > this.maxCharacters) ? (description.substring(0, (this.maxCharacters - ('...').length)) + "...") : description);
|
2019-04-08 16:53:09 +02:00
|
|
|
}
|
|
|
|
|
2019-04-05 19:21:23 +02:00
|
|
|
public confirmModalOpen(community: CommunityInfo) {
|
2019-07-30 15:26:31 +02:00
|
|
|
this.modal.cancelButton = true;
|
|
|
|
this.modal.okButton = true;
|
|
|
|
this.modal.alertTitle = 'You are going to visit ' +
|
|
|
|
((community.title) ? community.title : community.shortTitle);
|
|
|
|
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-05 19:21:23 +02:00
|
|
|
}
|
|
|
|
|
2019-07-30 15:26:31 +02:00
|
|
|
public getCommunityPageUrl(communityId: string): string {
|
2019-04-05 19:21:23 +02:00
|
|
|
let url = '';
|
2019-07-30 15:26:31 +02:00
|
|
|
if (this.isProduction()) {
|
|
|
|
url = 'https://' + this.getProductionPrefix() + communityId + '.openaire.eu';
|
2019-04-05 19:21:23 +02:00
|
|
|
} else {
|
|
|
|
url = this.router.createUrlTree(['/'], {
|
2019-07-30 15:26:31 +02:00
|
|
|
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');
|
2019-04-05 19:21:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|