2017-12-19 13:53: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';
|
|
|
|
|
2018-02-15 11:36:12 +01:00
|
|
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {StringUtils} from '../../utils/string-utils.class';
|
|
|
|
import {RouterHelper} from '../../utils/routerHelper.class';
|
2018-02-05 14:14:59 +01:00
|
|
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'searchingProjectsTab',
|
|
|
|
template: `
|
2018-06-08 13:21:42 +02:00
|
|
|
<errorMessages [status]="[fetchProjects.searchUtils.status]" [type]="'projects'" tab_error_class=true></errorMessages>
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-06-11 01:25:33 +02:00
|
|
|
<div *ngIf="fetchProjects.searchUtils.status == errorCodes.DONE">
|
2017-12-19 13:53:46 +01:00
|
|
|
<div class = "uk-text-right" *ngIf = "fetchProjects.searchUtils.totalResultsNoFilters > 10">
|
2018-07-05 12:52:42 +02:00
|
|
|
<a [queryParams]="routerHelper.createQueryParams(['organization', 'og'], [organizationId, 'and'])"
|
2017-12-19 13:53:46 +01:00
|
|
|
routerLinkActive="router-link-active" [routerLink]="linkToSearchProjects" class="uk-button uk-button-text">
|
2018-05-18 14:47:26 +02:00
|
|
|
View all {{fetchProjects.searchUtils.totalResultsNoFilters | number}} results
|
2017-12-19 13:53:46 +01:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<div class= "searchPaging uk-panel uk-margin-top">
|
|
|
|
<div class="uk-clearfix">
|
|
|
|
<div class="uk-float-right" *ngIf="fetchProjects.results && fetchProjects.searchUtils.totalResults > fetchProjects.searchUtils.size">
|
|
|
|
<paging-no-load [currentPage]="page" [totalResults]="fetchProjects.searchUtils.totalResults" [term]="keyword" [size]="size" (pageChange)="pageChange($event)"> </paging-no-load>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<ul *ngIf = "fetchProjects.funders.length > 1" class="uk-list uk-list-divider uk-margin-remove">
|
|
|
|
<li *ngFor="let filter of fetchProjects.filters " >
|
|
|
|
<!--div class="text-bold">Filter by {{filter.title}}:</div-->
|
|
|
|
<span *ngFor = "let value of filter.values" class = "uk-animation-fade">
|
|
|
|
<input [(ngModel)]="value.selected" type="checkbox" (ngModelChange)="filterChange(value.selected)" />
|
2018-05-18 14:47:26 +02:00
|
|
|
<span title = "{{value.name}}"> {{value.name}}</span><span *ngIf = "showResultCount === true" > ({{value.number | number}})</span>
|
2017-12-19 13:53:46 +01:00
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
|
2018-05-18 14:47:26 +02:00
|
|
|
<li *ngIf = "fetchProjects.searchUtils.totalResults !=fetchProjects.searchUtils.totalResultsNoFilters "> Filtered {{fetchProjects.searchUtils.totalResults | number}} results of {{fetchProjects.searchUtils.totalResultsNoFilters | number}} total results</li>
|
2017-12-19 13:53:46 +01:00
|
|
|
<li></li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<tab-result [(results)]="fetchProjects.results" [(status)]= "fetchProjects.searchUtils.status"
|
|
|
|
type="project" urlParam="projectId" [showLoading] = true [showOrganizations] = false>
|
|
|
|
</tab-result>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
|
|
|
|
export class SearchingProjectsTabComponent {
|
|
|
|
@Input() fetchProjects : FetchProjects;
|
|
|
|
@Input() organizationId:string = "";
|
2018-02-05 14:14:59 +01:00
|
|
|
@Input() properties:EnvProperties;
|
2017-12-19 13:53:46 +01:00
|
|
|
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) {
|
2018-02-05 14:14:59 +01:00
|
|
|
this.linkToSearchProjects = this.properties.searchLinkToAdvancedPublications;//+"?organization="+this.organizationId+"or=and";;
|
2017-12-19 13:53:46 +01:00
|
|
|
if(this.fetchProjects.searchUtils.totalResults > 0) {
|
|
|
|
this.search(false,"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private search(refine:boolean, filterQuery:string){
|
|
|
|
var refineFields:string [] = ["funder"];
|
2018-02-05 14:14:59 +01:00
|
|
|
this.fetchProjects.getResultsForOrganizations(this.organizationId, filterQuery, this.page, this.size,(refine)?refineFields:[], this.properties);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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 + ' ) ';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.log("Filter Changed"+this.filterQuery);
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|