1 |
61381
|
k.triantaf
|
import {Component, Input} from '@angular/core';
|
2 |
|
|
import {ActivatedRoute} from '@angular/router';
|
3 |
|
|
|
4 |
|
|
import {FetchProjects} from '../../utils/fetchEntitiesClasses/fetchProjects.class';
|
5 |
|
|
import {SearchProjectsService} from '../../services/searchProjects.service';
|
6 |
|
|
|
7 |
|
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
8 |
|
|
import {StringUtils} from '../../utils/string-utils.class';
|
9 |
|
|
import {RouterHelper} from '../../utils/routerHelper.class';
|
10 |
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
11 |
|
|
import {AlertModal} from "../../utils/modal/alert";
|
12 |
|
|
|
13 |
|
|
@Component({
|
14 |
|
|
selector: 'projectsInModal',
|
15 |
|
|
template: `
|
16 |
|
|
<div *ngIf="fetchProjects.funders.length > 1" class="uk-margin-bottom">
|
17 |
|
|
<div class="uk-margin-small-bottom uk-text-muted">Filter by Funder:</div>
|
18 |
|
|
<ul class="uk-list uk-list-divider uk-margin-remove">
|
19 |
|
|
<li *ngFor="let filter of fetchProjects.filters ">
|
20 |
|
|
<span *ngFor="let value of filter.values" class="uk-animation-fade uk-margin-small-right">
|
21 |
|
|
<input [(ngModel)]="value.selected" type="checkbox"
|
22 |
|
|
(ngModelChange)="filterChange(value.selected)"/>
|
23 |
|
|
<span class="uk-text-bold"> {{value.name}}</span>
|
24 |
|
|
</span>
|
25 |
|
|
</li>
|
26 |
|
|
</ul>
|
27 |
|
|
</div>
|
28 |
|
|
<errorMessages [status]="[fetchProjects.searchUtils.status]" [type]="'projects'"
|
29 |
|
|
tab_error_class=true></errorMessages>
|
30 |
|
|
<div *ngIf="fetchProjects.searchUtils.status == errorCodes.DONE">
|
31 |
|
|
<no-load-paging *ngIf="fetchProjects.searchUtils.totalResults > size" [type]="'projects'"
|
32 |
|
|
(pageChange)="pageChange($event)"
|
33 |
|
|
[page]="page" [pageSize]="size"
|
34 |
|
|
[totalResults]="fetchProjects.searchUtils.totalResults">
|
35 |
|
|
</no-load-paging>
|
36 |
|
|
<search-result [results]="fetchProjects.results"
|
37 |
|
|
[status]="fetchProjects.searchUtils.status"
|
38 |
|
|
[type]="'project'"
|
39 |
|
|
[showLoading]="true" [properties]="properties">
|
40 |
|
|
</search-result>
|
41 |
|
|
<no-load-paging *ngIf="fetchProjects.searchUtils.totalResults > size" [type]="'projects'"
|
42 |
|
|
(pageChange)="pageChange($event)"
|
43 |
|
|
[page]="page" [pageSize]="size"
|
44 |
|
|
[totalResults]="fetchProjects.searchUtils.totalResults">
|
45 |
|
|
</no-load-paging>
|
46 |
|
|
</div>
|
47 |
|
|
`
|
48 |
|
|
})
|
49 |
|
|
|
50 |
|
|
export class ProjectsInModalComponent {
|
51 |
|
|
@Input() fetchProjects: FetchProjects;
|
52 |
|
|
@Input() organizationId: string = "";
|
53 |
|
|
@Input() properties: EnvProperties;
|
54 |
|
|
@Input() modal: AlertModal;
|
55 |
|
|
public page: number = 1;
|
56 |
|
|
public size: number = 5;
|
57 |
|
|
|
58 |
|
|
public routerHelper: RouterHelper = new RouterHelper();
|
59 |
|
|
public errorCodes: ErrorCodes = new ErrorCodes();
|
60 |
|
|
|
61 |
|
|
private filterQuery: string = "";
|
62 |
|
|
|
63 |
|
|
constructor(private route: ActivatedRoute,
|
64 |
|
|
private _searchProjectsService: SearchProjectsService) {
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
ngOnInit() {
|
69 |
|
|
if (this.organizationId) {
|
70 |
|
|
if (this.fetchProjects.searchUtils.totalResults > 0) {
|
71 |
|
|
this.search(false, "");
|
72 |
|
|
}
|
73 |
|
|
}
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
private search(refine: boolean, filterQuery: string) {
|
77 |
|
|
var refineFields: string [] = ["funder"];
|
78 |
|
|
this.fetchProjects.getResultsForOrganizations(this.organizationId, filterQuery, this.page, this.size, (refine) ? refineFields : [], this.properties);
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
public pageChange($event) {
|
82 |
|
|
this.page = $event.value;
|
83 |
|
|
this.search(false, this.filterQuery);
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
public filterChange($event) {
|
87 |
|
|
this.updateFilters();
|
88 |
|
|
//this.search(true, this.filterQuery);
|
89 |
|
|
this.search(false, this.filterQuery);
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
private updateFilters() {
|
93 |
|
|
this.filterQuery = "";
|
94 |
|
|
for (let filter of this.fetchProjects.filters) {
|
95 |
|
|
var filterLimits = "";
|
96 |
|
|
for (let value of filter.values) {
|
97 |
|
|
if (value.selected == true) {
|
98 |
|
|
//filterLimits+=((filterLimits.length == 0)?'':',') +'"'+ StringUtils.URIEncode(value.id)+'"';
|
99 |
|
|
filterLimits += ((filterLimits.length == 0) ? '' : ' or ') + filter.filterId + ' exact ';
|
100 |
|
|
filterLimits += '"' + StringUtils.URIEncode(value.id) + '"';
|
101 |
|
|
}
|
102 |
|
|
}
|
103 |
|
|
if (filterLimits.length > 0) {
|
104 |
|
|
//this.filterQuery+=' and '+filter.filterId + ' exact '+ filterLimits + ' ';
|
105 |
|
|
this.filterQuery += ' and ( ' + filterLimits + ' ) ';
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
}
|
109 |
|
|
//console.log("Filter Changed"+this.filterQuery);
|
110 |
|
|
|
111 |
|
|
}
|
112 |
|
|
}
|