2024-05-22 13:48:13 +02:00
|
|
|
import {Component, ElementRef, EventEmitter, Input, Output, ViewChild} 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";
|
2020-05-14 16:38:50 +02:00
|
|
|
import {Filter, Value} from "../../searchPages/searchUtils/searchHelperClasses.class";
|
|
|
|
import {RangeFilter} from "../../utils/rangeFilter/rangeFilterHelperClasses.class";
|
2022-04-08 15:55:22 +02:00
|
|
|
import {OpenaireEntities, SearchFields} from "../../utils/properties/searchFields";
|
2020-05-14 16:38:50 +02:00
|
|
|
import {NewSearchPageComponent} from "../../searchPages/searchUtils/newSearchPage.component";
|
2020-11-11 15:43:13 +01:00
|
|
|
import {Subscriber} from "rxjs";
|
2024-05-22 13:48:13 +02:00
|
|
|
import { properties } from 'src/environments/environment';
|
2019-07-23 14:23:12 +02:00
|
|
|
|
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 {
|
|
|
|
public query = '';
|
2023-02-15 22:56:16 +01:00
|
|
|
@Input() public centerAlign: boolean = false;
|
2019-07-23 14:23:12 +02:00
|
|
|
@Input() public selectedProjects:ClaimEntity[]=[] ;
|
2017-12-19 13:53:46 +01:00
|
|
|
public elementRef;
|
|
|
|
|
|
|
|
@Output() projectSelected = new EventEmitter();
|
2024-05-22 13:48:13 +02:00
|
|
|
public properties:EnvProperties = properties;
|
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;
|
2022-03-16 17:54:22 +01:00
|
|
|
@Input() showOptions;
|
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[] = [];
|
2024-06-19 11:14:15 +02:00
|
|
|
openaireResultsNum: number = -1;
|
2019-07-23 14:23:12 +02:00
|
|
|
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 refineFields: string[] = ["funder"];
|
|
|
|
public refineFieldsQuery: string = "&refine=true&fields=funder";
|
|
|
|
filters = [];
|
|
|
|
prevFilters = [];
|
2020-05-14 16:38:50 +02:00
|
|
|
public rangeFilters: RangeFilter[] = [];
|
|
|
|
public searchFields: SearchFields = new SearchFields();
|
|
|
|
public rangeFields:string[][] = this.searchFields.PROJECT_RANGE_FIELDS;
|
2022-04-08 15:55:22 +02:00
|
|
|
openaireEntities = OpenaireEntities;
|
|
|
|
sub;
|
2024-05-22 13:48:13 +02:00
|
|
|
|
|
|
|
selectedFunder = null;
|
|
|
|
funderOptions = [];
|
|
|
|
isNoProjectFunder = false;
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
constructor(private _service: ProjectService, private _projectService: SearchProjectsService, myElement: ElementRef) {
|
|
|
|
this.elementRef = myElement;
|
2024-05-22 13:48:13 +02:00
|
|
|
this.rangeFilters = RangeFilter.parse(this.rangeFields,"project");
|
|
|
|
this.getFunders();
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
if (this.sub instanceof Subscriber) {
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
2024-05-22 13:48:13 +02:00
|
|
|
getFunders(){
|
|
|
|
this.openaireResultsStatus = this.errorCodes.LOADING;
|
|
|
|
this.showResults = true;
|
|
|
|
this.sub = this._projectService.advancedSearchProjects("", 1, 0, this.properties,
|
2024-07-05 15:00:36 +02:00
|
|
|
this.refineFieldsQuery, this.refineFields, "&type=projects&sf=funder", false, false).subscribe(
|
2024-05-22 13:48:13 +02:00
|
|
|
data => {
|
2024-05-28 11:09:21 +02:00
|
|
|
let option = {value : null, label: "No funder selected"};
|
|
|
|
this.funderOptions.push(option);
|
2024-05-22 13:48:13 +02:00
|
|
|
for(let v of data[2][0].values){
|
|
|
|
let option = {value : v, label: v.name};
|
|
|
|
this.funderOptions.push(option);
|
|
|
|
}
|
|
|
|
this.openaireResultsStatus = this.errorCodes.DONE;
|
|
|
|
}, error =>{
|
|
|
|
this.openaireResultsStatus = this.errorCodes.ERROR;
|
|
|
|
})
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2024-05-22 13:48:13 +02:00
|
|
|
funderChanged(value){
|
|
|
|
this.keyword = ""
|
|
|
|
this.selectedFunder = value;
|
|
|
|
this.isNoProjectFunder = this.selectedFunder && this.selectedFunder.number == 1;
|
|
|
|
this.openaireResults = [];
|
2024-06-19 11:14:15 +02:00
|
|
|
this.openaireResultsNum = -1;
|
2024-05-22 13:48:13 +02:00
|
|
|
if(this.isNoProjectFunder){
|
|
|
|
this.showResults = true;
|
|
|
|
this.search(1,1);
|
|
|
|
}else{
|
|
|
|
this.openaireResults = [];
|
|
|
|
}
|
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
search(page,size) {
|
2024-05-22 13:48:13 +02:00
|
|
|
/* if (this.keyword.length == 0) {
|
2024-04-12 10:19:17 +02:00
|
|
|
this.showResults = false;
|
2019-07-23 14:23:12 +02:00
|
|
|
return;
|
2024-05-22 13:48:13 +02:00
|
|
|
}*/
|
2024-04-12 10:19:17 +02:00
|
|
|
this.showResults = true;
|
2019-07-23 14:23:12 +02:00
|
|
|
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 {
|
2024-07-05 15:00:36 +02:00
|
|
|
this.sub = this._projectService.advancedSearchProjects(this.createOpenaireQueryParams(), page, size, this.properties, this.createOpenaireRefineQuery(), [], null, false, false).subscribe(
|
2024-04-12 10:19:17 +02:00
|
|
|
// this.sub = this._projectService.searchProjects(this.createOpenaireQueryParams(),(page==1)? this.refineFieldsQuery:null, page, size, (page==1)?this.refineFields:[], this.properties).subscribe(
|
2019-07-23 14:23:12 +02:00
|
|
|
data => {
|
2024-04-12 10:19:17 +02:00
|
|
|
if (data != null) {
|
|
|
|
this.openaireResultsPage = page;
|
|
|
|
this.openaireResultsNum = data[0];
|
|
|
|
this.openaireResults = ClaimProjectsSearchFormComponent.openaire2ClaimEntity(data[1], this.properties);
|
|
|
|
if (data[2] && data[2].length > 0) {
|
|
|
|
this.filters = this.checkSelectedFilters(data[2], this.prevFilters);
|
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
|
2024-04-12 10:19:17 +02:00
|
|
|
this.openaireResultsStatus = this.errorCodes.DONE;
|
|
|
|
if (this.openaireResultsNum == 0) {
|
|
|
|
this.openaireResultsStatus = this.errorCodes.NONE;
|
|
|
|
this.filters = this.checkSelectedFilters([], this.prevFilters);
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2024-05-22 13:48:13 +02:00
|
|
|
/* if(this.isNoProjectFunder && this.claimResultsComponent){
|
|
|
|
this.claimResultsComponent.add(this.openaireResults[0])
|
|
|
|
}*/
|
2024-04-12 10:19:17 +02:00
|
|
|
} else {
|
|
|
|
this.openaireResultsStatus = this.errorCodes.ERROR;
|
|
|
|
}
|
|
|
|
},
|
2019-07-23 14:23:12 +02:00
|
|
|
err => {
|
|
|
|
this.openaireResultsStatus = this.errorCodes.ERROR;
|
|
|
|
//console.log(err.status);
|
|
|
|
ClaimProjectsSearchFormComponent.handleError("Error getting projects by keyword: "+this.keyword, err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2024-05-22 13:48:13 +02:00
|
|
|
remove(item){
|
2019-07-23 14:23:12 +02:00
|
|
|
let index:number =this.selectedProjects.indexOf(item);
|
|
|
|
if (index > -1) {
|
|
|
|
this.selectedProjects.splice(index, 1);
|
|
|
|
}
|
|
|
|
|
2018-11-12 16:36:20 +01:00
|
|
|
}
|
2024-05-22 13:48:13 +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;
|
2024-05-28 11:09:21 +02:00
|
|
|
entity.project.funderShortname = item.funderShortname?item.funderShortname:(entity.project.funderId?entity.project.funderId.split("::")[1]:"");
|
2024-04-19 11:09:00 +02:00
|
|
|
entity.project.funderName = item.funderName;
|
2019-07-23 14:23:12 +02:00
|
|
|
entity.id = item.id;
|
2024-04-19 11:09:00 +02:00
|
|
|
entity.project.url = (item.code !="unidentified") ? properties.searchLinkToProject + entity.id : null;
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 10:19:17 +02:00
|
|
|
createOpenaireQueryParams(): string {
|
2019-07-23 14:23:12 +02:00
|
|
|
let query = "";
|
2024-04-12 10:19:17 +02:00
|
|
|
if (this.keyword.length > 0) {
|
|
|
|
// query += "q=" + StringUtils.quote(StringUtils.URIEncode(this.keyword));
|
|
|
|
query += StringUtils.quote(StringUtils.URIEncode(this.keyword));
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2024-04-12 10:19:17 +02:00
|
|
|
return query;
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2024-04-12 10:19:17 +02:00
|
|
|
createOpenaireRefineQuery(): string {
|
2019-07-23 14:23:12 +02:00
|
|
|
let allFqs = "";
|
2024-04-12 10:19:17 +02:00
|
|
|
for (let filter of this.filters) {
|
|
|
|
if (filter.countSelectedValues > 0) {
|
|
|
|
let count_selected = 0;
|
2019-07-23 14:23:12 +02:00
|
|
|
let fq = "";
|
2024-04-12 10:19:17 +02:00
|
|
|
for (let value of filter.values) {
|
|
|
|
if (value.selected == true) {
|
2019-07-23 14:23:12 +02:00
|
|
|
count_selected++;
|
2024-04-12 10:19:17 +02:00
|
|
|
fq += (fq.length > 0 ? " " + filter.filterOperator + " " : "") + filter.filterId + " exact " + (StringUtils.quote(value.id));
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
}
|
2024-04-12 10:19:17 +02:00
|
|
|
if (count_selected > 0) {
|
|
|
|
fq = "&fq=" + StringUtils.URIEncode(fq);
|
2019-07-23 14:23:12 +02:00
|
|
|
allFqs += fq;
|
|
|
|
}
|
2018-07-25 15:56:02 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2024-05-28 11:09:21 +02:00
|
|
|
if(this.selectedFunder){
|
|
|
|
allFqs += "&fq=" + StringUtils.URIEncode( "funder exact " + (StringUtils.quote(this.selectedFunder.id)));
|
|
|
|
}
|
|
|
|
if(!this.isNoProjectFunder || !this.selectedFunder){
|
|
|
|
allFqs += '&fq=(projectcode<>"unidentified")'
|
2024-05-22 13:48:13 +02:00
|
|
|
}
|
2024-04-12 10:19:17 +02:00
|
|
|
for (let i = 0; i < this.rangeFilters.length; i++) {
|
2020-05-14 16:38:50 +02:00
|
|
|
let filter = this.rangeFilters[i];
|
|
|
|
//selectedFromValue, selectedToValue, equalityOp, equalityOpFrom, equalityOpTo, filterOp ){
|
2024-04-12 10:19:17 +02:00
|
|
|
allFqs += NewSearchPageComponent.createRangeFilterQuery(this.rangeFields[i], filter.selectedFromValue, filter.selectedToValue, " within ", ">=", "<=", "and")
|
2020-05-14 16:38:50 +02:00
|
|
|
}
|
2024-04-12 10:19:17 +02:00
|
|
|
return allFqs + "&type=projects";
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2024-04-12 10:19:17 +02: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
|
|
|
}
|
2024-04-12 10:19:17 +02:00
|
|
|
filter.countAllValues = filter.values.length;
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2022-06-28 12:19:08 +02:00
|
|
|
if(filters.length == 0 ){
|
2024-04-12 10:19:17 +02:00
|
|
|
for(let j=0; j< prevFilters.length ; j++) {
|
|
|
|
let filter = Object.assign({}, prevFilters[j]);
|
|
|
|
filter.values = [];
|
|
|
|
for (let filterValue of prevFilters[j].values) {
|
|
|
|
if (filterValue.selected) {
|
|
|
|
filterValue.number = 0;
|
|
|
|
filter.values.push(filterValue);
|
2022-06-28 12:19:08 +02:00
|
|
|
}
|
2024-04-12 10:19:17 +02:00
|
|
|
}
|
|
|
|
filter.countAllValues = filter.values.length;
|
|
|
|
filters.push(filter)
|
|
|
|
}
|
2022-06-28 12:19:08 +02: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
|
|
|
}
|
2020-05-14 16:38:50 +02:00
|
|
|
|
|
|
|
getSelectedValues(filter): any {
|
|
|
|
var selected = [];
|
|
|
|
if (filter.countSelectedValues > 0) {
|
|
|
|
for (var i = 0; i < filter.values.length; i++) {
|
|
|
|
if (filter.values[i].selected) {
|
|
|
|
selected.push(filter.values[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return selected;
|
|
|
|
|
|
|
|
}
|
|
|
|
dateFilterChanged(filter:RangeFilter) {
|
|
|
|
if (filter.selectedFromValue && filter.selectedToValue) {
|
|
|
|
filter.selectedFromAndToValues = filter.selectedFromValue + "-" + filter.selectedToValue;
|
|
|
|
} else if (filter.selectedFromValue) {
|
|
|
|
filter.selectedFromAndToValues = "From " + filter.selectedFromValue;
|
|
|
|
} else if (filter.selectedToValue) {
|
|
|
|
filter.selectedFromAndToValues = "Until " + filter.selectedToValue;
|
|
|
|
}
|
|
|
|
this.filterChanged(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
private removeFilter(value: Value, filter: Filter) {
|
|
|
|
filter.countSelectedValues--;
|
|
|
|
if (value.selected == true) {
|
|
|
|
value.selected = false;
|
|
|
|
}
|
|
|
|
// this.search(false);
|
|
|
|
this.filterChanged(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public countFilters(): number {
|
|
|
|
let filters = 0;
|
|
|
|
for (let filter of this.filters) {
|
|
|
|
if (filter.countSelectedValues > 0) {
|
|
|
|
filters += filter.countSelectedValues;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (let filter of this.rangeFilters) {
|
|
|
|
if (filter.selectedFromValue || filter.selectedToValue) {
|
|
|
|
filters += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filters;
|
|
|
|
}
|
|
|
|
|
|
|
|
private clearFilters() {
|
|
|
|
for (let i = 0; i < this.filters.length; i++) {
|
|
|
|
for (let j = 0; j < this.filters[i].countSelectedValues; j++) {
|
|
|
|
if (this.filters[i].values[j].selected) {
|
|
|
|
this.filters[i].values[j].selected = false;
|
|
|
|
}
|
|
|
|
this.filters[i].countSelectedValues = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(let filter of this.rangeFilters){
|
|
|
|
this.removeRangeFilter(filter);
|
|
|
|
}
|
|
|
|
this.filterChanged(null);
|
|
|
|
}
|
|
|
|
public removeRangeFilter(filter: RangeFilter) {
|
|
|
|
filter.selectedFromValue = null;
|
|
|
|
filter.selectedToValue = null;
|
|
|
|
filter.selectedFromAndToValues = null;
|
|
|
|
this.filterChanged(null);
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|