Replace meta service import and use with meta and title from angular/platform-browser for user, publication, claimAdmin,claimsByToken, directLinking, linkingGeneric, myClaims, depositBySubject, depositBySubjectResult, deposit, depositResult, dataProvider, htmlProjectReport, organization, project, software, search, advancedSearchPage, searchPage and searchPageTableView component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51835 d315682c-612b-4755-9ff5-7f18f6832af3
2018-04-17 15:00:23 +02:00
|
|
|
import {Component, Input} from '@angular/core';
|
|
|
|
import {ViewChild, Output} from '@angular/core';
|
2019-04-24 14:31:01 +02:00
|
|
|
import {EventEmitter} from '@angular/core';
|
Replace meta service import and use with meta and title from angular/platform-browser for user, publication, claimAdmin,claimsByToken, directLinking, linkingGeneric, myClaims, depositBySubject, depositBySubjectResult, deposit, depositResult, dataProvider, htmlProjectReport, organization, project, software, search, advancedSearchPage, searchPage and searchPageTableView component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51835 d315682c-612b-4755-9ff5-7f18f6832af3
2018-04-17 15:00:23 +02:00
|
|
|
import {Location} from '@angular/common';
|
|
|
|
import {Router, ActivatedRoute} from '@angular/router';
|
|
|
|
import {Title, Meta} from '@angular/platform-browser';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
Replace meta service import and use with meta and title from angular/platform-browser for user, publication, claimAdmin,claimsByToken, directLinking, linkingGeneric, myClaims, depositBySubject, depositBySubjectResult, deposit, depositResult, dataProvider, htmlProjectReport, organization, project, software, search, advancedSearchPage, searchPage and searchPageTableView component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51835 d315682c-612b-4755-9ff5-7f18f6832af3
2018-04-17 15:00:23 +02:00
|
|
|
import {Filter, Value} from './searchHelperClasses.class';
|
2019-04-16 01:32:07 +02:00
|
|
|
import {SearchFields} from '../../utils/properties/searchFields';
|
2019-06-12 16:13:56 +02:00
|
|
|
import {SearchCustomFilter, SearchUtilsClass} from './searchUtils.class';
|
Replace meta service import and use with meta and title from angular/platform-browser for user, publication, claimAdmin,claimsByToken, directLinking, linkingGeneric, myClaims, depositBySubject, depositBySubjectResult, deposit, depositResult, dataProvider, htmlProjectReport, organization, project, software, search, advancedSearchPage, searchPage and searchPageTableView component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51835 d315682c-612b-4755-9ff5-7f18f6832af3
2018-04-17 15:00:23 +02:00
|
|
|
import {DOI, StringUtils} from '../../utils/string-utils.class';
|
2019-04-16 01:32:07 +02:00
|
|
|
import {RouterHelper} from '../../utils/routerHelper.class';
|
Replace meta service import and use with meta and title from angular/platform-browser for user, publication, claimAdmin,claimsByToken, directLinking, linkingGeneric, myClaims, depositBySubject, depositBySubjectResult, deposit, depositResult, dataProvider, htmlProjectReport, organization, project, software, search, advancedSearchPage, searchPage and searchPageTableView component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51835 d315682c-612b-4755-9ff5-7f18f6832af3
2018-04-17 15:00:23 +02:00
|
|
|
import {ModalLoading} from '../../utils/modal/loading.component';
|
|
|
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
|
|
|
import {PiwikService} from '../../utils/piwik/piwik.service';
|
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
2019-04-16 01:32:07 +02:00
|
|
|
import { SEOService } from '../../sharedComponents/SEO/SEO.service';
|
2019-04-24 14:31:01 +02:00
|
|
|
import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'search-page',
|
|
|
|
templateUrl: 'searchPage.component.html'
|
|
|
|
|
|
|
|
})
|
|
|
|
export class SearchPageComponent {
|
2018-04-11 10:59:01 +02:00
|
|
|
@Input() piwikSiteId = null;
|
2017-12-19 13:53:46 +01:00
|
|
|
@Input() pageTitle = "";
|
|
|
|
@Input() formPlaceholderText = "Type Keywords...";
|
|
|
|
@Input() results = [];
|
|
|
|
@Input() filters = [];
|
|
|
|
@Input() type:string = "";
|
|
|
|
@Input() entityType: string = "";
|
|
|
|
@Input() searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
|
|
|
@Output() queryChange = new EventEmitter();
|
|
|
|
@Input() baseUrl:string = '';
|
|
|
|
@Input() showResultCount:boolean = true;
|
|
|
|
@Input() showRefine:boolean = true;
|
|
|
|
@Input() refineFields = [];
|
|
|
|
@Input() csvParams: string;
|
|
|
|
@Input() csvPath: string;
|
|
|
|
@Input() advancedSearchLink: string = "";
|
2018-02-05 14:14:59 +01:00
|
|
|
@Input() advancedSearchParameters;
|
2017-12-19 13:53:46 +01:00
|
|
|
@Input() tableViewLink: string;
|
|
|
|
@Input() disableForms: boolean = false;
|
|
|
|
@Input() loadPaging: boolean = true;
|
|
|
|
@Input() oldTotalResults: number = 0;
|
|
|
|
@Input() tableView: boolean = false;
|
|
|
|
@Input() searchFormClass: string = "searchForm";
|
2018-02-05 14:14:59 +01:00
|
|
|
@Input() openaireLink: string;
|
2019-06-12 16:13:56 +02:00
|
|
|
@Input() customFilter:SearchCustomFilter= null;
|
2018-11-21 16:28:38 +01:00
|
|
|
@Input() sort: boolean = false;
|
2019-02-12 12:15:21 +01:00
|
|
|
@Input() mapUrl: string = "";
|
|
|
|
@Input() mapTooltipType: string ="content providers";
|
|
|
|
@Input() newQueryButton: boolean = true;
|
2019-04-05 19:21:23 +02:00
|
|
|
@Input() lastIndex: boolean = true;
|
2019-04-15 09:47:36 +02:00
|
|
|
@Input() hasPrefix: boolean = true;
|
2018-11-21 16:28:38 +01:00
|
|
|
//@Input() sortBy: string = "";
|
2017-12-19 13:53:46 +01:00
|
|
|
@ViewChild (ModalLoading) loading : ModalLoading ;
|
|
|
|
public fieldIdsMap;//: { [key:string]:{ name:string, operator:string, type:string, indexField:string, equalityOperator:string }};
|
|
|
|
private searchFieldsHelper:SearchFields = new SearchFields();
|
|
|
|
private queryParameters: Map<string, string> = new Map<string,string>();
|
|
|
|
private baseURLWithParameters:string = '';
|
|
|
|
private sub: any; piwiksub: any;
|
2018-07-19 12:52:29 +02:00
|
|
|
// public countFilters= 0;
|
2017-12-19 13:53:46 +01:00
|
|
|
public parameterNames:string[] =[];
|
|
|
|
public parameterValues:string[] =[];
|
|
|
|
public showUnknownFilters:boolean = false; // when a filter exists in query but has no results, so no filters returned from the query
|
|
|
|
//@ViewChild (SearchFilterModalComponent) searchFilterModal : SearchFilterModalComponent ;
|
2018-07-19 12:52:29 +02:00
|
|
|
// public currentFilter: Filter;
|
2018-02-05 14:14:59 +01:00
|
|
|
public csvLimit: number = 0;
|
|
|
|
public pagingLimit: number = 0;
|
2019-04-05 19:21:23 +02:00
|
|
|
public resultsPerPage: number = 10;
|
2018-02-05 14:14:59 +01:00
|
|
|
public isPiwikEnabled;
|
|
|
|
properties:EnvProperties;
|
2019-04-16 01:32:07 +02:00
|
|
|
public routerHelper:RouterHelper = new RouterHelper();
|
2018-12-03 13:32:33 +01:00
|
|
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
2017-12-19 13:53:46 +01:00
|
|
|
|
Replace meta service import and use with meta and title from angular/platform-browser for user, publication, claimAdmin,claimsByToken, directLinking, linkingGeneric, myClaims, depositBySubject, depositBySubjectResult, deposit, depositResult, dataProvider, htmlProjectReport, organization, project, software, search, advancedSearchPage, searchPage and searchPageTableView component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51835 d315682c-612b-4755-9ff5-7f18f6832af3
2018-04-17 15:00:23 +02:00
|
|
|
constructor (private route: ActivatedRoute,
|
|
|
|
private location: Location,
|
|
|
|
private _meta: Meta,
|
|
|
|
private _title: Title,
|
|
|
|
private _piwikService:PiwikService,
|
2018-11-14 11:38:53 +01:00
|
|
|
private router: Router,
|
|
|
|
private seoService: SEOService) {
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2018-02-05 14:14:59 +01:00
|
|
|
|
|
|
|
this.route.data
|
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
this.properties = data.envSpecific;
|
|
|
|
this.pagingLimit = data.envSpecific.pagingLimit;
|
|
|
|
this.csvLimit = data.envSpecific.csvLimit;
|
|
|
|
this.isPiwikEnabled = data.envSpecific.enablePiwikTrack;
|
|
|
|
if(typeof window !== 'undefined') {
|
|
|
|
this.updateUrl(data.envSpecific.baseLink+location.pathname);
|
|
|
|
}
|
|
|
|
if(typeof document !== 'undefined' && this.isPiwikEnabled){
|
2018-04-11 10:59:01 +02:00
|
|
|
this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe();
|
2018-02-05 14:14:59 +01:00
|
|
|
}
|
|
|
|
});
|
2019-04-24 14:31:01 +02:00
|
|
|
HelperFunctions.scroll();
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
// this.updateBaseUrlWithParameters(this.filters);
|
|
|
|
this.updateTitle(this.pageTitle);
|
Replace meta service import and use with meta and title from angular/platform-browser for user, publication, claimAdmin,claimsByToken, directLinking, linkingGeneric, myClaims, depositBySubject, depositBySubjectResult, deposit, depositResult, dataProvider, htmlProjectReport, organization, project, software, search, advancedSearchPage, searchPage and searchPageTableView component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51835 d315682c-612b-4755-9ff5-7f18f6832af3
2018-04-17 15:00:23 +02:00
|
|
|
var description = "Openaire, search, repositories, open access, type, content provider, funder, project, " + this.type + "," +this.pageTitle;
|
|
|
|
this.updateDescription(description);
|
2019-02-11 16:03:38 +01:00
|
|
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this.router.url,false);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
if(this.piwiksub){
|
|
|
|
this.piwiksub.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
2019-04-05 19:21:23 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
|
Replace meta service import and use with meta and title from angular/platform-browser for user, publication, claimAdmin,claimsByToken, directLinking, linkingGeneric, myClaims, depositBySubject, depositBySubjectResult, deposit, depositResult, dataProvider, htmlProjectReport, organization, project, software, search, advancedSearchPage, searchPage and searchPageTableView component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51835 d315682c-612b-4755-9ff5-7f18f6832af3
2018-04-17 15:00:23 +02:00
|
|
|
updateDescription(description:string) {
|
|
|
|
this._meta.updateTag({content:description},"name='description'");
|
|
|
|
this._meta.updateTag({content:description},"property='og:description'");
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-04-15 09:47:36 +02:00
|
|
|
|
Replace meta service import and use with meta and title from angular/platform-browser for user, publication, claimAdmin,claimsByToken, directLinking, linkingGeneric, myClaims, depositBySubject, depositBySubjectResult, deposit, depositResult, dataProvider, htmlProjectReport, organization, project, software, search, advancedSearchPage, searchPage and searchPageTableView component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51835 d315682c-612b-4755-9ff5-7f18f6832af3
2018-04-17 15:00:23 +02:00
|
|
|
updateTitle(title:string) {
|
2019-04-15 09:47:36 +02:00
|
|
|
let _title: string;
|
2019-04-15 10:08:59 +02:00
|
|
|
if(this.hasPrefix) {
|
2019-04-15 09:47:36 +02:00
|
|
|
let _prefix ="OpenAIRE | ";
|
|
|
|
_title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
|
|
|
|
} else {
|
|
|
|
_title = ((title.length > 50) ? title.substring(0, 50) : title);
|
|
|
|
}
|
Replace meta service import and use with meta and title from angular/platform-browser for user, publication, claimAdmin,claimsByToken, directLinking, linkingGeneric, myClaims, depositBySubject, depositBySubjectResult, deposit, depositResult, dataProvider, htmlProjectReport, organization, project, software, search, advancedSearchPage, searchPage and searchPageTableView component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51835 d315682c-612b-4755-9ff5-7f18f6832af3
2018-04-17 15:00:23 +02:00
|
|
|
this._title.setTitle(_title);
|
|
|
|
this._meta.updateTag({content:_title},"property='og:title'");
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-04-15 09:47:36 +02:00
|
|
|
|
Replace meta service import and use with meta and title from angular/platform-browser for user, publication, claimAdmin,claimsByToken, directLinking, linkingGeneric, myClaims, depositBySubject, depositBySubjectResult, deposit, depositResult, dataProvider, htmlProjectReport, organization, project, software, search, advancedSearchPage, searchPage and searchPageTableView component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51835 d315682c-612b-4755-9ff5-7f18f6832af3
2018-04-17 15:00:23 +02:00
|
|
|
updateUrl(url:string) {
|
|
|
|
this._meta.updateTag({content:url},"property='og:url'");
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2019-04-05 19:21:23 +02:00
|
|
|
public getQueryParamsFromUrl(params) {
|
|
|
|
this.queryParameters = new Map<string,string>();
|
|
|
|
for(let i=0; i< this.refineFields.length ; i++) {
|
|
|
|
let filterId = this.refineFields[i];
|
|
|
|
if (params[filterId] != undefined) {
|
|
|
|
this.queryParameters.set(filterId, StringUtils.URIDecode(params[filterId]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.queryParameters;
|
|
|
|
}
|
|
|
|
|
2018-04-25 15:30:59 +02:00
|
|
|
public getQueryParametersFromUrl(params){ // called by ngOnInit function of search find pages
|
2017-12-19 13:53:46 +01:00
|
|
|
// var parameters = "";
|
|
|
|
var allFqs = "";
|
|
|
|
|
|
|
|
this.queryParameters = new Map<string,string>();
|
|
|
|
for(var i=0; i< this.refineFields.length ; i++){
|
|
|
|
var filterId = this.refineFields[i];
|
|
|
|
|
|
|
|
if(params[filterId] != undefined) {
|
|
|
|
this.queryParameters.set(filterId, StringUtils.URIDecode(params[filterId]));
|
|
|
|
let values = (StringUtils.URIDecode(this.queryParameters.get(filterId))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1);
|
|
|
|
var countvalues = 0;
|
|
|
|
var fq = "";
|
|
|
|
for(let value of values) {
|
|
|
|
countvalues++;
|
|
|
|
var paramId = this.fieldIdsMap[filterId].param;
|
|
|
|
// parameters+='&' + paramId+ '='+ value;//+"&" + this.fieldIdsMap[paramId].operator + "="+((countvalues == 1)?"and":"or");
|
2018-05-08 12:36:42 +02:00
|
|
|
fq+=(fq.length > 0 ? " " + "or" + " ":"" ) + filterId +" exact " +(value);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
if(countvalues > 0){
|
2018-05-08 12:36:42 +02:00
|
|
|
fq="&fq="+StringUtils.URIEncode(fq);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
allFqs += fq;
|
|
|
|
}
|
2018-04-26 14:20:32 +02:00
|
|
|
}
|
2019-06-12 16:13:56 +02:00
|
|
|
if(this.customFilter){
|
|
|
|
allFqs+= "&fq="+StringUtils.URIEncode(this.customFilter.queryFieldName + " exact " + StringUtils.quote((this.customFilter.valueId )));
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
var keyword = params['keyword'];
|
|
|
|
var doiQuery = "";
|
|
|
|
var keywordQuery = "";
|
|
|
|
if((keyword && keyword.length > 0)){
|
2019-02-12 15:33:00 +01:00
|
|
|
if((this.type == 'publications' ||this.type == 'research data' || this.type == 'software' || this.type == 'other research products')){
|
2017-12-19 13:53:46 +01:00
|
|
|
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){
|
|
|
|
doiQuery += "&"+doisParams;
|
|
|
|
}else {
|
|
|
|
keywordQuery += "&q="+StringUtils.URIEncode(keyword);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
keywordQuery += "&q="+StringUtils.URIEncode(keyword);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (doiQuery.length > 0 ? doiQuery:keywordQuery) + allFqs;
|
|
|
|
}
|
2018-04-25 15:30:59 +02:00
|
|
|
public getIndexQueryParametersFromUrl(params){ // called by ngOnInit function of search pages that request 'resources'
|
2017-12-19 13:53:46 +01:00
|
|
|
// var parameters = "";
|
|
|
|
var allFqs = "";
|
|
|
|
|
|
|
|
for(var i=0; i< this.refineFields.length ; i++){
|
|
|
|
var filterId = this.refineFields[i];
|
|
|
|
var fq = "";
|
|
|
|
if(params[filterId] != undefined) {
|
|
|
|
this.queryParameters.set(filterId,decodeURIComponent(params[filterId]));
|
|
|
|
let values = (decodeURIComponent(this.queryParameters.get(filterId))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1);
|
|
|
|
var countvalues = 0
|
|
|
|
for(let value of values) {
|
|
|
|
countvalues++;
|
|
|
|
// parameters+= ((countvalues == 1)?" and (":" or ")+ filterId+ '='+ value;
|
|
|
|
fq+=(fq.length > 0 ? " " + "or" + " ":"" ) + filterId + " exact " + value;//StringUtils.quote(value);
|
|
|
|
}
|
|
|
|
// parameters+= " ) ";
|
|
|
|
if(countvalues > 0){
|
2018-05-08 12:36:42 +02:00
|
|
|
fq="&fq="+StringUtils.URIEncode(fq);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
allFqs += fq;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
var keyword = params['keyword'];
|
|
|
|
var doiQuery = "";
|
|
|
|
var keywordQuery = "";
|
|
|
|
if((keyword && keyword.length > 0)){
|
2019-02-12 15:33:00 +01:00
|
|
|
if((this.type == 'publications' ||this.type == 'research data' || this.type == 'software' || this.type == 'other research products')){
|
2017-12-19 13:53:46 +01:00
|
|
|
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){
|
|
|
|
doiQuery += "&"+doisParams;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
keywordQuery += "and ("+StringUtils.quote(StringUtils.URIEncode(keyword)) +")";
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (doiQuery.length > 0 ? doiQuery:keywordQuery) + allFqs;
|
|
|
|
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Mark as check the new filters that are selected, when you get them from search
|
|
|
|
*/
|
|
|
|
public checkSelectedFilters(filters:Filter[]){
|
|
|
|
this.filters = filters;
|
|
|
|
for(var i=0; i< filters.length ; i++){
|
|
|
|
var filter:Filter = filters[i];
|
|
|
|
filter.countSelectedValues = 0;
|
|
|
|
if(this.queryParameters.get(filter.filterId) != undefined) {
|
|
|
|
let values = (decodeURIComponent(this.queryParameters.get(filter.filterId))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1);
|
|
|
|
for(let filterValue of filter.values) {
|
|
|
|
if(values.indexOf(StringUtils.quote(filterValue.id)) > -1) {
|
|
|
|
filterValue.selected = true;
|
|
|
|
filter.countSelectedValues++;
|
|
|
|
}else{
|
|
|
|
filterValue.selected = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
for(let filterValue of filter.values) {
|
|
|
|
filterValue.selected = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.filterFilterValues(this.filters);
|
|
|
|
return filters;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* For Funder filters - if funder selected
|
|
|
|
*/
|
|
|
|
public filterFilterValues(filters:Filter[]){
|
|
|
|
var funders = [];
|
|
|
|
var funder_prefix = [];
|
|
|
|
for(var i=0; i< filters.length ; i++){
|
|
|
|
|
|
|
|
var filter:Filter = filters[i];
|
|
|
|
// console.log(filter.filterId);
|
|
|
|
if(filter.filterId.indexOf("funder")!=-1 && this.queryParameters.get(filter.filterId) != undefined) {
|
|
|
|
let funders = (decodeURIComponent(this.queryParameters.get(filter.filterId))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1);
|
|
|
|
for(let funder of funders) {
|
|
|
|
funder_prefix.push(StringUtils.unquote(funder).split("____")[0]);
|
|
|
|
}
|
|
|
|
// console.log(funder_prefix );
|
|
|
|
}else if(filter.filterId.indexOf("funding")!=-1){
|
|
|
|
// console.log(" funding: "+filter.filterId );
|
|
|
|
var filteredValues = []
|
|
|
|
for(let filterValue of filter.values) {
|
|
|
|
var value_prefix = filterValue.id.split("____")[0];
|
|
|
|
// console.log("Value prefix: "+value_prefix );
|
|
|
|
if(funder_prefix.indexOf(value_prefix)!=-1){
|
|
|
|
// console.log("here" + value_prefix);
|
|
|
|
filteredValues.push(filterValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if(filteredValues.length > 0){
|
|
|
|
filter.values = filteredValues;
|
|
|
|
}
|
2018-04-26 14:20:32 +02:00
|
|
|
}
|
2019-06-13 14:31:39 +02:00
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
return filters;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Update the url with proper parameters. This is used as base url in Paging Component
|
|
|
|
*/
|
|
|
|
public updateBaseUrlWithParameters(filters:Filter[]){
|
|
|
|
this.baseURLWithParameters = this.baseUrl + this.createUrlParameters(filters,false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*Get The filters and create url parameters
|
|
|
|
*/
|
|
|
|
private createUrlParameters(filters:Filter[], includePage:boolean){
|
|
|
|
var allLimits="";//location.search.slice(1);
|
|
|
|
this.queryParameters = new Map<string,string>();
|
|
|
|
this.parameterNames.splice(0,this.parameterNames.length);
|
|
|
|
this.parameterValues.splice(0,this.parameterValues.length);
|
|
|
|
|
|
|
|
for (let filter of filters){
|
|
|
|
var filterLimits="";
|
2019-06-13 14:31:39 +02:00
|
|
|
if(filter.countSelectedValues > 0 ){
|
2017-12-19 13:53:46 +01:00
|
|
|
for (let value of filter.values){
|
|
|
|
if(value.selected == true){
|
2018-05-08 12:36:42 +02:00
|
|
|
filterLimits+=((filterLimits.length == 0)?'':',') +'"'+ (value.id)+'"';
|
2018-02-05 14:14:59 +01:00
|
|
|
}
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
this.queryParameters.set(filter.filterId,filterLimits);
|
|
|
|
if(filterLimits.length > 0){
|
|
|
|
this.parameterNames.push(filter.filterId);
|
|
|
|
this.parameterValues.push(filterLimits);
|
|
|
|
}
|
|
|
|
allLimits+=(allLimits.length==0?"?":"&")+((filterLimits.length == 0 )?'':filter.filterId + '='+ filterLimits) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(this.searchUtils.keyword.length > 0 ){
|
|
|
|
allLimits+=(allLimits.length==0?"?":"&")+'keyword=' + this.searchUtils.keyword;
|
|
|
|
this.parameterNames.push("keyword");
|
|
|
|
this.parameterValues.push(this.searchUtils.keyword);
|
|
|
|
}
|
|
|
|
if(this.searchUtils.page != 1 && includePage){
|
|
|
|
allLimits+=((allLimits.length == 0)?'?':'&') + 'page=' + this.searchUtils.page;
|
|
|
|
}
|
2019-04-05 19:21:23 +02:00
|
|
|
if(this.searchUtils.size != this.resultsPerPage) {
|
2018-11-21 16:28:38 +01:00
|
|
|
allLimits+=((allLimits.length == 0)?'?':'&') + 'size=' + this.searchUtils.size;
|
|
|
|
this.parameterNames.push("size");
|
|
|
|
this.parameterValues.push(""+this.searchUtils.size);
|
|
|
|
}
|
|
|
|
if(this.sort && this.searchUtils.sortBy) {
|
|
|
|
allLimits+=((allLimits.length == 0)?'?':'&') + 'sortBy=' + this.searchUtils.sortBy;
|
|
|
|
this.parameterNames.push("sortBy");
|
|
|
|
this.parameterValues.push(this.searchUtils.sortBy);
|
|
|
|
} /*else {
|
|
|
|
let index: number = this.parameterNames.findIndex(function(element) {
|
|
|
|
return element == "sortBy";
|
|
|
|
});
|
|
|
|
console.info("index of sortby: "+index);
|
|
|
|
if(index >= 0) {
|
|
|
|
console.info("------remove sortBy------");
|
|
|
|
this.parameterNames.splice(index, 1);
|
|
|
|
this.parameterValues.splice(index, 1);
|
|
|
|
}
|
|
|
|
}*/
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
return allLimits;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
2018-04-25 15:30:59 +02:00
|
|
|
private createSearchQueryParameters(filters:Filter[]){ // called by goTo, result emited to and used by search find pages
|
2017-12-19 13:53:46 +01:00
|
|
|
var allFqs = "";
|
|
|
|
for (let filter of filters){
|
2019-06-13 14:31:39 +02:00
|
|
|
if(filter.countSelectedValues > 0 ){
|
2017-12-19 13:53:46 +01:00
|
|
|
var fq = "";
|
|
|
|
var count_selected=0;
|
|
|
|
for (let value of filter.values){
|
|
|
|
if(value.selected == true){
|
|
|
|
count_selected++;
|
2018-05-08 12:36:42 +02:00
|
|
|
fq+=(fq.length > 0 ? " " + filter.filterOperator + " ":"" ) + filter.filterId + " exact " + StringUtils.quote((value.id));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
2019-06-13 14:31:39 +02:00
|
|
|
|
2018-05-08 12:36:42 +02:00
|
|
|
fq="&fq="+StringUtils.URIEncode(fq);
|
2017-12-19 13:53:46 +01:00
|
|
|
allFqs += fq;
|
|
|
|
}
|
2018-04-26 14:20:32 +02:00
|
|
|
}
|
2019-06-13 14:31:39 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
var doiQuery = "";
|
|
|
|
var keywordQuery = "";
|
|
|
|
if((this.searchUtils.keyword && this.searchUtils.keyword.length > 0)){
|
2019-02-12 15:33:00 +01:00
|
|
|
if((this.type == 'publications' ||this.type == 'research data' || this.type == 'software' || this.type == 'other research products')){
|
2017-12-19 13:53:46 +01:00
|
|
|
var DOIs:string[] = DOI.getDOIsFromString(this.searchUtils.keyword);
|
|
|
|
var doisParams = "";
|
|
|
|
|
|
|
|
for(var i =0 ;i < DOIs.length; i++){
|
|
|
|
doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"';
|
|
|
|
}
|
|
|
|
if(doisParams.length > 0){
|
|
|
|
doiQuery += "&"+doisParams;
|
|
|
|
}else{
|
|
|
|
keywordQuery += "&q="+StringUtils.URIEncode(this.searchUtils.keyword);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
keywordQuery += "&q="+StringUtils.URIEncode(this.searchUtils.keyword);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (doiQuery.length > 0 ? doiQuery:keywordQuery) + allFqs;
|
|
|
|
|
|
|
|
}
|
2018-04-25 15:30:59 +02:00
|
|
|
private createIndexQueryParameters(filters:Filter[]){ // called by goTo, result emited to and used by search pages that request 'resources'
|
2017-12-19 13:53:46 +01:00
|
|
|
var allFqs = "";
|
|
|
|
for (let filter of filters){
|
|
|
|
if(filter.countSelectedValues > 0){
|
|
|
|
var count_selected=0;
|
|
|
|
var fq = "";
|
|
|
|
for (let value of filter.values){
|
|
|
|
if(value.selected == true){
|
|
|
|
count_selected++;
|
2018-05-10 09:52:55 +02:00
|
|
|
fq+=(fq.length > 0 ? " " + filter.filterOperator + " ":"" ) + filter.filterId + " exact " + (StringUtils.quote(value.id));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(count_selected > 0){
|
2018-05-08 12:36:42 +02:00
|
|
|
fq="&fq="+StringUtils.URIEncode(fq);
|
2017-12-19 13:53:46 +01:00
|
|
|
allFqs += fq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var doiQuery = "";
|
|
|
|
var keywordQuery = "";
|
|
|
|
if((this.searchUtils.keyword && this.searchUtils.keyword.length > 0)){
|
2019-02-12 15:33:00 +01:00
|
|
|
if((this.type == 'publications' ||this.type == 'research data' || this.type == 'software' || this.type == 'other research products')){
|
2017-12-19 13:53:46 +01:00
|
|
|
var DOIs:string[] = DOI.getDOIsFromString(this.searchUtils.keyword);
|
|
|
|
var doisParams = "";
|
|
|
|
for(var i =0 ;i < DOIs.length; i++){
|
|
|
|
doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"';
|
|
|
|
}
|
|
|
|
if(doisParams.length > 0){
|
|
|
|
doiQuery += "&"+doisParams;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
keywordQuery += " and ("+StringUtils.quote(StringUtils.URIEncode(this.searchUtils.keyword)) +")"
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (doiQuery.length > 0 ? doiQuery:keywordQuery) + allFqs;
|
|
|
|
|
2018-04-25 15:30:59 +02:00
|
|
|
}
|
2018-07-19 12:52:29 +02:00
|
|
|
public countFilters():number{
|
|
|
|
var filters=0;
|
2017-12-19 13:53:46 +01:00
|
|
|
this.showUnknownFilters = false;
|
|
|
|
for (let filter of this.filters){
|
|
|
|
if(filter.countSelectedValues > 0){
|
2018-07-19 12:52:29 +02:00
|
|
|
filters+=filter.countSelectedValues;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(this.searchUtils.keyword.length > 0 ){
|
2018-07-19 12:52:29 +02:00
|
|
|
filters++;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
if(this.queryParameters.keys() && this.searchUtils.totalResults == 0 && this.searchUtils.status !=errorCodes.LOADING ){
|
2019-02-12 12:15:21 +01:00
|
|
|
if(this.newQueryButton) {
|
|
|
|
this.showUnknownFilters = true;
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2018-07-19 12:52:29 +02:00
|
|
|
return filters;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
private clearKeywords(){
|
|
|
|
if(this.searchUtils.keyword.length > 0 ){
|
|
|
|
this.searchUtils.keyword ='';
|
|
|
|
}
|
|
|
|
this.goTo(1);
|
|
|
|
}
|
|
|
|
private clearFilters(){
|
|
|
|
for (var i =0 ; i < this.filters.length; i++){
|
|
|
|
for (var j=0; j < this.filters[i].countSelectedValues; j++){
|
|
|
|
if(this.filters[i].values[j].selected){
|
|
|
|
this.filters[i].values[j].selected = false;
|
|
|
|
}
|
|
|
|
this.filters[i].countSelectedValues = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.clearKeywords();
|
|
|
|
|
|
|
|
}
|
|
|
|
private removeFilter(value:Value,filter:Filter){
|
|
|
|
filter.countSelectedValues--;
|
|
|
|
if(value.selected == true){
|
|
|
|
value.selected = false;
|
|
|
|
}
|
|
|
|
this.goTo(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
goTo(page:number = 1){
|
|
|
|
this.searchUtils.page = page;
|
|
|
|
var urlParameters = this.createUrlParameters(this.filters,true);
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.info("urlParams : "+urlParameters);
|
2017-12-19 13:53:46 +01:00
|
|
|
this.updateBaseUrlWithParameters(this.filters);
|
|
|
|
var queryParameters = this.createSearchQueryParameters(this.filters);
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.info("queryParams : "+queryParameters);
|
2018-04-25 15:30:59 +02:00
|
|
|
var indexQuery = this.createIndexQueryParameters(this.filters);
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-04-16 01:32:07 +02:00
|
|
|
//this.location.go(location.pathname,urlParameters);
|
|
|
|
this.router.navigate( [this.baseUrl], { queryParams: this.routerHelper.createQueryParams(this.parameterNames, this.parameterValues) } );
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
/* Code For Piwik*/
|
|
|
|
if (typeof localStorage !== 'undefined') {
|
|
|
|
localStorage.setItem('previousRoute', this.router.url);
|
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
if(this.isPiwikEnabled && (typeof document !== 'undefined')){
|
2018-04-11 10:59:01 +02:00
|
|
|
this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe();
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
/* End Piwik Code */
|
|
|
|
this.queryChange.emit({
|
|
|
|
value: queryParameters,
|
2019-04-05 19:21:23 +02:00
|
|
|
index:indexQuery,
|
|
|
|
params: this.queryParameters
|
2017-12-19 13:53:46 +01:00
|
|
|
});
|
2019-04-24 14:31:01 +02:00
|
|
|
HelperFunctions.scroll();
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
filterChanged($event){
|
|
|
|
this.goTo(1);
|
|
|
|
}
|
|
|
|
keywordChanged($event) {
|
|
|
|
this.searchUtils.keyword = $event.value;
|
|
|
|
this.goTo(1);
|
|
|
|
}
|
|
|
|
|
2018-11-21 16:28:38 +01:00
|
|
|
sizeChanged($event) {
|
|
|
|
this.searchUtils.size = $event.value;
|
|
|
|
this.goTo(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sortByChanged($event) {
|
|
|
|
this.searchUtils.sortBy = $event.value;
|
|
|
|
this.goTo(1);
|
|
|
|
}
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
/*
|
|
|
|
* Get A sub-array of this.refineFields array, which contains the ids of the selected filters
|
|
|
|
*/
|
|
|
|
public getSelectedFilters():string[] {
|
|
|
|
var selected:string[] = [];
|
|
|
|
for(var i=0; i < this.filters.length; i++){
|
|
|
|
var filter:Filter = this.filters[i];
|
|
|
|
if(filter.countSelectedValues > 0){
|
|
|
|
selected.push(filter.filterId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return selected;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Get A sub-array of this.refineFields array, which contains the ids of the selected parameters
|
|
|
|
*/
|
|
|
|
private getSelectedParameters():string[] {
|
|
|
|
var selected:string[] = [];
|
|
|
|
var params:string[] = Object.keys(this.queryParameters);
|
2018-05-09 15:54:30 +02:00
|
|
|
|
|
|
|
for(var i=0; i < this.refineFields.length; i++){
|
|
|
|
if(this.queryParameters.get(this.refineFields[i])!= undefined ){
|
|
|
|
selected.push(this.refineFields[i]);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return selected;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Get A sub-array of this.refineFields array, which hides hidden fields (e.g Funding level 0,1,2,..), and contains those that depend on another fields (e.g Funding level 0 if Funder is selected )
|
|
|
|
*/
|
|
|
|
public getFields():string[] {
|
|
|
|
var selected_filters:string[] = this.getSelectedFilters();
|
|
|
|
if(selected_filters.length == 0){
|
|
|
|
selected_filters = this.getSelectedParameters();
|
|
|
|
}
|
|
|
|
var fields:string[] = [];
|
|
|
|
for(var i =0 ; i < this.refineFields.length;i++){
|
|
|
|
var dependentTo = this.searchFieldsHelper.DEPENDENT_FIELDS[this.refineFields[i]];
|
|
|
|
|
|
|
|
//if filter is not marked as hidden OR it is hidden but it is dependent to a field that it IS selected
|
|
|
|
if(this.searchFieldsHelper.HIDDEN_FIELDS.indexOf(this.refineFields[i]) == -1 || (selected_filters.indexOf(dependentTo) != -1) || (selected_filters.indexOf(this.refineFields[i]) != -1) ){
|
|
|
|
fields.push(this.refineFields[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fields;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Get a query string of all fields, that want to get from search (e.g. &fields=funderid&fields=projectstartyear&...))
|
|
|
|
*/
|
|
|
|
public getRefineFieldsQuery():string{
|
|
|
|
|
|
|
|
var fields:string[] = this.getFields();
|
|
|
|
var fieldsStr = ""
|
|
|
|
for(var i =0 ; i < fields.length ;i++){
|
|
|
|
fieldsStr+="&fields="+fields[i];
|
|
|
|
}
|
|
|
|
return "&refine=true"+fieldsStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// for loading
|
|
|
|
public openLoading(){
|
|
|
|
if(this.loading){
|
|
|
|
this.loading.open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public closeLoading(){
|
|
|
|
if(this.loading){
|
|
|
|
this.loading.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getSelectedValues(filter):any{
|
|
|
|
var selected = [];
|
|
|
|
if(filter.countSelectedValues >0){
|
|
|
|
for (var i=0; i < filter.values.length; i++){
|
|
|
|
if(filter.values[i].selected){
|
|
|
|
selected.push(filter.values[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return selected;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|