2021-11-12 13:07:55 +01:00
|
|
|
import {Component, Input, OnInit, 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";
|
2021-10-19 14:20:30 +02:00
|
|
|
import {Stakeholder, StakeholderInfo, Visibility} from "../../monitor/entities/stakeholder";
|
2022-06-09 10:21:25 +02:00
|
|
|
import {StringUtils} from '../../utils/string-utils.class';
|
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;
|
|
|
|
@ViewChild('AlertModal') modal;
|
2021-10-19 14:20:30 +02:00
|
|
|
visibilityIcon: Map<Visibility, string> = new Map<Visibility, string> ([
|
2022-02-16 17:18:12 +01:00
|
|
|
["PRIVATE", 'incognito'],
|
2022-02-22 23:37:18 +01:00
|
|
|
["RESTRICTED", 'restricted']
|
2021-10-19 14:20:30 +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
|
|
|
}
|
2021-10-05 17:12:19 +02:00
|
|
|
|
2022-01-20 10:19:44 +01:00
|
|
|
mapType(type: string) {
|
2022-06-09 10:21:25 +02:00
|
|
|
if(type === 'community') {
|
|
|
|
return 'Research Community';
|
|
|
|
} else {
|
|
|
|
return StringUtils.getStakeholderType(type, false);
|
|
|
|
}
|
2022-01-20 10:19:44 +01:00
|
|
|
}
|
|
|
|
|
2021-10-05 17:12:19 +02:00
|
|
|
hasPermission(result: CommunityInfo & StakeholderInfo) {
|
2021-11-03 16:44:12 +01:00
|
|
|
if(this.type === "community") {
|
|
|
|
return result.status === "all" || (result.status === "manager" && result.isManager);
|
|
|
|
} else if(this.type === "stakeholder") {
|
|
|
|
return result.visibility === "PUBLIC" || (result.visibility === "RESTRICTED" && (result.isManager || result.isMember)) ||
|
2022-02-16 17:18:12 +01:00
|
|
|
(result.visibility === "PRIVATE" && result.isManager);
|
2021-11-03 16:44:12 +01:00
|
|
|
}
|
2021-10-05 17:12:19 +02:00
|
|
|
}
|
2020-06-05 14:56:28 +02:00
|
|
|
|
2021-11-03 16:44:12 +01:00
|
|
|
getEnvironmentPrefix(): 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";
|
2019-04-05 19:21:23 +02:00
|
|
|
}
|
2020-06-05 14:56:28 +02:00
|
|
|
|
|
|
|
public confirmModalOpen(result: CommunityInfo & Stakeholder) {
|
|
|
|
this.selected = result;
|
|
|
|
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';
|
|
|
|
}
|
2022-06-20 15:17:26 +02:00
|
|
|
this.modal.message = 'You will be navigated to a new tab. Are you sure that you want to proceed?';
|
2019-07-30 15:26:31 +02:00
|
|
|
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-07-30 15:26:31 +02:00
|
|
|
if (this.isProduction()) {
|
2022-01-20 10:19:44 +01:00
|
|
|
return 'https://' + this.getEnvironmentPrefix() + communityInfo.communityId + '.openaire.eu';
|
2019-04-05 19:21:23 +02:00
|
|
|
} else {
|
2022-01-20 10:19:44 +01:00
|
|
|
return this.router.createUrlTree(['/'], {
|
2020-06-05 14:56:28 +02:00
|
|
|
queryParams: {'communityId': communityInfo.communityId}
|
2019-07-30 15:26:31 +02:00
|
|
|
}).toString();
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|