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." : ""; return "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 = (this.type == 'community')? community.communityId:community['alias']; this.modal.cancelButton = true; this.modal.okButton = true; this.modal.alertTitle = 'You are going to visit ' + ((community.title) ? community.title : community.shortTitle) + (this.type == 'community')? ' Gateway':' Monitor Dashboard'; 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(entity): string { let url = ''; if (this.isProduction()) { url = 'https://' + this.getProductionPrefix() + entity.communityId + '.openaire.eu'; } else { url = this.router.createUrlTree(['/'], { queryParams: {'communityId': entity.communityId} }).toString(); } if(this.type == 'funder'){ url = "http://dl170.madgik.di.uoa.gr/monitor/dashboard/"+entity.alias; } 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(); } if(this.type == 'funder'){ url = "http://dl170.madgik.di.uoa.gr/monitor/dashboard/"+this.selectedCommunityId; } console.log(url) window.open(url, '_blank'); } } }