2018-07-25 15:30:12 +02: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 {SearchOrpsService} from '../../services/searchOrps.service';
|
|
|
|
import {SearchResult} from '../../utils/entities/searchResult';
|
|
|
|
import { ErrorCodes} from '../../utils/properties/errorCodes';
|
2019-02-15 13:50:24 +01:00
|
|
|
import {ErrorMessagesComponent} from '../../utils/errorMessages.component';
|
2018-07-25 15:30:12 +02: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';
|
|
|
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'search-orps',
|
|
|
|
template: `
|
|
|
|
|
|
|
|
<search-page pageTitle="Search Other Research Products"
|
|
|
|
formPlaceholderText = "Search for Other Research Products"
|
|
|
|
type="other research products" entityType="other" [(filters)] = "filters"
|
|
|
|
[(results)] = "results" [(searchUtils)] = "searchUtils"
|
|
|
|
[baseUrl] = "baseUrl" (queryChange)="queryChanged($event)"
|
|
|
|
[csvParams]="csvParams" csvPath="other" advancedSearchLink="/search/advanced/other"
|
|
|
|
[disableForms]="disableForms"
|
|
|
|
[loadPaging]="loadPaging"
|
|
|
|
[oldTotalResults]="oldTotalResults"
|
|
|
|
searchFormClass="orpsSearchForm"
|
|
|
|
[(openaireLink)]=openaireLink
|
|
|
|
[(advancedSearchParameters)]=advancedSearchParameters
|
|
|
|
[piwikSiteId]=piwikSiteId
|
2018-11-21 16:28:38 +01:00
|
|
|
[(connectCommunityId)]=connectCommunityId
|
|
|
|
[(sort)]=sort >
|
2018-07-25 15:30:12 +02:00
|
|
|
</search-page>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
|
|
|
|
export class SearchOrpsComponent {
|
|
|
|
private errorCodes: ErrorCodes;
|
2019-02-15 13:50:24 +01:00
|
|
|
private errorMessages: ErrorMessagesComponent;
|
2018-07-25 15:30:12 +02:00
|
|
|
@Input() piwikSiteId = null;
|
|
|
|
public results =[];
|
|
|
|
public filters: Filter[] =[];
|
|
|
|
public baseUrl:string;
|
|
|
|
@Input() openaireLink: string ;
|
|
|
|
@Input() connectCommunityId: string;
|
|
|
|
@Input() advancedSearchParameters ;
|
|
|
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
|
|
|
private sub: any;
|
|
|
|
private subResults: any;
|
|
|
|
private searchFields:SearchFields = new SearchFields();
|
|
|
|
public refineFields: string[] = this.searchFields.RESULT_REFINE_FIELDS;
|
|
|
|
public fieldIdsMap=this.searchFields.RESULT_FIELDS;
|
|
|
|
private urlParams : Map<string, string>;
|
|
|
|
private _location:Location;
|
|
|
|
public csvParams: string;
|
|
|
|
public disableForms: boolean = false;
|
|
|
|
public loadPaging: boolean = true;
|
|
|
|
public oldTotalResults: number = 0;
|
|
|
|
pagingLimit = 0;
|
2018-11-21 16:28:38 +01:00
|
|
|
public sort: boolean = true;
|
2018-07-25 15:30:12 +02:00
|
|
|
properties: EnvProperties;
|
|
|
|
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
|
|
|
|
constructor (private route: ActivatedRoute, private _searchOrpsService: SearchOrpsService ) {
|
|
|
|
|
|
|
|
this.errorCodes = new ErrorCodes();
|
2019-02-15 13:50:24 +01:00
|
|
|
this.errorMessages = new ErrorMessagesComponent();
|
2018-07-25 15:30:12 +02:00
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
this.searchUtils.page =1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnInit() {
|
|
|
|
this.route.data
|
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
this.properties = data.envSpecific;
|
|
|
|
this.baseUrl = data.envSpecific.searchLinkToOrps;
|
|
|
|
this.pagingLimit = data.envSpecific.pagingLimit;
|
|
|
|
|
|
|
|
});
|
|
|
|
this.searchPage.refineFields = this.refineFields;
|
|
|
|
this.searchPage.fieldIdsMap = this.fieldIdsMap;
|
|
|
|
this.searchPage.type = "other research products";
|
|
|
|
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'];
|
2018-11-21 16:28:38 +01:00
|
|
|
this.searchUtils.size = (params['size']=== undefined)?10:+params['size'];
|
|
|
|
if(this.searchUtils.size != 5 && this.searchUtils.size != 10 && this.searchUtils.size != 20 && this.searchUtils.size != 50) {
|
|
|
|
this.searchUtils.size = 10;
|
|
|
|
}
|
|
|
|
this.searchUtils.sortBy = (params['sortBy'])?params['sortBy']:'';
|
2018-12-03 13:32:33 +01:00
|
|
|
if(this.searchUtils.sortBy && this.searchUtils.sortBy != "resultdateofacceptance,descending" && this.searchUtils.sortBy != "resultdateofacceptance,ascending") {
|
2018-11-21 16:28:38 +01:00
|
|
|
this.searchUtils.sortBy = "";
|
|
|
|
}
|
|
|
|
|
2018-07-25 15:30:12 +02:00
|
|
|
this.searchPage.connectCommunityId = this.connectCommunityId;
|
|
|
|
var queryParameters = this.searchPage.getQueryParametersFromUrl(params);
|
2018-11-21 16:28:38 +01:00
|
|
|
this._getResults(queryParameters, refine, this.searchUtils.page, this.searchUtils.size, this.searchUtils.sortBy);
|
2018-07-25 15:30:12 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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 != "") {
|
|
|
|
|
|
|
|
this._searchOrpsService.searchOrpsForEntity(parameters, page, size, this.properties).subscribe(
|
|
|
|
data => {
|
|
|
|
this.searchUtils.totalResults = data[0];
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.info("search Other Research Products for "+entity+": [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
2018-07-25 15:30:12 +02:00
|
|
|
this.results = data[1];
|
|
|
|
|
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
|
|
|
if(this.searchUtils.totalResults == 0 ){
|
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
2019-02-15 13:50:24 +01:00
|
|
|
//console.log(err);
|
|
|
|
this.handleError("Error getting other research products for "+entity+" with id: "+id, err);
|
|
|
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
|
|
|
|
2018-07-25 15:30:12 +02:00
|
|
|
//TODO check erros (service not available, bad request)
|
2019-02-15 13:50:24 +01:00
|
|
|
/*if(err.status == '404') {
|
2018-07-25 15:30:12 +02:00
|
|
|
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-15 13:50:24 +01:00
|
|
|
}*/
|
2018-07-25 15:30:12 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public getResultsForDataproviders(id:string, resultsFrom:string, page: number, size: number){
|
|
|
|
var parameters;
|
|
|
|
if(resultsFrom == "collectedFrom") {
|
|
|
|
parameters = "orps?fq=collectedfromdatasourceid exact "+'"'+id+'"';
|
|
|
|
} else if(resultsFrom == "hostedBy") {
|
|
|
|
parameters = "orps?fq=resulthostingdatasourceid exact "+'"'+id+'"';
|
|
|
|
}
|
|
|
|
|
|
|
|
if(parameters != "") {
|
|
|
|
|
|
|
|
this._searchOrpsService.searchOrpsForDataproviders(parameters, page, size, this.properties).subscribe(
|
|
|
|
data => {
|
|
|
|
this.searchUtils.totalResults = data[0];
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.info("search Other Research Products for Dataproviders: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
2018-07-25 15:30:12 +02:00
|
|
|
this.results = data[1];
|
|
|
|
|
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
|
|
|
if(this.searchUtils.totalResults == 0 ){
|
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
2019-02-15 13:50:24 +01:00
|
|
|
//console.log(err);
|
|
|
|
this.handleError("Error getting other research products for content provider ("+resultsFrom+") with id: "+id, err);
|
|
|
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
|
|
|
|
2018-07-25 15:30:12 +02:00
|
|
|
//TODO check erros (service not available, bad request)
|
2019-02-15 13:50:24 +01:00
|
|
|
/*if(err.status == '404') {
|
2018-07-25 15:30:12 +02:00
|
|
|
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-15 13:50:24 +01:00
|
|
|
}*/
|
2018-07-25 15:30:12 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-21 16:28:38 +01:00
|
|
|
public getResults(keyword:string,refine:boolean, page: number, size: number, sortBy: string){
|
2018-07-25 15:30:12 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2018-11-21 16:28:38 +01:00
|
|
|
this._getResults(parameters,refine,page,size,sortBy);
|
2018-07-25 15:30:12 +02:00
|
|
|
}
|
2018-11-21 16:28:38 +01:00
|
|
|
private _getResults(parameters:string,refine:boolean, page: number, size: number, sortBy: string){
|
2018-07-25 15:30:12 +02:00
|
|
|
if(page > this.pagingLimit) {
|
|
|
|
size=0;
|
|
|
|
}
|
|
|
|
if(page <= this.pagingLimit || this.searchUtils.status == this.errorCodes.LOADING) {
|
|
|
|
this.csvParams = parameters;
|
|
|
|
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
this.disableForms = true;
|
|
|
|
this.results = [];
|
|
|
|
this.searchUtils.totalResults = 0;
|
|
|
|
|
2018-11-21 16:28:38 +01:00
|
|
|
this.subResults = this._searchOrpsService.searchOrps(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, sortBy, this.searchPage.getFields(), this.properties).subscribe(
|
2018-07-25 15:30:12 +02:00
|
|
|
data => {
|
|
|
|
this.searchUtils.totalResults = data[0];
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.info("search Other Research Products: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
2018-07-25 15:30:12 +02:00
|
|
|
this.results = data[1];
|
|
|
|
if(refine){
|
|
|
|
this.filters = data[2];
|
|
|
|
}
|
|
|
|
this.searchPage.checkSelectedFilters(this.filters);
|
|
|
|
this.searchPage.updateBaseUrlWithParameters(this.filters);
|
|
|
|
|
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
|
|
|
if(this.searchUtils.totalResults == 0 ){
|
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
|
|
|
}
|
|
|
|
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 => {
|
2019-02-15 13:50:24 +01:00
|
|
|
//console.log(err);
|
|
|
|
this.handleError("Error getting other research products", err);
|
|
|
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
|
|
|
|
2018-07-25 15:30:12 +02:00
|
|
|
//TODO check erros (service not available, bad request)
|
2019-02-15 13:50:24 +01:00
|
|
|
/*if(err.status == '404') {
|
2018-07-25 15:30:12 +02:00
|
|
|
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-15 13:50:24 +01:00
|
|
|
}*/
|
2018-07-25 15:30:12 +02:00
|
|
|
|
|
|
|
this.disableForms = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private setFilters(){
|
|
|
|
//TODO set filters from
|
|
|
|
}
|
|
|
|
|
|
|
|
public queryChanged($event) {
|
|
|
|
this.loadPaging = true;
|
|
|
|
|
|
|
|
var parameters = $event.value;
|
2018-11-21 16:28:38 +01:00
|
|
|
this._getResults(parameters, true, this.searchUtils.page, this.searchUtils.size, this.searchUtils.sortBy);
|
2018-07-25 15:30:12 +02:00
|
|
|
}
|
2019-02-15 13:50:24 +01:00
|
|
|
|
|
|
|
private handleError(message: string, error) {
|
|
|
|
console.error("Other Research Products simple Search Page: "+message, error);
|
|
|
|
}
|
2018-07-25 15:30:12 +02:00
|
|
|
}
|