2020-11-12 16:59:26 +01:00
|
|
|
import {Component, ViewChild} from '@angular/core';
|
2018-03-01 12:55:49 +01:00
|
|
|
import { ActivatedRoute} from '@angular/router';
|
|
|
|
|
|
|
|
import { Filter, Value} from '../../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class';
|
|
|
|
|
|
|
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
2019-02-19 13:17:53 +01:00
|
|
|
import {ErrorMessagesComponent} from '../../openaireLibrary/utils/errorMessages.component';
|
2020-11-12 16:59:26 +01:00
|
|
|
import {SearchFields} from '../../openaireLibrary/utils/properties/searchFields';
|
2018-03-01 12:55:49 +01:00
|
|
|
import {SearchPageTableViewComponent } from '../../openaireLibrary/searchPages/searchUtils/searchPageTableView.component';
|
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';
|
2018-04-11 12:40:29 +02:00
|
|
|
import {PiwikHelper} from '../../utils/piwikHelper';
|
2018-03-29 10:28:04 +02:00
|
|
|
import {ConnectHelper} from '../../openaireLibrary/connect/connectHelper';
|
2020-11-12 16:59:26 +01:00
|
|
|
import {properties} from "../../../environments/environment";
|
2018-01-26 16:00:07 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'openaire-search-projects',
|
|
|
|
template: `
|
|
|
|
|
2019-08-02 16:56:03 +02:00
|
|
|
<search-page-table pageTitle="Search Projects"
|
2020-04-03 18:02:40 +02:00
|
|
|
type="projects" entityType="project" [filters] = "filters"
|
|
|
|
[results] = "results" [searchUtils] = "searchUtils"
|
2018-03-01 12:55:49 +01:00
|
|
|
[columnNames]="columnNames"
|
|
|
|
[showResultCount]=false
|
2018-05-23 15:48:12 +02:00
|
|
|
openaireLink="https://beta.explore.openaire.eu/search/find/projects"
|
2018-03-01 12:55:49 +01:00
|
|
|
[disableForms]="disableForms"
|
2018-05-23 15:29:07 +02:00
|
|
|
[enableSearchView]="enableSearchView"
|
2018-03-02 13:52:12 +01:00
|
|
|
searchFormClass="projectsTableSearchForm"
|
2020-05-07 12:29:52 +02:00
|
|
|
formPlaceholderText="Search by project title, grant id, funder... "
|
2020-04-27 10:22:46 +02:00
|
|
|
[piwikSiteId]="piwikSiteId" [hasPrefix]="false" [customFilter]="customFilter" [enableEntitySelection]="true"
|
2020-05-07 12:29:52 +02:00
|
|
|
[includeOnlyResultsAndFilter]="false" [showBreadcrumb]="true">
|
2018-03-01 12:55:49 +01:00
|
|
|
</search-page-table>
|
|
|
|
`
|
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 =[];
|
|
|
|
public filters =[];
|
|
|
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
|
|
|
public sub: any; public subResults: any;
|
|
|
|
public _location:Location;
|
|
|
|
public searchFields:SearchFields = new SearchFields();
|
|
|
|
public refineFields: string[] = [];// = this.searchFields.JOURNAL_FIELDS;
|
|
|
|
properties:EnvProperties;
|
|
|
|
|
|
|
|
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 = '';
|
|
|
|
|
2018-03-01 12:55:49 +01:00
|
|
|
@ViewChild (SearchPageTableViewComponent) searchPage : SearchPageTableViewComponent ;
|
2018-04-11 12:40:29 +02:00
|
|
|
piwikSiteId = null;
|
2020-04-03 18:02:40 +02:00
|
|
|
customFilter: SearchCustomFilter = null;
|
2020-04-23 15:35:54 +02:00
|
|
|
initialLoad = true;
|
2018-03-02 13:52:12 +01:00
|
|
|
constructor (private route: ActivatedRoute, private _searchProjectsService: SearchCommunityProjectsService) {
|
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() {
|
2018-03-22 16:38:42 +01:00
|
|
|
|
2020-11-12 16:59:26 +01:00
|
|
|
this.properties = properties;
|
|
|
|
|
2018-03-01 12:55:49 +01:00
|
|
|
this.sub = this.route.queryParams.subscribe(params => {
|
2019-07-03 12:16:58 +02:00
|
|
|
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
|
|
|
|
if(!this.communityId) {
|
|
|
|
this.communityId = params['communityId'];
|
2018-03-22 16:38:42 +01:00
|
|
|
}
|
2020-04-03 18:02:40 +02:00
|
|
|
this.customFilter = new SearchCustomFilter("Community", "communityId", this.communityId, "");
|
2019-08-02 16:56:03 +02:00
|
|
|
this.piwikSiteId = PiwikHelper.getSiteId(this.communityId,this.properties.environment);
|
2020-04-23 15:35:54 +02:00
|
|
|
this.searchUtils.keyword = (params['fv0']?params['fv0']:(params['keyword']?params['keyword']:''));
|
|
|
|
if(this.initialLoad) {
|
|
|
|
this.initialLoad = false;
|
|
|
|
this._getResults(params);
|
|
|
|
}else{
|
|
|
|
this.searchPage.goTo(1);
|
|
|
|
}
|
2018-03-01 12:55:49 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
if(this.sub){
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
if(this.subResults){
|
|
|
|
this.subResults.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private _getResults(params){
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
this.disableForms = true;
|
2018-05-23 15:29:07 +02:00
|
|
|
this.enableSearchView = false;
|
2018-03-01 12:55:49 +01:00
|
|
|
this.results = [];
|
|
|
|
this.searchUtils.totalResults = 0;
|
|
|
|
|
|
|
|
let size: number = 0;
|
|
|
|
|
2018-03-02 14:10:15 +01:00
|
|
|
this.subResults = this._searchProjectsService.searchProjects(this.properties, this.communityId).subscribe(
|
2018-03-01 12:55:49 +01:00
|
|
|
data => {
|
2020-04-03 18:02:40 +02:00
|
|
|
// data=data.slice(0,150)
|
2018-03-01 12:55:49 +01:00
|
|
|
this.filters = this.createFilters(data, params);
|
|
|
|
|
|
|
|
this.searchUtils.totalResults = data.length;
|
2019-02-14 12:11:12 +01:00
|
|
|
//console.info("search Projects [total results:"+this.searchUtils.totalResults+"]");
|
2018-03-01 12:55:49 +01:00
|
|
|
this.results = data;
|
|
|
|
|
|
|
|
this.searchPage.checkSelectedFilters(this.filters);
|
|
|
|
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
|
|
|
if(this.searchUtils.totalResults == 0 ){
|
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
2018-05-23 15:29:07 +02:00
|
|
|
} else {
|
|
|
|
this.searchPage.triggerInitialLoad();
|
2020-05-11 13:07:36 +02:00
|
|
|
this.searchPage.transform(this.results, this.searchUtils);
|
2018-05-23 15:29:07 +02:00
|
|
|
this.disableForms = false;
|
2018-03-01 12:55:49 +01:00
|
|
|
}
|
2018-05-23 15:29:07 +02:00
|
|
|
this.enableSearchView = true;
|
2018-03-01 12:55:49 +01:00
|
|
|
},
|
|
|
|
err => {
|
2019-02-19 13:17:53 +01:00
|
|
|
/*
|
2018-03-01 12:55:49 +01:00
|
|
|
console.log(err);
|
|
|
|
//TODO check erros (service not available, bad request)
|
|
|
|
|
|
|
|
if(err.status == '404') {
|
|
|
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
|
|
|
} else if(err.status == '500') {
|
|
|
|
this.searchUtils.status = this.errorCodes.ERROR;
|
|
|
|
} else {
|
|
|
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
|
|
|
}
|
2019-02-19 13:17:53 +01:00
|
|
|
*/
|
|
|
|
this.handleError("Error getting projects for community with id: "+this.communityId, err);
|
|
|
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
2018-03-01 12:55:49 +01:00
|
|
|
|
2018-05-23 15:29:07 +02:00
|
|
|
this.enableSearchView = true;
|
2018-03-01 12:55:49 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
private setFilters(){
|
|
|
|
//TODO set filters from
|
|
|
|
}
|
|
|
|
|
|
|
|
private createFilters(data, params):Filter[] {
|
|
|
|
let length = Array.isArray(data) ? data.length : 1;
|
|
|
|
|
|
|
|
var filter_names=["Funder"];
|
|
|
|
var filter_ids=["relfunder"];
|
|
|
|
var searchFields = new SearchFields();
|
|
|
|
var filter_original_ids = ["relfunder"];//searchFields.JOURNAL_FIELDS;
|
|
|
|
|
|
|
|
this.refineFields = ["relfunder"];
|
|
|
|
this.searchPage.refineFields = this.refineFields;
|
|
|
|
this.searchPage.getParametersFromUrl(params);
|
|
|
|
|
|
|
|
var value_names=[/*["Journal", "Journal Aggregator\/Publisher"]*/];
|
|
|
|
var value_original_ids=[/*["pubsrepository::journal", "aggregator::pubsrepository::journals"]*/];
|
|
|
|
|
|
|
|
var funders = new Set<String>();
|
|
|
|
var value_name = [];
|
|
|
|
var value_original_id = [];
|
|
|
|
let i;
|
|
|
|
for(i=0; i<length; i++) {
|
|
|
|
let resData = Array.isArray(data) ? data[i] : data;
|
|
|
|
if(resData.funder && !funders.has(resData.funder)) {
|
|
|
|
funders.add(resData.funder);
|
|
|
|
value_name.push(resData.funder);
|
|
|
|
value_original_id.push(resData.funder.trim());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
value_names.push(value_name);
|
|
|
|
value_original_ids.push(value_original_id);
|
|
|
|
|
|
|
|
var filters: Filter[] =[];
|
|
|
|
for(i =0 ; i < filter_names.length;i++){
|
2020-04-27 10:22:46 +02:00
|
|
|
if(value_names[i].length > 0) {
|
|
|
|
var values: Value[] = [];
|
|
|
|
for (var j = 0; j < value_names[i].length; j++) {
|
|
|
|
var value: Value = {name: value_names[i][j], id: value_original_ids[i][j], number: j, selected: false}
|
|
|
|
values.push(value);
|
|
|
|
}
|
|
|
|
var filter: Filter = {
|
|
|
|
title: filter_names[i],
|
|
|
|
filterId: filter_ids[i],
|
|
|
|
originalFilterId: filter_original_ids[i],
|
|
|
|
values: values,
|
|
|
|
countSelectedValues: 0,
|
|
|
|
"filterOperator": 'or',
|
|
|
|
valueIsExact: true,
|
|
|
|
filterType: "checkbox"
|
|
|
|
};
|
|
|
|
filters.push(filter);
|
2018-03-01 12:55:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return filters;
|
|
|
|
}
|
2019-02-19 13:17:53 +01:00
|
|
|
|
|
|
|
private handleError(message: string, error) {
|
|
|
|
console.error("Projects simple Search Page: "+message, error);
|
|
|
|
}
|
2018-01-26 16:00:07 +01:00
|
|
|
}
|