1
|
import {Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild} from '@angular/core';
|
2
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
3
|
import {RouterHelper} from '../../utils/routerHelper.class';
|
4
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
5
|
import {CommunityInfo} from "../../connect/community/communityInfo";
|
6
|
import {Router} from "@angular/router";
|
7
|
import {LocalStorageService} from "../../services/localStorage.service";
|
8
|
import {Stakeholder, StakeholderInfo} from "../../monitor/entities/stakeholder";
|
9
|
|
10
|
@Component({
|
11
|
selector: 'portal-search-result',
|
12
|
templateUrl: 'portal-search-result.component.html'
|
13
|
})
|
14
|
|
15
|
export class PortalSearchResultComponent implements OnInit, OnChanges{
|
16
|
@Input() results: (CommunityInfo & StakeholderInfo)[];
|
17
|
@Input() status: number;
|
18
|
@Input() type: string;
|
19
|
@Input() showType = false;
|
20
|
@Input() showLoading: boolean = false;
|
21
|
@Input() custom_class: string = "search-results";
|
22
|
@Input() properties: EnvProperties;
|
23
|
@Input() maxCharacters: number = 150;
|
24
|
@ViewChild('AlertModal') modal;
|
25
|
|
26
|
|
27
|
public urlParam: string;
|
28
|
public errorCodes: ErrorCodes = new ErrorCodes();
|
29
|
public routerHelper: RouterHelper = new RouterHelper();
|
30
|
public errorMessage: string = "No results found";
|
31
|
public selected: CommunityInfo & Stakeholder;
|
32
|
public directLink: boolean = true;
|
33
|
|
34
|
|
35
|
constructor(private router: Router,
|
36
|
private localStorageService: LocalStorageService) {
|
37
|
}
|
38
|
|
39
|
ngOnInit() {
|
40
|
this.localStorageService.get().subscribe(value => {
|
41
|
this.directLink = value;
|
42
|
});
|
43
|
}
|
44
|
|
45
|
ngOnChanges(changes: SimpleChanges) {
|
46
|
console.log(changes);
|
47
|
}
|
48
|
|
49
|
getProductionPrefix(): string {
|
50
|
// return (this.properties.environment == "beta") ? "beta." : "";
|
51
|
return "beta.";
|
52
|
}
|
53
|
|
54
|
isProduction(): boolean {
|
55
|
return this.properties.environment != "development";
|
56
|
|
57
|
}
|
58
|
|
59
|
public _formatDescription(description) {
|
60
|
return (((description).length > this.maxCharacters) ? (description.substring(0, (this.maxCharacters - ('...').length)) + "...") : description);
|
61
|
}
|
62
|
|
63
|
public confirmModalOpen(result: CommunityInfo & Stakeholder) {
|
64
|
this.selected = result;
|
65
|
this.modal.cancelButton = true;
|
66
|
this.modal.okButton = true;
|
67
|
if(this.type === 'stakeholder') {
|
68
|
this.modal.alertTitle = 'You are going to visit ' + result.name + ' Monitor Dashboard';
|
69
|
} else if (this.type === 'community') {
|
70
|
this.modal.alertTitle = 'You are going to visit ' + ((result.title) ? result.title : result.shortTitle) +' Gateway';
|
71
|
}
|
72
|
this.modal.alertMessage = false;
|
73
|
this.modal.okButtonLeft = false;
|
74
|
this.modal.okButtonText = 'Yes';
|
75
|
this.modal.cancelButtonText = 'No';
|
76
|
this.modal.choice = true;
|
77
|
this.modal.open();
|
78
|
}
|
79
|
|
80
|
public getCommunityPageUrl(communityInfo: CommunityInfo): string {
|
81
|
let url = '';
|
82
|
if (this.isProduction()) {
|
83
|
url = 'https://' + this.getProductionPrefix() + communityInfo.communityId + '.openaire.eu';
|
84
|
} else {
|
85
|
url = this.router.createUrlTree(['/'], {
|
86
|
queryParams: {'communityId': communityInfo.communityId}
|
87
|
}).toString();
|
88
|
}
|
89
|
return url;
|
90
|
}
|
91
|
|
92
|
public getStakeholderPageUrl(stakeholder: Stakeholder) {
|
93
|
return this.properties.baseLink + '/dashboard/' + stakeholder.alias;
|
94
|
}
|
95
|
|
96
|
public goToPage(data: any) {
|
97
|
if (data.value == true) {
|
98
|
let url = '';
|
99
|
if (this.type === 'stakeholder') {
|
100
|
url = this.getStakeholderPageUrl(this.selected);
|
101
|
} else if (this.type === 'community') {
|
102
|
url = this.getCommunityPageUrl(this.selected);
|
103
|
}
|
104
|
this.localStorageService.setCommunityDirectLink(data.choice);
|
105
|
window.open(url, '_blank');
|
106
|
}
|
107
|
}
|
108
|
}
|