openaire-library/landingPages/landing-utils/projects-in-modal.component.ts

120 lines
4.7 KiB
TypeScript

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 {ResultLandingInfo} from "../../utils/entities/resultLandingInfo";
import {ResultPreview} from "../../utils/result-preview/result-preview";
import {SearchResult} from "../../utils/entities/searchResult";
import {AlertModal} from "../../utils/modal/alert";
@Component({
selector: 'projectsInModal',
template: `
<div *ngIf="fetchProjects.funders.length > 1" class="uk-margin-small-bottom">Filter by Funder:</div>
<ul *ngIf="fetchProjects.funders.length > 1" class="uk-list uk-list-divider uk-margin-remove">
<li *ngFor="let filter of fetchProjects.filters ">
<span *ngFor="let value of filter.values" class="uk-animation-fade uk-margin-small-right">
<input [(ngModel)]="value.selected" type="checkbox"
(ngModelChange)="filterChange(value.selected)"/>
<span class="uk-text-bold"> {{value.name}}</span>
</span>
</li>
</ul>
<errorMessages [status]="[fetchProjects.searchUtils.status]" [type]="'projects'"
tab_error_class=true></errorMessages>
<div *ngIf="fetchProjects.searchUtils.status == errorCodes.DONE">
<no-load-paging *ngIf="fetchProjects.searchUtils.totalResults > size" [type]="'projects'"
(pageChange)="pageChange($event)"
[page]="page" [pageSize]="size"
[totalResults]="fetchProjects.searchUtils.totalResults">
</no-load-paging>
<ul class="uk-list uk-list-divider uk-margin">
<li *ngFor="let result of fetchProjects.results">
<result-preview [properties]="properties" [modal]="modal" [result]="getResultPreview(result)"></result-preview>
</li>
</ul>
<no-load-paging *ngIf="fetchProjects.searchUtils.totalResults > size" [type]="'projects'"
(pageChange)="pageChange($event)"
[page]="page" [pageSize]="size"
[totalResults]="fetchProjects.searchUtils.totalResults">
</no-load-paging>
</div>
`
})
export class ProjectsInModalComponent {
@Input() fetchProjects: FetchProjects;
@Input() organizationId: string = "";
@Input() properties: EnvProperties;
@Input() modal: AlertModal;
public page: number = 1;
public size: number = 10;
public linkToSearchProjects: string;
public routerHelper: RouterHelper = new RouterHelper();
public errorCodes: ErrorCodes = new ErrorCodes();
private filterQuery: string = "";
constructor(private route: ActivatedRoute,
private _searchProjectsService: SearchProjectsService) {
}
ngOnInit() {
if (this.organizationId) {
this.linkToSearchProjects = this.properties.searchLinkToAdvancedProjects;//+"?organization="+this.organizationId+"or=and";;
if (this.fetchProjects.searchUtils.totalResults > 0) {
this.search(false, "");
}
}
}
public getResultPreview(result: SearchResult): ResultPreview {
return ResultPreview.searchResultConvert(result, 'project');
}
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);
}
}