2020-03-16 14:09:46 +01:00
|
|
|
import {Component, Input} from '@angular/core';
|
|
|
|
import {ActivatedRoute} from '@angular/router';
|
|
|
|
|
|
|
|
import {FetchProjects} from '../../utils/fetchEntitiesClasses/fetchProjects.class';
|
|
|
|
import {SearchProjectsService} from '../../services/searchProjects.service';
|
|
|
|
|
|
|
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
|
|
|
import {StringUtils} from '../../utils/string-utils.class';
|
|
|
|
import {RouterHelper} from '../../utils/routerHelper.class';
|
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
|
|
|
import {AlertModal} from "../../utils/modal/alert";
|
2022-05-04 11:47:51 +02:00
|
|
|
import {OpenaireEntities} from '../../utils/properties/searchFields';
|
2020-03-16 14:09:46 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'projectsInModal',
|
|
|
|
template: `
|
2022-05-04 11:47:51 +02:00
|
|
|
<div *ngIf="fetchProjects.funders.length > 1" class="uk-margin-medium-bottom">
|
|
|
|
<div class="uk-margin-small-bottom uk-text-meta">Filter by Funder:</div>
|
2020-05-26 17:42:02 +02:00
|
|
|
<ul class="uk-list uk-list-divider uk-margin-remove">
|
|
|
|
<li *ngFor="let filter of fetchProjects.filters ">
|
2021-08-10 12:46:33 +02:00
|
|
|
<label *ngFor="let value of filter.values" class="uk-animation-fade uk-margin-small-right">
|
2020-05-26 17:42:02 +02:00
|
|
|
<input [(ngModel)]="value.selected" type="checkbox"
|
2022-05-04 11:47:51 +02:00
|
|
|
(ngModelChange)="filterChange(value.selected)"
|
|
|
|
class="uk-checkbox"/>
|
2020-05-26 17:42:02 +02:00
|
|
|
<span class="uk-text-bold"> {{value.name}}</span>
|
2021-08-10 12:46:33 +02:00
|
|
|
</label>
|
2020-05-26 17:42:02 +02:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2020-03-20 15:52:34 +01:00
|
|
|
<errorMessages [status]="[fetchProjects.searchUtils.status]" [type]="'projects'"
|
|
|
|
tab_error_class=true></errorMessages>
|
|
|
|
<div *ngIf="fetchProjects.searchUtils.status == errorCodes.DONE">
|
2022-05-04 11:47:51 +02:00
|
|
|
<results-and-pages *ngIf="fetchProjects.searchUtils.totalResults > size" [type]="openaireEntities.PROJECTS"
|
|
|
|
[page]="page" [pageSize]="size"
|
|
|
|
[totalResults]="fetchProjects.searchUtils.totalResults">
|
|
|
|
</results-and-pages>
|
2020-05-26 17:42:02 +02:00
|
|
|
<search-result [results]="fetchProjects.results"
|
|
|
|
[status]="fetchProjects.searchUtils.status"
|
|
|
|
[type]="'project'"
|
|
|
|
[showLoading]="true" [properties]="properties">
|
|
|
|
</search-result>
|
2022-05-04 11:47:51 +02:00
|
|
|
<paging-no-load *ngIf="fetchProjects.searchUtils.totalResults > size"
|
|
|
|
(pageChange)="pageChange($event)"
|
|
|
|
[currentPage]="page"
|
|
|
|
[size]="size"
|
|
|
|
[totalResults]="fetchProjects.searchUtils.totalResults">
|
|
|
|
</paging-no-load>
|
2020-03-16 14:09:46 +01:00
|
|
|
</div>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
|
|
|
|
export class ProjectsInModalComponent {
|
|
|
|
@Input() fetchProjects: FetchProjects;
|
|
|
|
@Input() organizationId: string = "";
|
|
|
|
@Input() properties: EnvProperties;
|
|
|
|
@Input() modal: AlertModal;
|
|
|
|
public page: number = 1;
|
2020-05-27 12:47:40 +02:00
|
|
|
public size: number = 5;
|
2020-03-16 14:09:46 +01:00
|
|
|
|
|
|
|
public routerHelper: RouterHelper = new RouterHelper();
|
|
|
|
public errorCodes: ErrorCodes = new ErrorCodes();
|
|
|
|
|
|
|
|
private filterQuery: string = "";
|
2022-05-04 11:47:51 +02:00
|
|
|
|
|
|
|
public openaireEntities = OpenaireEntities;
|
2020-03-16 14:09:46 +01:00
|
|
|
|
|
|
|
constructor(private route: ActivatedRoute,
|
|
|
|
private _searchProjectsService: SearchProjectsService) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
if (this.organizationId) {
|
|
|
|
if (this.fetchProjects.searchUtils.totalResults > 0) {
|
|
|
|
this.search(false, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private search(refine: boolean, filterQuery: string) {
|
|
|
|
var refineFields: string [] = ["funder"];
|
|
|
|
this.fetchProjects.getResultsForOrganizations(this.organizationId, filterQuery, this.page, this.size, (refine) ? refineFields : [], this.properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
public pageChange($event) {
|
|
|
|
this.page = $event.value;
|
|
|
|
this.search(false, this.filterQuery);
|
|
|
|
}
|
|
|
|
|
|
|
|
public filterChange($event) {
|
|
|
|
this.updateFilters();
|
|
|
|
//this.search(true, this.filterQuery);
|
|
|
|
this.search(false, this.filterQuery);
|
|
|
|
}
|
|
|
|
|
|
|
|
private updateFilters() {
|
|
|
|
this.filterQuery = "";
|
|
|
|
for (let filter of this.fetchProjects.filters) {
|
|
|
|
var filterLimits = "";
|
|
|
|
for (let value of filter.values) {
|
|
|
|
if (value.selected == true) {
|
|
|
|
//filterLimits+=((filterLimits.length == 0)?'':',') +'"'+ StringUtils.URIEncode(value.id)+'"';
|
|
|
|
filterLimits += ((filterLimits.length == 0) ? '' : ' or ') + filter.filterId + ' exact ';
|
|
|
|
filterLimits += '"' + StringUtils.URIEncode(value.id) + '"';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (filterLimits.length > 0) {
|
|
|
|
//this.filterQuery+=' and '+filter.filterId + ' exact '+ filterLimits + ' ';
|
|
|
|
this.filterQuery += ' and ( ' + filterLimits + ' ) ';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
//console.log("Filter Changed"+this.filterQuery);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|