1
|
import {Component, Input} from '@angular/core';
|
2
|
|
3
|
import { FetchProjects } from '../utils/fetchEntitiesClasses/fetchProjects.class';
|
4
|
import { SearchProjectsService } from '../services/searchProjects.service';
|
5
|
|
6
|
import {OpenaireProperties} from '../utils/properties/openaireProperties';
|
7
|
import {StringUtils} from '../utils/string-utils.class';
|
8
|
import {RouterHelper} from '../utils/routerHelper.class';
|
9
|
|
10
|
@Component({
|
11
|
selector: 'searchingProjectsTab',
|
12
|
template: `
|
13
|
<div *ngIf="fetchProjects.searchUtils.totalResults == 0" class = "uk-alert">
|
14
|
There are no projects
|
15
|
</div>
|
16
|
|
17
|
<div *ngIf="fetchProjects.searchUtils.totalResults > 0">
|
18
|
<p>
|
19
|
The results below are discovered through our pilot algorithms.
|
20
|
<a href="mailto:feedback@openaire.eu">Let us know how we are doing!</a>
|
21
|
</p>
|
22
|
<div class = "uk-text-right" *ngIf = "fetchProjects.totalResults > 10">
|
23
|
<!--a [href] = "linkToSearchProjects">
|
24
|
View all {{fetchProjects.totalResults}} results
|
25
|
</a-->
|
26
|
<a [queryParams]="routerHelper.createQueryParams(['organizationId', 'or'], [organizationId, 'and'])"
|
27
|
routerLinkActive="router-link-active" [routerLink]="linkToSearchProjects">
|
28
|
View all {{fetchProjects.totalResults}} results
|
29
|
</a>
|
30
|
</div>
|
31
|
<div class= "searchPaging uk-panel uk-margin-top">
|
32
|
<div class="uk-float-right" *ngIf="fetchProjects.results && fetchProjects.searchUtils.totalResults > fetchProjects.searchUtils.size">
|
33
|
<paging-no-load [currentPage]="page" [totalResults]="fetchProjects.searchUtils.totalResults" [navigateTo]="navigateTo" [term]="keyword" [size]="size" (pageChange)="pageChange($event)"> </paging-no-load>
|
34
|
</div>
|
35
|
<ul *ngIf = "fetchProjects.funders.length > 1" class="uk-list uk-list-line">
|
36
|
<li *ngFor="let filter of fetchProjects.filters " >
|
37
|
<div class="text-bold">Filter by {{filter.title}}:</div>
|
38
|
<span *ngFor = "let value of filter.values" class = "uk-animation-fade">
|
39
|
<input [(ngModel)]="value.selected" type="checkbox" (ngModelChange)="filterChange(value.selected)" />
|
40
|
<span title = "{{value.name}}"> {{value.name}}</span><span *ngIf = "showResultCount === true" > ({{value.number}})</span>
|
41
|
</span>
|
42
|
</li>
|
43
|
|
44
|
<li *ngIf = "fetchProjects.searchUtils.totalResults !=fetchProjects.totalResults "> Filtered {{fetchProjects.searchUtils.totalResults}} results of {{fetchProjects.totalResults}} total results</li>
|
45
|
<li></li>
|
46
|
</ul>
|
47
|
|
48
|
<tab-result [(results)]="fetchProjects.results" [(status)]= "fetchProjects.searchUtils.status"
|
49
|
type="project" urlParam="projectId" showLoading = true>
|
50
|
</tab-result>
|
51
|
</div>
|
52
|
`
|
53
|
})
|
54
|
|
55
|
export class SearchingProjectsTabComponent {
|
56
|
public fetchProjects : FetchProjects;
|
57
|
@Input() organizationId:string = "";
|
58
|
public page :number = 1;
|
59
|
public size :number = 10;
|
60
|
public linkToSearchProjects;
|
61
|
private filterQuery:string = "";
|
62
|
|
63
|
public routerHelper:RouterHelper = new RouterHelper();
|
64
|
|
65
|
constructor (private _searchProjectsService: SearchProjectsService) {
|
66
|
this.fetchProjects = new FetchProjects(this._searchProjectsService);
|
67
|
|
68
|
}
|
69
|
|
70
|
|
71
|
ngOnInit() {
|
72
|
this.linkToSearchProjects = OpenaireProperties.getLinkToAdvancedSearchProjects();//+"?organization="+this.organizationId+"or=and";;
|
73
|
this.search(true,"");
|
74
|
}
|
75
|
|
76
|
|
77
|
search(refine:boolean, filterQuery:string){
|
78
|
var refineFields:string [] = ["funderid"];
|
79
|
this.fetchProjects.getResultsForOrganizations(this.organizationId, filterQuery, this.page, this.size,(refine)?refineFields:[]);
|
80
|
}
|
81
|
|
82
|
pageChange($event) {
|
83
|
this.page=$event.value;
|
84
|
this.search(false, this.filterQuery);
|
85
|
}
|
86
|
|
87
|
filterChange($event) {
|
88
|
console.log("Filter Changed");
|
89
|
this.updateFilters();
|
90
|
this.search(true, this.filterQuery);
|
91
|
}
|
92
|
|
93
|
updateFilters (){
|
94
|
this.filterQuery = "";
|
95
|
for (let filter of this.fetchProjects.filters){
|
96
|
var filterLimits="";
|
97
|
for (let value of filter.values){
|
98
|
if(value.selected == true){
|
99
|
filterLimits+=((filterLimits.length == 0)?'':',') +'"'+ StringUtils.URIEncode(value.id)+'"';
|
100
|
}
|
101
|
}
|
102
|
if(filterLimits.length > 0){
|
103
|
this.filterQuery+=' and '+filter.filterId + ' exact '+ filterLimits + ' ';
|
104
|
}
|
105
|
|
106
|
}
|
107
|
console.log("Filter Changed"+this.filterQuery);
|
108
|
|
109
|
}
|
110
|
}
|