2020-06-05 14:56:28 +02:00
|
|
|
import {Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild} from '@angular/core';
|
2019-04-05 19:21:23 +02:00
|
|
|
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';
|
2020-11-30 17:55:28 +01:00
|
|
|
import {CommunityInfo} from "../../connect/community/communityInfo";
|
2019-04-05 19:21:23 +02:00
|
|
|
import {Router} from "@angular/router";
|
2019-07-30 15:26:31 +02:00
|
|
|
import {LocalStorageService} from "../../services/localStorage.service";
|
2020-11-30 17:55:28 +01:00
|
|
|
import {Stakeholder, StakeholderInfo} from "../../monitor/entities/stakeholder";
|
2019-07-30 15:26:31 +02:00
|
|
|
|
2019-04-05 19:21:23 +02:00
|
|
|
@Component({
|
2020-06-05 14:56:28 +02:00
|
|
|
selector: 'portal-search-result',
|
|
|
|
templateUrl: 'portal-search-result.component.html'
|
2019-04-05 19:21:23 +02:00
|
|
|
})
|
|
|
|
|
2020-12-02 16:26:35 +01:00
|
|
|
export class PortalSearchResultComponent implements OnInit{
|
2020-06-05 14:56:28 +02:00
|
|
|
@Input() results: (CommunityInfo & StakeholderInfo)[];
|
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;
|
2020-11-02 17:55:05 +01:00
|
|
|
/*visibilityIcon: Map<Visibility, string> = new Map<Visibility, string> ([
|
|
|
|
["PUBLIC", 'earth'],
|
|
|
|
["PRIVATE", 'lock'],
|
|
|
|
["RESTRICTED", 'group']
|
|
|
|
]);*/
|
2020-06-05 14:56:28 +02:00
|
|
|
|
2019-04-05 19:21:23 +02:00
|
|
|
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";
|
2020-06-05 14:56:28 +02:00
|
|
|
public selected: CommunityInfo & Stakeholder;
|
2019-07-30 15:26:31 +02:00
|
|
|
public directLink: boolean = true;
|
2020-11-11 15:43:13 +01:00
|
|
|
sub;
|
2020-06-05 14:56:28 +02:00
|
|
|
|
2019-07-30 15:26:31 +02:00
|
|
|
constructor(private router: Router,
|
|
|
|
private localStorageService: LocalStorageService) {
|
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
if(this.sub){
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
2019-07-30 15:26:31 +02:00
|
|
|
ngOnInit() {
|
2020-11-11 15:43:13 +01:00
|
|
|
this.sub = this.localStorageService.get().subscribe(value => {
|
2019-07-30 15:26:31 +02:00
|
|
|
this.directLink = value;
|
|
|
|
});
|
2019-04-05 19:21:23 +02:00
|
|
|
}
|
2020-12-02 16:26:35 +01:00
|
|
|
|
2020-06-05 14:56:28 +02:00
|
|
|
|
2020-06-30 17:56:56 +02:00
|
|
|
getProductionPrefix(id:string): string {
|
2020-11-30 17:55:28 +01:00
|
|
|
return (this.properties.environment == "production") ? "" : "beta.";
|
2019-04-05 19:21:23 +02:00
|
|
|
}
|
2020-06-05 14:56:28 +02:00
|
|
|
|
2019-07-30 15:26:31 +02:00
|
|
|
isProduction(): boolean {
|
|
|
|
return this.properties.environment != "development";
|
2020-06-05 14:56:28 +02:00
|
|
|
|
2019-04-05 19:21:23 +02:00
|
|
|
}
|
2020-06-05 14:56:28 +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
|
|
|
}
|
2020-06-05 14:56:28 +02:00
|
|
|
|
|
|
|
public confirmModalOpen(result: CommunityInfo & Stakeholder) {
|
|
|
|
this.selected = result;
|
2019-07-30 15:26:31 +02:00
|
|
|
this.modal.cancelButton = true;
|
|
|
|
this.modal.okButton = true;
|
2020-06-05 14:56:28 +02:00
|
|
|
if(this.type === 'stakeholder') {
|
|
|
|
this.modal.alertTitle = 'You are going to visit ' + result.name + ' Monitor Dashboard';
|
|
|
|
} else if (this.type === 'community') {
|
|
|
|
this.modal.alertTitle = 'You are going to visit ' + ((result.title) ? result.title : result.shortTitle) +' Gateway';
|
|
|
|
}
|
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
|
|
|
}
|
2020-06-05 14:56:28 +02:00
|
|
|
|
|
|
|
public getCommunityPageUrl(communityInfo: CommunityInfo): string {
|
2019-04-05 19:21:23 +02:00
|
|
|
let url = '';
|
2019-07-30 15:26:31 +02:00
|
|
|
if (this.isProduction()) {
|
2020-06-30 17:56:56 +02:00
|
|
|
url = 'https://' + this.getProductionPrefix(communityInfo.communityId ) + communityInfo.communityId + '.openaire.eu';
|
2019-04-05 19:21:23 +02:00
|
|
|
} else {
|
|
|
|
url = this.router.createUrlTree(['/'], {
|
2020-06-05 14:56:28 +02:00
|
|
|
queryParams: {'communityId': communityInfo.communityId}
|
2019-07-30 15:26:31 +02:00
|
|
|
}).toString();
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
}
|
2020-09-18 09:57:42 +02:00
|
|
|
|
2020-06-05 14:56:28 +02:00
|
|
|
public getStakeholderPageUrl(stakeholder: Stakeholder) {
|
2020-11-05 10:37:41 +01:00
|
|
|
return this.properties.domain + this.properties.baseLink +"/dashboard/" + stakeholder.alias;
|
2020-06-05 14:56:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public goToPage(data: any) {
|
2019-07-30 15:26:31 +02:00
|
|
|
if (data.value == true) {
|
|
|
|
let url = '';
|
2020-06-05 14:56:28 +02:00
|
|
|
if (this.type === 'stakeholder') {
|
|
|
|
url = this.getStakeholderPageUrl(this.selected);
|
|
|
|
} else if (this.type === 'community') {
|
|
|
|
url = this.getCommunityPageUrl(this.selected);
|
2019-07-30 15:26:31 +02:00
|
|
|
}
|
2020-06-05 14:56:28 +02:00
|
|
|
this.localStorageService.setCommunityDirectLink(data.choice);
|
2019-07-30 15:26:31 +02:00
|
|
|
window.open(url, '_blank');
|
2019-04-05 19:21:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|