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;
|
2019-08-05 12:30:19 +02:00
|
|
|
@Input() showType = false;
|
2019-04-05 19:21:23 +02:00
|
|
|
@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 {
|
2020-04-10 11:45:20 +02:00
|
|
|
// return (this.properties.environment == "beta") ? "beta." : "";
|
|
|
|
return "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-12-03 11:45:28 +01:00
|
|
|
this.selectedCommunityId = (this.type == 'community')? community.communityId:community['alias'];
|
2019-07-30 15:26:31 +02:00
|
|
|
this.modal.cancelButton = true;
|
|
|
|
this.modal.okButton = true;
|
|
|
|
this.modal.alertTitle = 'You are going to visit ' +
|
2019-12-03 11:45:28 +01:00
|
|
|
((community.title) ? community.title : community.shortTitle) + (this.type == 'community')? ' Gateway':' Monitor Dashboard';
|
2019-07-30 15:26:31 +02:00
|
|
|
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-12-03 11:45:28 +01:00
|
|
|
public getCommunityPageUrl(entity): string {
|
2019-04-05 19:21:23 +02:00
|
|
|
let url = '';
|
2019-07-30 15:26:31 +02:00
|
|
|
if (this.isProduction()) {
|
2019-12-03 11:45:28 +01:00
|
|
|
url = 'https://' + this.getProductionPrefix() + entity.communityId + '.openaire.eu';
|
2019-04-05 19:21:23 +02:00
|
|
|
} else {
|
|
|
|
url = this.router.createUrlTree(['/'], {
|
2019-12-03 11:45:28 +01:00
|
|
|
queryParams: {'communityId': entity.communityId}
|
2019-07-30 15:26:31 +02:00
|
|
|
}).toString();
|
|
|
|
}
|
2019-12-03 11:45:28 +01:00
|
|
|
if(this.type == 'funder'){
|
|
|
|
url = "http://dl170.madgik.di.uoa.gr/monitor/dashboard/"+entity.alias;
|
|
|
|
}
|
2019-07-30 15:26:31 +02:00
|
|
|
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();
|
|
|
|
}
|
2019-12-03 11:45:28 +01:00
|
|
|
if(this.type == 'funder'){
|
|
|
|
url = "http://dl170.madgik.di.uoa.gr/monitor/dashboard/"+this.selectedCommunityId;
|
|
|
|
}
|
|
|
|
console.log(url)
|
2019-07-30 15:26:31 +02:00
|
|
|
window.open(url, '_blank');
|
2019-04-05 19:21:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|