2019-07-23 14:23:12 +02:00
|
|
|
import {Component, ElementRef, EventEmitter, Input, Output} from '@angular/core';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {SearchProjectsService} from '../../services/searchProjects.service';
|
|
|
|
import {ProjectService} from '../../landingPages/project/project.service';
|
2019-07-23 14:23:12 +02:00
|
|
|
import {ClaimEntity, ClaimProject} from './claimHelper.class';
|
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
|
|
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
|
|
|
import {StringUtils} from "../../utils/string-utils.class";
|
|
|
|
import {Filter} from "../../searchPages/searchUtils/searchHelperClasses.class";
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
declare var UIkit:any;
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'claim-projects-search-form',
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
templateUrl:'claimProjectSearchForm.component.html',
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
})
|
|
|
|
export class ClaimProjectsSearchFormComponent {
|
|
|
|
ngOnInit() {
|
2019-07-23 14:23:12 +02:00
|
|
|
// this.getFunders();
|
|
|
|
// this.search(this.page, this.size);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
// @ViewChild (ModalLoading) loading : ModalLoading ;
|
|
|
|
|
|
|
|
// @Input() public inline: boolean = false ; // for claimed started from landing pages
|
|
|
|
public query = '';
|
2019-07-23 14:23:12 +02:00
|
|
|
@Input() public selectedProjects:ClaimEntity[]=[] ;
|
2017-12-19 13:53:46 +01:00
|
|
|
public elementRef;
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
// public funders:string[];
|
|
|
|
// public selectedFunderId:string ="0";
|
|
|
|
// selectedFunderName:string ="Select funder:";
|
2017-12-19 13:53:46 +01:00
|
|
|
@Output() projectSelected = new EventEmitter();
|
2018-02-05 14:14:59 +01:00
|
|
|
@Input() public properties:EnvProperties;
|
2018-07-25 15:56:02 +02:00
|
|
|
@Input() public inlineClaim:boolean=false;
|
|
|
|
@Input() localStoragePrefix:string = "";
|
2019-07-24 14:46:29 +02:00
|
|
|
@Input() basketLimit;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
2017-12-19 13:53:46 +01:00
|
|
|
public projects:string[];
|
|
|
|
public warningMessage = "";
|
2019-07-23 14:23:12 +02:00
|
|
|
openaireResults:ClaimEntity[] = [];
|
|
|
|
openaireResultsNum: number ;
|
|
|
|
openaireResultsPage : number = 1;
|
|
|
|
openaireResultsStatus:number = this.errorCodes.NONE;
|
|
|
|
page : number = 1;
|
|
|
|
size:number = 5;
|
|
|
|
keyword:string = '';
|
|
|
|
showResults = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
// public openaireRefineFields: string[] = ["relfunder", "relproject", "resultbestaccessright", "instancetypename", "resultlanguagename", "community"];
|
|
|
|
// public openaireRefineFieldsQuery: string = "&refine=true&fields=funder&fields=projectstartyear&fields=projectendyear&fields=projectecsc39";
|
|
|
|
public refineFields: string[] = ["funder"];
|
|
|
|
public refineFieldsQuery: string = "&refine=true&fields=funder";
|
|
|
|
filters = [];
|
|
|
|
prevFilters = [];
|
|
|
|
startYear = "";
|
|
|
|
endYear = "";
|
|
|
|
constructor(private _service: ProjectService, private _projectService: SearchProjectsService, myElement: ElementRef) {
|
|
|
|
this.elementRef = myElement;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
search(page,size) {
|
|
|
|
if(this.keyword.length == 0){
|
|
|
|
this.showResults =false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.showResults =true;
|
|
|
|
this.openaireResults = [];
|
|
|
|
this.openaireResultsStatus = this.errorCodes.LOADING;
|
|
|
|
this.prevFilters = this.filters;
|
|
|
|
|
|
|
|
//searchProjects (params: string, refineParams:string, page: number, size: number, refineFields:string[] , properties:EnvProperties ):any {
|
|
|
|
this._projectService.searchProjects(this.createOpenaireQueryParams(),(page==1)? this.refineFieldsQuery:null, page, size, (page==1)?this.refineFields:[], this.properties).subscribe(
|
|
|
|
data => {
|
|
|
|
if(data != null) {
|
|
|
|
this.openaireResultsPage=page;
|
|
|
|
this.openaireResultsNum = data[0];
|
2019-10-16 12:18:32 +02:00
|
|
|
this.openaireResults =ClaimProjectsSearchFormComponent.openaire2ClaimEntity(data[1], this.properties);
|
2019-07-23 14:23:12 +02:00
|
|
|
if(data[2] && data[2].length > 0){
|
|
|
|
this.filters = this.checkSelectedFilters( data[2], this.prevFilters);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.openaireResultsStatus = this.errorCodes.DONE;
|
|
|
|
if(this.openaireResultsNum == 0){
|
|
|
|
this.openaireResultsStatus = this.errorCodes.NONE;
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
this.openaireResultsStatus = this.errorCodes.ERROR;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
this.openaireResultsStatus = this.errorCodes.ERROR;
|
|
|
|
//console.log(err.status);
|
|
|
|
ClaimProjectsSearchFormComponent.handleError("Error getting projects by keyword: "+this.keyword, err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// select(entity){
|
|
|
|
// if(this.selectedProjects.length > 50){
|
|
|
|
// UIkit.notification({
|
|
|
|
// message : 'Your basket exceeds the number of allowed projects (50)',
|
|
|
|
// status : 'warning',
|
|
|
|
// timeout : 1500,
|
|
|
|
// pos : 'top-center'
|
|
|
|
// });
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// this.query = "";
|
|
|
|
// // this.searchTermStream.next(this.query); //clear
|
|
|
|
// entity = entity.value;
|
|
|
|
// // var project: ClaimProject = new ClaimProject();
|
|
|
|
// // project.funderId = entity.funderId;
|
|
|
|
// // project.funderName = entity.funderName;
|
|
|
|
// // project.id = entity.id;
|
|
|
|
// // project.projectName = entity.projectName;
|
|
|
|
// // project.projectAcronym = entity.projectAcronym;
|
|
|
|
// // project.startDate = entity.startDate;
|
|
|
|
// // project.endDate = entity.endDate;
|
|
|
|
// // project.code = entity.code;
|
|
|
|
// // project.jurisdiction = entity.jurisdiction;
|
|
|
|
// // project.fundingLevel0 = entity.fundingLevel0;
|
|
|
|
//
|
2017-12-19 13:53:46 +01:00
|
|
|
//
|
2019-07-23 14:23:12 +02:00
|
|
|
// var index:number =this.selectedProjects.indexOf(entity);
|
|
|
|
// var found:boolean = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
// this.warningMessage = "";
|
|
|
|
//
|
2019-07-23 14:23:12 +02:00
|
|
|
// for (var _i = 0; _i < this.selectedProjects.length; _i++) {
|
|
|
|
// let project = this.selectedProjects[_i];
|
|
|
|
// if(entity.id == project.id){
|
|
|
|
// found=true;
|
|
|
|
// this.warningMessage = "Project already in your basket";
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (!found) {
|
|
|
|
// this.selectedProjects.push(entity);
|
|
|
|
// if(this.selectedProjects != null){
|
|
|
|
// localStorage.setItem(this.localStoragePrefix + "projects", JSON.stringify(this.selectedProjects));
|
|
|
|
// }
|
|
|
|
// this.projectSelected.emit({
|
|
|
|
// value: true
|
|
|
|
// });
|
2017-12-19 13:53:46 +01:00
|
|
|
//
|
2019-07-23 14:23:12 +02:00
|
|
|
// }
|
2017-12-19 13:53:46 +01:00
|
|
|
// }
|
2019-07-23 14:23:12 +02:00
|
|
|
/* static showItem(item):string{
|
|
|
|
return ((item.field[1]['@value'])?item.field[1]['@value']+" - ":"" ) + item.field[3]['@value'];
|
|
|
|
}*/
|
|
|
|
remove(item){
|
|
|
|
let index:number =this.selectedProjects.indexOf(item);
|
|
|
|
if (index > -1) {
|
|
|
|
this.selectedProjects.splice(index, 1);
|
|
|
|
}
|
|
|
|
|
2018-11-12 16:36:20 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
/* handleClick(event){
|
|
|
|
var clickedComponent = event.target;
|
|
|
|
var inside = false;
|
|
|
|
do {
|
|
|
|
if (clickedComponent === this.elementRef.nativeElement) {
|
|
|
|
inside = true;
|
|
|
|
}
|
|
|
|
clickedComponent = clickedComponent.parentNode;
|
|
|
|
} while (clickedComponent);
|
|
|
|
|
|
|
|
}*/
|
2019-10-16 12:18:32 +02:00
|
|
|
static openaire2ClaimEntity(items, properties:EnvProperties){
|
2019-07-23 14:23:12 +02:00
|
|
|
const projects: ClaimEntity[] = [];
|
|
|
|
for(const item of items){
|
|
|
|
const entity: ClaimEntity = new ClaimEntity();
|
|
|
|
entity.project = new ClaimProject();
|
|
|
|
entity.project.funderId = item.funderId;
|
|
|
|
entity.project.funderName = item.funderShortname;
|
|
|
|
entity.id = item.id;
|
2019-10-16 12:18:32 +02:00
|
|
|
entity.project.url = properties.searchLinkToProject + entity.id;
|
2019-07-23 14:23:12 +02:00
|
|
|
entity.title = item.title.name;
|
|
|
|
entity.project.acronym = item.acronym;
|
|
|
|
entity.project.startDate = item.startYear;
|
|
|
|
entity.project.endDate = item.endYear;
|
|
|
|
entity.project.code = item.code;
|
|
|
|
entity.project.jurisdiction = item.jurisdiction;
|
|
|
|
entity.project.fundingLevel0 = item.fundingLevel0;
|
|
|
|
entity.type="project";
|
|
|
|
projects.push(entity);
|
|
|
|
}
|
|
|
|
return projects;
|
|
|
|
}
|
|
|
|
private openaireResultsPageChange($event) {
|
|
|
|
this.openaireResultsPage=$event.value;
|
|
|
|
this.openaireResults = [];
|
|
|
|
this.search(this.openaireResultsPage,this.size);
|
|
|
|
}
|
|
|
|
private static handleError(message: string, error) {
|
|
|
|
console.error("Claim project search form (component): "+message, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
createOpenaireQueryParams():string {
|
|
|
|
let query = "";
|
|
|
|
if(this.keyword.length > 0){
|
|
|
|
query += "q=" + StringUtils.quote(StringUtils.URIEncode(this.keyword));
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
if(this.startYear.length > 0 ){
|
|
|
|
query+='&fq=projectstartyear exact \"'+this.startYear+'\"'
|
|
|
|
}
|
|
|
|
if(this.endYear.length > 0 ){
|
|
|
|
query+='&fq=projectendyear exact \"'+this.endYear+'\"'
|
|
|
|
}
|
|
|
|
let allFqs = "";
|
|
|
|
for (let filter of this.filters){
|
|
|
|
if(filter.countSelectedValues > 0){
|
|
|
|
let count_selected=0;
|
|
|
|
let fq = "";
|
|
|
|
for (let value of filter.values){
|
|
|
|
if(value.selected == true){
|
|
|
|
count_selected++;
|
|
|
|
fq+=(fq.length > 0 ? " " + filter.filterOperator + " ":"" ) + filter.filterId + " exact " + (StringUtils.quote(value.id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(count_selected > 0){
|
|
|
|
fq="&fq="+StringUtils.URIEncode(fq);
|
|
|
|
allFqs += fq;
|
|
|
|
}
|
2018-07-25 15:56:02 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
return query+allFqs;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
public yearChanged() {
|
|
|
|
this.search(this.page, this.size);
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
filterChanged($event) {
|
|
|
|
this.search(this.page, this.size);
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
public checkSelectedFilters(filters:Filter[], prevFilters:Filter[]){
|
|
|
|
for(let i=0; i< filters.length ; i++){
|
|
|
|
let filter:Filter = filters[i];
|
|
|
|
filter.countSelectedValues = 0;
|
|
|
|
let prevFilterSelectedValues:string[] = [];
|
|
|
|
for(let j=0; j< prevFilters.length ; j++){
|
|
|
|
if(filters[i].filterId == prevFilters[j].filterId){
|
|
|
|
if(prevFilters[j].countSelectedValues >0){
|
|
|
|
for(let filterValue of prevFilters[j].values) {
|
|
|
|
if(filterValue.selected){
|
|
|
|
prevFilterSelectedValues.push(filterValue.id);
|
|
|
|
}
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(let filterValue of filter.values) {
|
|
|
|
if(prevFilterSelectedValues.indexOf(filterValue.id) > -1) {
|
|
|
|
filterValue.selected = true;
|
|
|
|
filter.countSelectedValues++;
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
return filters;
|
|
|
|
}
|
|
|
|
totalPages(totalResults: number): number {
|
|
|
|
let totalPages:any = totalResults/(this.size);
|
|
|
|
if(!(Number.isInteger(totalPages))) {
|
|
|
|
totalPages = (parseInt(totalPages, 10) + 1);
|
|
|
|
}
|
|
|
|
return totalPages;
|
2019-02-18 15:00:43 +01:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|