2020-11-12 16:59:26 +01:00
|
|
|
import {Component, ViewChild} from '@angular/core';
|
2021-03-08 16:40:49 +01:00
|
|
|
import {ActivatedRoute} from '@angular/router';
|
|
|
|
import {AdvancedField, Filter, Value} from '../../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class';
|
2018-03-01 12:55:49 +01:00
|
|
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
2021-03-08 16:40:49 +01:00
|
|
|
import {ErrorMessagesComponent} from '../../openaireLibrary/utils/errorMessages.component';
|
2020-11-12 16:59:26 +01:00
|
|
|
import {SearchFields} from '../../openaireLibrary/utils/properties/searchFields';
|
2020-04-03 18:02:40 +02:00
|
|
|
import {SearchCustomFilter, SearchUtilsClass} from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class';
|
2018-03-01 12:55:49 +01:00
|
|
|
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
2018-04-04 14:31:14 +02:00
|
|
|
import {SearchCommunityProjectsService} from '../../openaireLibrary/connect/projects/searchProjects.service';
|
2020-11-12 16:59:26 +01:00
|
|
|
import {properties} from "../../../environments/environment";
|
2020-11-30 18:04:05 +01:00
|
|
|
import {CommunityService} from "../../openaireLibrary/connect/community/community.service";
|
|
|
|
import {Subscriber} from "rxjs";
|
2021-03-08 16:40:49 +01:00
|
|
|
import {NewSearchPageComponent} from "../../openaireLibrary/searchPages/searchUtils/newSearchPage.component";
|
|
|
|
import {SearchResult} from "../../openaireLibrary/utils/entities/searchResult";
|
2023-10-06 14:30:10 +02:00
|
|
|
import {StringUtils} from "../../openaireLibrary/utils/string-utils.class";
|
2018-01-26 16:00:07 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'openaire-search-projects',
|
|
|
|
template: `
|
2021-03-08 16:40:49 +01:00
|
|
|
<new-search-page
|
2023-07-24 18:19:26 +02:00
|
|
|
pageTitle="Search Projects"
|
|
|
|
entityType="project"
|
|
|
|
type="project"
|
|
|
|
[results]="results"
|
|
|
|
[searchUtils]="searchUtils"
|
|
|
|
[sortedByChanged]="searchUtils.sortBy"
|
|
|
|
[fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields"
|
2021-03-08 16:40:49 +01:00
|
|
|
|
2023-07-24 18:19:26 +02:00
|
|
|
[simpleSearchLink]="properties.searchLinkToProjects"
|
|
|
|
[disableForms]="disableForms"
|
|
|
|
[disableRefineForms]="disableRefineForms"
|
|
|
|
[loadPaging]="loadPaging"
|
|
|
|
[oldTotalResults]="oldTotalResults"
|
|
|
|
[openaireLink]="'https://' + (properties.environment == 'production'?'':'beta.') + 'explore.openaire.eu/search/find/projects'"
|
|
|
|
[includeOnlyResultsAndFilter]="false"
|
|
|
|
[hasPrefix]="false"
|
|
|
|
searchFormClass="datasourcesTableSearchForm" [entitiesSelection]="false" [showSwitchSearchLink]="false"
|
|
|
|
[filters]="filters"
|
|
|
|
[simpleView]="true" formPlaceholderText="Search by name..."
|
|
|
|
[showResultCount]="false" [showIndexInfo]="false" [showDownload]="false"
|
|
|
|
[sort]="false" [showBreadcrumb]="true"
|
|
|
|
[customFilter]=customFilter [searchForm]="{dark: false, class: 'search-form'}">
|
|
|
|
</new-search-page>
|
2018-03-01 12:55:49 +01:00
|
|
|
`
|
2018-01-26 16:00:07 +01:00
|
|
|
|
|
|
|
})
|
|
|
|
export class OpenaireSearchProjectsComponent {
|
2018-03-01 12:55:49 +01:00
|
|
|
private errorCodes: ErrorCodes;
|
2019-02-19 13:17:53 +01:00
|
|
|
private errorMessages: ErrorMessagesComponent;
|
2018-03-27 16:32:53 +02:00
|
|
|
public columnNames = ['Project', 'GrantId', 'Funder'];
|
2018-03-01 12:55:49 +01:00
|
|
|
public results =[];
|
2023-10-06 14:30:10 +02:00
|
|
|
public originalFunders =[];
|
2018-03-01 12:55:49 +01:00
|
|
|
public filters =[];
|
2023-10-06 14:30:10 +02:00
|
|
|
selectedFunder = null;
|
2018-03-01 12:55:49 +01:00
|
|
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
2020-11-30 18:04:05 +01:00
|
|
|
subscriptions = [];
|
2018-03-01 12:55:49 +01:00
|
|
|
public searchFields:SearchFields = new SearchFields();
|
2021-03-08 16:40:49 +01:00
|
|
|
public refineFields: string[] = ["funder"];
|
2021-02-19 18:52:12 +01:00
|
|
|
properties:EnvProperties = properties;
|
2018-03-01 12:55:49 +01:00
|
|
|
|
|
|
|
public disableForms: boolean = false;
|
2018-05-23 15:29:07 +02:00
|
|
|
public enableSearchView: boolean = true;
|
2018-03-01 12:55:49 +01:00
|
|
|
|
2018-03-02 14:10:15 +01:00
|
|
|
private communityId: string = '';
|
2020-04-03 18:02:40 +02:00
|
|
|
customFilter: SearchCustomFilter = null;
|
2020-04-23 15:35:54 +02:00
|
|
|
initialLoad = true;
|
2021-07-14 16:51:20 +02:00
|
|
|
@ViewChild(NewSearchPageComponent, { static: true }) searchPage: NewSearchPageComponent;
|
2021-03-08 16:40:49 +01:00
|
|
|
public fieldIds: string[] = this.searchFields.PROJECT_ADVANCED_FIELDS;
|
|
|
|
public fieldIdsMap= this.searchFields.PROJECT_FIELDS;
|
|
|
|
public selectedFields:AdvancedField[] = [];
|
|
|
|
public disableRefineForms: boolean = false;
|
|
|
|
public loadPaging: boolean = true;
|
|
|
|
public oldTotalResults: number = 0;
|
|
|
|
keyword;
|
|
|
|
constructor (private route: ActivatedRoute, private _searchProjectsService: SearchCommunityProjectsService, private _communityService: CommunityService) {
|
2018-03-01 12:55:49 +01:00
|
|
|
this.errorCodes = new ErrorCodes();
|
2019-02-19 13:17:53 +01:00
|
|
|
this.errorMessages = new ErrorMessagesComponent();
|
2018-03-01 12:55:49 +01:00
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnInit() {
|
2021-03-08 16:40:49 +01:00
|
|
|
this.searchUtils.baseUrl = this.properties.searchLinkToProjects;
|
2021-02-19 18:52:12 +01:00
|
|
|
this.subscriptions.push(this._communityService.getCommunityAsObservable().subscribe(community =>{
|
2020-11-30 18:04:05 +01:00
|
|
|
if(community != null){
|
2021-02-19 18:52:12 +01:00
|
|
|
this.communityId = community.communityId;
|
|
|
|
this.customFilter = new SearchCustomFilter("Community", "communityId", this.communityId, community.shortTitle);
|
2021-03-08 16:40:49 +01:00
|
|
|
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
|
|
|
let page = (params['page'] === undefined) ? 1 : +params['page'];
|
|
|
|
this.searchUtils.page = (page <= 0) ? 1 : page;
|
2023-10-06 14:30:10 +02:00
|
|
|
this.selectedFunder = params["funder"]?StringUtils.unquote(params["funder"]):null;
|
2021-08-13 14:48:41 +02:00
|
|
|
this.searchUtils.validateSize(params['size']);
|
2021-03-26 16:54:07 +01:00
|
|
|
this.keyword = decodeURIComponent(params['fv0']?params['fv0']:(params['keyword']?params['keyword']:''));
|
2021-03-08 16:40:49 +01:00
|
|
|
this.selectedFields = [];
|
|
|
|
this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, this.refineFields, [], this.fieldIdsMap, this.customFilter, params, "project");
|
|
|
|
if(this.initialLoad) {
|
|
|
|
this.initialLoad = false;
|
2023-10-06 14:30:10 +02:00
|
|
|
this._getCommunityFunders();
|
2021-03-08 16:40:49 +01:00
|
|
|
}else{
|
2022-02-16 15:03:14 +01:00
|
|
|
this._getResults();
|
2021-03-08 16:40:49 +01:00
|
|
|
}
|
|
|
|
}));
|
2020-11-30 18:04:05 +01:00
|
|
|
}
|
|
|
|
}));
|
2018-03-01 12:55:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
2020-11-30 18:04:05 +01:00
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscriber) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
2018-03-01 12:55:49 +01:00
|
|
|
}
|
2021-03-08 16:40:49 +01:00
|
|
|
private _getResults(){
|
2022-02-16 15:03:14 +01:00
|
|
|
this.results = [];
|
|
|
|
this.searchUtils.totalResults = 0;
|
|
|
|
this.searchUtils.refineStatus = this.errorCodes.LOADING;
|
2018-03-01 12:55:49 +01:00
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
this.disableForms = true;
|
2022-02-16 15:03:14 +01:00
|
|
|
this.disableRefineForms = true;
|
2018-05-23 15:29:07 +02:00
|
|
|
this.enableSearchView = false;
|
2023-10-06 14:30:10 +02:00
|
|
|
this.subscriptions.push(this._searchProjectsService.searchProjectsWithPaging(this.properties, this.communityId, this.searchUtils.page, this.searchUtils.size, this.searchUtils.keyword, this.selectedFunder, "name" ).subscribe(
|
|
|
|
data => {
|
|
|
|
this.searchUtils.totalResults = data['totalElements'];
|
|
|
|
this.filters = this.selectedFunder?this.createFilters([this.selectedFunder]):this.createFilters(this.originalFunders);
|
|
|
|
this.results = this.parseResults(data.content);
|
|
|
|
this.oldTotalResults = data['totalElements'];
|
|
|
|
this.searchUtils.totalResults = data['totalElements'];
|
|
|
|
this.searchUtils.status = this.results.length == 0 ? this.errorCodes.NONE: this.errorCodes.DONE;
|
|
|
|
this.disableForms = false;
|
|
|
|
this.disableRefineForms = false;
|
|
|
|
this.enableSearchView = true;
|
|
|
|
this.searchUtils.refineStatus = this.errorCodes.DONE;
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
this.handleError("Error getting projects for community with id: " + this.communityId, err);
|
|
|
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
|
|
|
this.enableSearchView = true;
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
2018-03-01 12:55:49 +01:00
|
|
|
}
|
|
|
|
|
2021-03-08 16:40:49 +01:00
|
|
|
|
|
|
|
private createFilters(data):Filter[] {
|
2018-03-01 12:55:49 +01:00
|
|
|
var funders = new Set<String>();
|
|
|
|
var value_name = [];
|
|
|
|
var value_original_id = [];
|
2023-10-06 14:30:10 +02:00
|
|
|
for(let funder of data) {
|
|
|
|
funders.add(funder);
|
|
|
|
value_name.push(funder);
|
|
|
|
value_original_id.push(funder);
|
2018-03-01 12:55:49 +01:00
|
|
|
}
|
2023-10-06 14:30:10 +02:00
|
|
|
|
2018-03-01 12:55:49 +01:00
|
|
|
|
|
|
|
var filters: Filter[] =[];
|
2023-10-06 14:30:10 +02:00
|
|
|
if(value_name.length > 0) {
|
2020-04-27 10:22:46 +02:00
|
|
|
var values: Value[] = [];
|
2023-10-06 14:30:10 +02:00
|
|
|
for (var j = 0; j < value_name.length; j++) {
|
|
|
|
var value: Value = {name: value_name[j], id:value_name[j], number: 0, selected: this.selectedFunder == value_name[j] }
|
2020-04-27 10:22:46 +02:00
|
|
|
values.push(value);
|
|
|
|
}
|
|
|
|
var filter: Filter = {
|
2023-10-06 14:30:10 +02:00
|
|
|
title: "Funder",
|
|
|
|
filterId: "funder",
|
|
|
|
originalFilterId: "funder",
|
2020-04-27 10:22:46 +02:00
|
|
|
values: values,
|
2023-10-06 14:30:10 +02:00
|
|
|
countSelectedValues: this.selectedFunder?1:0,
|
2020-04-27 10:22:46 +02:00
|
|
|
"filterOperator": 'or',
|
|
|
|
valueIsExact: true,
|
|
|
|
filterType: "checkbox"
|
|
|
|
};
|
|
|
|
filters.push(filter);
|
2018-03-01 12:55:49 +01:00
|
|
|
}
|
2023-10-06 14:30:10 +02:00
|
|
|
|
2018-03-01 12:55:49 +01:00
|
|
|
return filters;
|
|
|
|
}
|
2019-02-19 13:17:53 +01:00
|
|
|
|
2021-03-08 16:40:49 +01:00
|
|
|
parseResults(data){
|
|
|
|
let results:SearchResult[]=[];
|
|
|
|
for(let result of data){
|
|
|
|
let sResult:SearchResult = new SearchResult();
|
|
|
|
sResult.id = result.openaireId;
|
2022-06-16 14:01:41 +02:00
|
|
|
sResult.title = {name:"", accessMode: null};
|
2021-03-26 16:54:07 +01:00
|
|
|
sResult.title.name = result.name?result.name:result.acronym;
|
2021-03-08 16:40:49 +01:00
|
|
|
sResult.acronym = result['acronym'];
|
|
|
|
sResult.code = result['grantId'];
|
|
|
|
sResult['funderShortname'] = result['funder'];
|
|
|
|
results.push(sResult);
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
}
|
2023-10-06 14:30:10 +02:00
|
|
|
getFunderFilterValue(){
|
2021-03-08 16:40:49 +01:00
|
|
|
for(let filter of this.filters){
|
|
|
|
if(filter.countSelectedValues > 0){
|
|
|
|
for(let value of filter.values){
|
|
|
|
if(value.selected) {
|
2023-10-06 14:30:10 +02:00
|
|
|
return value.name;
|
2021-03-08 16:40:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-06 14:30:10 +02:00
|
|
|
return null;
|
|
|
|
|
2021-03-08 16:40:49 +01:00
|
|
|
}
|
2019-02-19 13:17:53 +01:00
|
|
|
private handleError(message: string, error) {
|
|
|
|
console.error("Projects simple Search Page: "+message, error);
|
|
|
|
}
|
2023-10-06 14:30:10 +02:00
|
|
|
|
|
|
|
public _getCommunityFunders() {
|
|
|
|
this.subscriptions.push(this._searchProjectsService.getProjectFunders(this.properties, this.communityId).subscribe(
|
|
|
|
data => {
|
|
|
|
this.originalFunders = data
|
2023-10-06 16:28:37 +02:00
|
|
|
this._getResults();
|
2023-10-06 14:30:10 +02:00
|
|
|
},
|
|
|
|
err => {
|
|
|
|
}
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2018-01-26 16:00:07 +01:00
|
|
|
}
|