2020-02-19 16:35:48 +01:00
|
|
|
import {Component, EventEmitter, Input, OnChanges, Output, SimpleChanges, ViewChild} from '@angular/core';
|
2020-01-31 16:12:51 +01:00
|
|
|
import {ActivatedRoute} from '@angular/router';
|
2020-02-11 15:56:20 +01:00
|
|
|
import {AdvancedField, Filter} from './searchUtils/searchHelperClasses.class';
|
2020-01-31 16:12:51 +01:00
|
|
|
import {SearchResearchResultsService} from '../services/searchResearchResults.service';
|
|
|
|
import {ErrorCodes} from '../utils/properties/errorCodes';
|
|
|
|
import {ErrorMessagesComponent} from '../utils/errorMessages.component';
|
|
|
|
import {SearchFields} from '../utils/properties/searchFields';
|
|
|
|
import {SearchCustomFilter, SearchUtilsClass} from './searchUtils/searchUtils.class';
|
|
|
|
import {EnvProperties} from '../utils/properties/env-properties';
|
|
|
|
import {NewSearchPageComponent} from "./searchUtils/newSearchPage.component";
|
2020-02-17 15:19:14 +01:00
|
|
|
import {RangeFilter} from "../utils/rangeFilter/rangeFilterHelperClasses.class";
|
2020-01-31 16:12:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'search-research-results',
|
2020-02-24 14:45:22 +01:00
|
|
|
template: `
|
2020-01-31 16:12:51 +01:00
|
|
|
<new-search-page
|
|
|
|
pageTitle="{{(simpleView?'':'Advanced ')}} Search for {{ getEntityName(resultType, true, true) | titlecase }}"
|
|
|
|
[entityType]="resultType"
|
|
|
|
[type]="getEntityName(resultType, true, true)"
|
2020-02-19 16:35:48 +01:00
|
|
|
[results]="results"
|
|
|
|
[searchUtils]="searchUtils"
|
|
|
|
[fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields"
|
2020-01-31 16:12:51 +01:00
|
|
|
[csvParams]="csvParams" [csvPath]="getEntityName(resultType, true, false)"
|
|
|
|
[simpleSearchLink]="simpleSearchLink" [advancedSearchLink]="advancedSearchLink"
|
|
|
|
[disableForms]="disableForms"
|
|
|
|
[loadPaging]="loadPaging"
|
|
|
|
[oldTotalResults]="oldTotalResults"
|
2020-02-19 16:35:48 +01:00
|
|
|
[openaireLink]=openaireLink
|
2020-01-31 16:12:51 +01:00
|
|
|
[piwikSiteId]=piwikSiteId [hasPrefix]="hasPrefix"
|
|
|
|
searchFormClass="publicationsSearchForm"
|
2020-02-19 16:35:48 +01:00
|
|
|
[filters]="filters" [quickFilter]="quickFilter"
|
2020-02-17 15:19:14 +01:00
|
|
|
[rangeFilters]="rangeFilters" [rangeFields]="rangeFields"
|
2020-03-26 13:18:18 +01:00
|
|
|
[simpleView]="simpleView" formPlaceholderText="Search by title, author, abstract, DOI, orcid..."
|
2020-04-23 09:33:23 +02:00
|
|
|
[includeOnlyResultsAndFilter]="includeOnlyResultsAndFilter" [showBreadcrumb]="showBreadcrumb" [showAdvancedSearchLink]="showAdvancedSearchLink"
|
2020-01-31 16:12:51 +01:00
|
|
|
>
|
|
|
|
</new-search-page>
|
2020-02-19 16:35:48 +01:00
|
|
|
|
2020-01-31 16:12:51 +01:00
|
|
|
`
|
|
|
|
})
|
|
|
|
|
|
|
|
export class SearchResearchResultsComponent {
|
2020-02-11 12:58:51 +01:00
|
|
|
@Input() resultType: string = "result";
|
2020-01-31 16:12:51 +01:00
|
|
|
|
2020-02-19 16:35:48 +01:00
|
|
|
@Input() simpleSearchLink: string = "";
|
2020-01-31 16:12:51 +01:00
|
|
|
advancedSearchLink: string = "";
|
|
|
|
|
|
|
|
private errorCodes: ErrorCodes;
|
|
|
|
private errorMessages: ErrorMessagesComponent;
|
|
|
|
@Input() piwikSiteId = null;
|
|
|
|
@Input() hasPrefix: boolean = true;
|
|
|
|
public results = [];
|
|
|
|
public filters = [];
|
2020-02-17 15:19:14 +01:00
|
|
|
public rangeFilters: RangeFilter[] = [];
|
2020-01-31 16:12:51 +01:00
|
|
|
|
|
|
|
public searchUtils: SearchUtilsClass = new SearchUtilsClass();
|
|
|
|
public searchFields: SearchFields = new SearchFields();
|
|
|
|
|
|
|
|
public fieldIds: string[] = this.searchFields.RESULT_ADVANCED_FIELDS;
|
|
|
|
public fieldIdsMap = this.searchFields.RESULT_FIELDS;
|
2020-02-17 15:19:14 +01:00
|
|
|
public rangeFields:string[][] = this.searchFields.RESULT_RANGE_FIELDS;
|
2020-01-31 16:12:51 +01:00
|
|
|
public selectedFields: AdvancedField[] = [];
|
|
|
|
public resourcesQuery = "((oaftype exact result) and (resulttypeid exact " + this.resultType + "))";
|
|
|
|
public csvParams: string;
|
|
|
|
public disableForms: boolean = false;
|
|
|
|
public loadPaging: boolean = true;
|
|
|
|
public oldTotalResults: number = 0;
|
|
|
|
@Input() openaireLink: string;
|
|
|
|
@Input() customFilter: SearchCustomFilter = null;
|
|
|
|
public pagingLimit: number = 0;
|
|
|
|
public isPiwikEnabled;
|
|
|
|
properties: EnvProperties;
|
|
|
|
public refineFields: string[] = this.searchFields.RESULT_REFINE_FIELDS;
|
|
|
|
@ViewChild(NewSearchPageComponent) searchPage: NewSearchPageComponent;
|
|
|
|
@Input() simpleView: boolean = true;
|
2020-02-11 15:56:20 +01:00
|
|
|
quickFilter: { filter: Filter, selected: boolean, filterId: string, value: string } = {
|
|
|
|
filter: null,
|
|
|
|
selected: true,
|
|
|
|
filterId: "resultbestaccessright",
|
|
|
|
value: "Open Access"
|
|
|
|
};
|
2020-02-19 16:35:48 +01:00
|
|
|
@Input() includeOnlyResultsAndFilter: boolean = false;
|
2020-04-22 15:00:13 +02:00
|
|
|
@Input() showBreadcrumb:boolean = false;
|
2020-02-19 16:35:48 +01:00
|
|
|
@Output() searchPageUpdates = new EventEmitter();
|
2020-04-23 09:33:23 +02:00
|
|
|
@Input() showAdvancedSearchLink:boolean = true;
|
2020-03-30 16:24:56 +02:00
|
|
|
subs: any[]=[];
|
2020-01-31 16:12:51 +01:00
|
|
|
constructor(private route: ActivatedRoute, private _searchResearchResultsService: SearchResearchResultsService) {
|
|
|
|
this.results = [];
|
|
|
|
this.errorCodes = new ErrorCodes();
|
|
|
|
this.errorMessages = new ErrorMessagesComponent();
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
2020-02-19 16:35:48 +01:00
|
|
|
}
|
2020-01-31 16:12:51 +01:00
|
|
|
|
|
|
|
ngOnInit() {
|
2020-02-13 15:44:51 +01:00
|
|
|
//TODO add checks about which result types are enabled!
|
2020-03-30 16:24:56 +02:00
|
|
|
this.subs.push(this.route.data.subscribe((data: { envSpecific: EnvProperties }) => {
|
2020-01-31 16:12:51 +01:00
|
|
|
this.properties = data.envSpecific;
|
|
|
|
this.pagingLimit = data.envSpecific.pagingLimit;
|
|
|
|
this.isPiwikEnabled = data.envSpecific.enablePiwikTrack;
|
|
|
|
|
2020-02-19 16:35:48 +01:00
|
|
|
if (!this.simpleSearchLink) {
|
|
|
|
this.simpleSearchLink = this.properties.searchLinkToResults;
|
|
|
|
}
|
2020-01-31 16:12:51 +01:00
|
|
|
this.advancedSearchLink = this.properties.searchLinkToAdvancedResults;
|
2020-02-19 16:35:48 +01:00
|
|
|
this.searchUtils.baseUrl = (this.simpleView) ? this.simpleSearchLink : this.advancedSearchLink;
|
2020-02-11 15:56:20 +01:00
|
|
|
|
2020-03-30 16:24:56 +02:00
|
|
|
}));
|
2020-01-31 16:12:51 +01:00
|
|
|
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
var firstLoad = true;
|
2020-03-30 16:24:56 +02:00
|
|
|
this.subs.push(this.route.queryParams.subscribe(params => {
|
2020-03-28 01:33:55 +01:00
|
|
|
this.loadPaging = true;
|
2020-01-31 16:12:51 +01:00
|
|
|
if (params['page'] && this.searchUtils.page != params['page']) {
|
|
|
|
this.loadPaging = false;
|
|
|
|
this.oldTotalResults = this.searchUtils.totalResults;
|
|
|
|
}
|
|
|
|
var refine = true;
|
|
|
|
if (this.searchUtils.page != ((params['page'] === undefined) ? 1 : +params['page']) && this.filters && !firstLoad) {
|
|
|
|
refine = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
let page = (params['page'] === undefined) ? 1 : +params['page'];
|
|
|
|
this.searchUtils.page = (page <= 0) ? 1 : page;
|
|
|
|
|
|
|
|
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'] : '';
|
|
|
|
if (this.searchUtils.sortBy && this.searchUtils.sortBy != "resultdateofacceptance,descending" && this.searchUtils.sortBy != "resultdateofacceptance,ascending") {
|
|
|
|
this.searchUtils.sortBy = "";
|
|
|
|
}
|
|
|
|
this.selectedFields = [];
|
2020-02-17 15:19:14 +01:00
|
|
|
this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, this.refineFields, this.rangeFields, this.fieldIdsMap,this.customFilter,params, this.resultType, this.quickFilter);
|
2020-03-31 12:14:13 +02:00
|
|
|
this._getResults(this.searchPage.getSearchAPIQueryForAdvancedSearhFields(), this.searchUtils.page, this.searchUtils.size, this.searchUtils.sortBy, refine, this.searchPage.getSearchAPIQueryForRangeFields(params)+this.searchPage.getSearchAPIQueryForRefineFields(params, firstLoad));
|
2020-02-19 16:35:48 +01:00
|
|
|
firstLoad = false;
|
2020-03-30 16:24:56 +02:00
|
|
|
}));
|
2020-01-31 16:12:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
2020-03-30 16:24:56 +02:00
|
|
|
for(let sub of this.subs){
|
|
|
|
sub.unsubscribe();
|
|
|
|
}
|
2020-01-31 16:12:51 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 12:14:13 +02:00
|
|
|
public _getResults(parameters: string, page: number, size: number, sortBy: string, refine: boolean, refineFieldsFilterQuery = null) {
|
2020-01-31 16:12:51 +01:00
|
|
|
if (page > this.pagingLimit) {
|
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
if (page <= this.pagingLimit || this.searchUtils.status == this.errorCodes.LOADING) {
|
2020-02-24 14:45:22 +01:00
|
|
|
// if (parameters != null && parameters != '') {
|
|
|
|
// this.csvParams = "&fq=(" + this.resourcesQuery + " and (" + parameters + "))";
|
|
|
|
// } else {
|
|
|
|
// this.csvParams = "&fq=" + this.resourcesQuery;
|
|
|
|
// }
|
|
|
|
this.csvParams = (parameters ? ("&fq=("+parameters) : "") + (parameters ? ")" : "");
|
|
|
|
this.csvParams += (refineFieldsFilterQuery ? refineFieldsFilterQuery : "");
|
2020-01-31 16:12:51 +01:00
|
|
|
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
this.disableForms = true;
|
2020-02-19 16:35:48 +01:00
|
|
|
this.searchPageUpdates.emit({disableForms: this.disableForms,searchUtils: this.searchUtils});
|
2020-01-31 16:12:51 +01:00
|
|
|
this.results = [];
|
|
|
|
this.searchUtils.totalResults = 0;
|
2020-03-30 16:24:56 +02:00
|
|
|
this.subs.push(this._searchResearchResultsService.advancedSearchResults(this.resultType, parameters, page, size, sortBy, this.properties, (refine) ? this.searchPage.getRefineFieldsQuery() : null, this.searchPage.getFields(), refineFieldsFilterQuery)
|
|
|
|
.subscribe(
|
2020-01-31 16:12:51 +01:00
|
|
|
data => {
|
|
|
|
this.searchUtils.totalResults = data[0];
|
|
|
|
this.results = data[1];
|
|
|
|
if (refine) {
|
2020-03-30 16:24:56 +02:00
|
|
|
this.filters = this.searchPage.prepareFiltersToShow(data[2],this.searchUtils.totalResults);
|
2020-03-31 12:14:13 +02:00
|
|
|
this.rangeFilters = this.searchPage.prepareRangeFiltersToShow();
|
2020-02-19 16:35:48 +01:00
|
|
|
} else {
|
2020-02-17 15:19:14 +01:00
|
|
|
this.searchPage.buildPageURLParameters(this.filters, this.rangeFilters, false);
|
2020-01-31 16:12:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
|
|
|
if (this.searchUtils.totalResults == 0) {
|
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
|
|
|
}
|
|
|
|
this.disableForms = false;
|
2020-02-19 16:35:48 +01:00
|
|
|
this.searchPageUpdates.emit({disableForms: this.disableForms, searchUtils: this.searchUtils})
|
2020-01-31 16:12:51 +01:00
|
|
|
|
|
|
|
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 => {
|
|
|
|
this.handleError("Error getting " + this.getEntityName(this.resultType, true, true), err);
|
|
|
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
|
|
|
|
|
|
|
//TODO check erros (service not available, bad request)
|
|
|
|
// if( ){
|
|
|
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
|
|
|
// }
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
//this.searchUtils.status = errorCodes.NOT_AVAILABLE;
|
|
|
|
/*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;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
//this.searchPage.closeLoading();
|
|
|
|
this.disableForms = false;
|
2020-02-19 16:35:48 +01:00
|
|
|
this.searchPageUpdates.emit({disableForms: this.disableForms, searchUtils: this.searchUtils})
|
2020-01-31 16:12:51 +01:00
|
|
|
|
|
|
|
}
|
2020-03-30 16:24:56 +02:00
|
|
|
));
|
2020-01-31 16:12:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private handleError(message: string, error) {
|
|
|
|
console.error(this.getEntityName(this.resultType, true, true) + " advanced Search Page: " + message, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
public getEntityName(entityType: string, plural: boolean, full: boolean): string {
|
|
|
|
if (entityType == "publication") {
|
|
|
|
return "publication" + (plural ? "s" : "");
|
|
|
|
} else if (entityType == "dataset") {
|
|
|
|
return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
|
|
|
|
} else if (entityType == "software") {
|
|
|
|
return "software";
|
|
|
|
} else if (entityType == "other") {
|
|
|
|
return (full ? ("other research product" + (plural ? "s" : "")) : "other");
|
2020-02-11 12:58:51 +01:00
|
|
|
} else if (entityType == "result") {
|
|
|
|
return (full ? ("research outcome" + (plural ? "s" : "")) : "result");
|
2020-01-31 16:12:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|