2017-12-19 13:53:46 +01:00
|
|
|
import {Component, Input, ViewChild} from '@angular/core';
|
|
|
|
import { ActivatedRoute} from '@angular/router';
|
|
|
|
import {Location} from '@angular/common';
|
|
|
|
|
|
|
|
import { Filter, Value} from '../searchUtils/searchHelperClasses.class';
|
|
|
|
|
|
|
|
import {SearchPublicationsService} from '../../services/searchPublications.service';
|
|
|
|
import {SearchResult} from '../../utils/entities/searchResult';
|
2018-02-05 14:14:59 +01:00
|
|
|
import {ErrorCodes} from '../../utils/properties/openaireProperties';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {SearchFields, FieldDetails} from '../../utils/properties/searchFields';
|
|
|
|
import {SearchPageComponent } from '../searchUtils/searchPage.component';
|
|
|
|
import {SearchUtilsClass} from '../searchUtils/searchUtils.class';
|
|
|
|
import {DOI} from '../../utils/string-utils.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: 'search-publications',
|
|
|
|
template: `
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
<search-page pageTitle="Search Publications"
|
2017-12-19 13:53:46 +01:00
|
|
|
formPlaceholderText = "Search for Publications"
|
|
|
|
type="publications" entityType="publication"
|
|
|
|
[(filters)] = "filters" [(results)] = "results"
|
|
|
|
[(searchUtils)] = "searchUtils" [(baseUrl)] = baseUrl
|
|
|
|
(queryChange)="queryChanged($event)"
|
|
|
|
[csvParams]="csvParams" csvPath="publications"
|
|
|
|
advancedSearchLink="/search/advanced/publications"
|
|
|
|
[disableForms]="disableForms"
|
|
|
|
[loadPaging]="loadPaging"
|
|
|
|
[oldTotalResults]="oldTotalResults"
|
2018-02-05 14:14:59 +01:00
|
|
|
searchFormClass="publicationsSearchForm"
|
|
|
|
[(openaireLink)]=openaireLink
|
|
|
|
[(advancedSearchParameters)]=advancedSearchParameters
|
|
|
|
[(connectCommunityId)]=connectCommunityId
|
|
|
|
>
|
2017-12-19 13:53:46 +01:00
|
|
|
</search-page>
|
|
|
|
|
|
|
|
`
|
|
|
|
|
|
|
|
})
|
|
|
|
export class SearchPublicationsComponent {
|
|
|
|
private errorCodes: ErrorCodes;
|
|
|
|
|
|
|
|
public results =[];
|
|
|
|
public filters =[];
|
|
|
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
|
|
|
public baseUrl:string = "";
|
|
|
|
public sub: any;
|
|
|
|
public subResults: any;
|
|
|
|
public searchFields:SearchFields = new SearchFields();
|
|
|
|
public refineFields: string[] = this.searchFields.RESULT_REFINE_FIELDS;
|
|
|
|
public fieldIdsMap=this.searchFields.RESULT_FIELDS;
|
|
|
|
//: { [key:string] :{ name:string, operator:string, type:string, indexField:string, equalityOperator:string }} = this.searchFields.PUBLICATION_FIELDS_MAP;
|
|
|
|
public urlParams : Map<string, string>;
|
|
|
|
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
|
|
|
|
public _location:Location;
|
|
|
|
|
|
|
|
public CSV: any = { "columnNames": ["Title", "Authors", "Publication Year", "DOI",
|
|
|
|
/*"Download From", "Publication type", "Journal",*/
|
|
|
|
"Funder", "Project Name (GA Number)", "Access"],
|
|
|
|
"export":[]
|
|
|
|
};
|
|
|
|
public CSVDownloaded = false;
|
|
|
|
public csvParams: string;
|
|
|
|
public disableForms: boolean = false;
|
|
|
|
public loadPaging: boolean = true;
|
|
|
|
public oldTotalResults: number = 0;
|
2018-02-05 14:14:59 +01:00
|
|
|
@Input() openaireLink: string;
|
|
|
|
@Input() connectCommunityId: string;
|
|
|
|
@Input() advancedSearchParameters ;
|
|
|
|
pagingLimit = 0;
|
|
|
|
properties: EnvProperties;
|
2017-12-19 13:53:46 +01:00
|
|
|
constructor (private route: ActivatedRoute, private _searchPublicationsService: SearchPublicationsService ) {
|
|
|
|
this.errorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
this.searchUtils.page =1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnInit() {
|
2018-02-05 14:14:59 +01:00
|
|
|
this.route.data
|
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
this.properties = data.envSpecific;
|
|
|
|
this.baseUrl = data.envSpecific.searchLinkToPublications;
|
|
|
|
this.pagingLimit = data.envSpecific.pagingLimit;
|
|
|
|
|
|
|
|
});
|
2017-12-19 13:53:46 +01:00
|
|
|
this.searchPage.refineFields = this.refineFields;
|
|
|
|
this.searchPage.fieldIdsMap = this.fieldIdsMap;
|
|
|
|
this.searchPage.type = "publications";
|
|
|
|
var firstLoad =true;
|
|
|
|
this.sub = this.route.queryParams.subscribe(params => {
|
|
|
|
if(params['page'] && this.searchUtils.page != params['page']) {
|
|
|
|
this.loadPaging = false;
|
|
|
|
this.oldTotalResults = this.searchUtils.totalResults;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
|
|
|
|
var refine = true;
|
|
|
|
if(this.searchUtils.page != ((params['page']=== undefined)?1:+params['page']) && this.filters && !firstLoad){
|
|
|
|
refine = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
firstLoad = false;
|
|
|
|
this.searchUtils.page = (params['page']=== undefined)?1:+params['page'];
|
|
|
|
var queryParameters = this.searchPage.getQueryParametersFromUrl(params);
|
|
|
|
this._getResults(queryParameters, refine, this.searchUtils.page, this.searchUtils.size);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
if(this.sub){
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
if(this.subResults){
|
|
|
|
this.subResults.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public getResultsForEntity(entity:string, id:string, page: number, size: number){
|
|
|
|
var parameters = "";
|
|
|
|
|
|
|
|
if(entity == "project") {
|
|
|
|
parameters = "projects/"+id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(parameters != "") {
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
this._searchPublicationsService.searchPublicationsForEntity(parameters, page, size, this.properties).subscribe(
|
2017-12-19 13:53:46 +01:00
|
|
|
data => {
|
|
|
|
this.searchUtils.totalResults = data[0];
|
|
|
|
console.info("search Publications for "+entity+": [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
|
|
|
this.results = data[1];
|
|
|
|
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
|
|
|
if(this.searchUtils.totalResults == 0 ){
|
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
console.log(err);
|
|
|
|
//TODO check erros (service not available, bad request)
|
|
|
|
// if( ){
|
|
|
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
|
|
|
// }
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
//this.searchUtils.status = errorCodes.ERROR;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public getResultsForDataproviders(id:string, resultsFrom:string, page: number, size: number){
|
|
|
|
var parameters;
|
|
|
|
if(resultsFrom == "collectedFrom") {
|
|
|
|
parameters = "publications?fq=collectedfromdatasourceid exact "+'"'+id+'"';
|
|
|
|
} else if(resultsFrom == "hostedBy") {
|
|
|
|
parameters = "publications?fq=resulthostingdatasourceid exact "+'"'+id+'"';
|
|
|
|
}
|
|
|
|
|
|
|
|
if(parameters != "") {
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
this._searchPublicationsService.searchPublicationsForDataproviders(parameters, page, size, this.properties).subscribe(
|
2017-12-19 13:53:46 +01:00
|
|
|
data => {
|
|
|
|
this.searchUtils.totalResults = data[0];
|
|
|
|
console.info("search Publications for Dataproviders: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
|
|
|
this.results = data[1];
|
|
|
|
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
|
|
|
if(this.searchUtils.totalResults == 0 ){
|
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
console.log(err);
|
|
|
|
//TODO check erros (service not available, bad request)
|
|
|
|
// if( ){
|
|
|
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
|
|
|
// }
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
//this.searchUtils.status = errorCodes.ERROR;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public getResults(keyword:string,refine:boolean, page: number, size: number){
|
|
|
|
var parameters = "";
|
|
|
|
if(keyword.length > 0){
|
|
|
|
var DOIs:string[] = DOI.getDOIsFromString(keyword);
|
|
|
|
var doisParams = "";
|
|
|
|
|
|
|
|
for(var i =0 ;i < DOIs.length; i++){
|
|
|
|
doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"';
|
|
|
|
}
|
|
|
|
if(doisParams.length > 0){
|
|
|
|
parameters += "&"+doisParams;
|
|
|
|
}else{
|
|
|
|
parameters = "q=" + keyword;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._getResults(parameters,refine,page,size);
|
|
|
|
}
|
|
|
|
|
|
|
|
private _getResults(parameters:string,refine:boolean, page: number, size: number){
|
2018-02-05 14:14:59 +01:00
|
|
|
if(page > this.pagingLimit) {
|
|
|
|
size=0;
|
|
|
|
}
|
|
|
|
if(page <= this.pagingLimit || this.searchUtils.status == this.errorCodes.LOADING) {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.csvParams = parameters;
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
this.disableForms = true;
|
|
|
|
this.results = [];
|
|
|
|
this.searchUtils.totalResults = 0;
|
|
|
|
|
|
|
|
this.subResults = this._searchPublicationsService.searchPublications(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields(), this.properties).subscribe(
|
|
|
|
data => {
|
|
|
|
console.info(data);
|
|
|
|
this.searchUtils.totalResults = data[0];
|
|
|
|
console.info("search Publications: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
|
|
|
this.results = data[1];
|
|
|
|
if(refine){
|
|
|
|
this.filters = data[2];
|
|
|
|
}
|
|
|
|
this.searchPage.checkSelectedFilters(this.filters);
|
|
|
|
this.searchPage.updateBaseUrlWithParameters(this.filters);
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
|
|
|
if(this.searchUtils.totalResults == 0 ){
|
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
//this.searchPage.closeLoading();
|
|
|
|
this.disableForms = false;
|
|
|
|
|
|
|
|
if(this.searchUtils.status == this.errorCodes.DONE) {
|
|
|
|
// Page out of limit!!!
|
|
|
|
let totalPages:any = this.searchUtils.totalResults/(this.searchUtils.size);
|
|
|
|
if(!(Number.isInteger(totalPages))) {
|
|
|
|
totalPages = (parseInt(totalPages, 10) + 1);
|
|
|
|
}
|
|
|
|
if(totalPages < page) {
|
|
|
|
this.searchUtils.totalResults = 0;
|
|
|
|
this.searchUtils.status = this.errorCodes.OUT_OF_BOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
console.log(err);
|
|
|
|
//TODO check erros (service not available, bad request)
|
|
|
|
// if( ){
|
|
|
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
|
|
|
// }
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
//this.searchUtils.status = errorCodes.ERROR;
|
|
|
|
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;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
//this.searchPage.closeLoading();
|
|
|
|
this.disableForms = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
public getAggregatorResults(id:string, page: number, size: number){
|
|
|
|
this.subResults = this._searchPublicationsService.searchAggregators('&fq=collectedfromdatasourceid exact "'+id+'"',"&refine=true&fields=resulthostingdatasource" , page, size).subscribe(
|
|
|
|
data => {
|
|
|
|
this.results = data;
|
|
|
|
|
|
|
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = errorCodes.DONE;
|
|
|
|
if(this.searchUtils.totalResults == 0 ){
|
|
|
|
this.searchUtils.status = errorCodes.NONE;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
console.log(err);
|
|
|
|
//TODO check erros (service not available, bad request)
|
|
|
|
// if( ){
|
|
|
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
|
|
|
// }
|
|
|
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = errorCodes.ERROR;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}*/
|
|
|
|
|
|
|
|
public queryChanged($event) {
|
|
|
|
this.loadPaging = true;
|
|
|
|
|
|
|
|
var parameters = $event.value;
|
|
|
|
console.info("queryChanged: Execute search query "+parameters);
|
|
|
|
console.info("Search Pubs::page "+this.searchUtils.page);
|
|
|
|
this._getResults(parameters, true, this.searchUtils.page, this.searchUtils.size);
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|