2020-10-20 11:11:15 +02:00
import { ChangeDetectorRef , Component , ElementRef , Input , Output , ViewChild } from '@angular/core' ;
2020-01-31 16:12:51 +01:00
import { Location } from '@angular/common' ;
import { ActivatedRoute , Router } from '@angular/router' ;
import { Meta , Title } from '@angular/platform-browser' ;
import { AdvancedField , Filter , Value } from './searchHelperClasses.class' ;
import { SearchCustomFilter , SearchUtilsClass } from './searchUtils.class' ;
import { ModalLoading } from '../../utils/modal/loading.component' ;
2020-04-03 18:00:19 +02:00
import { Dates , Identifier , StringUtils } from '../../utils/string-utils.class' ;
2020-01-31 16:12:51 +01:00
import { ErrorCodes } from '../../utils/properties/errorCodes' ;
import { RouterHelper } from '../../utils/routerHelper.class' ;
import { PiwikService } from '../../utils/piwik/piwik.service' ;
import { EnvProperties } from '../../utils/properties/env-properties' ;
import { SEOService } from '../../sharedComponents/SEO/SEO.service' ;
import { HelperService } from "../../utils/helper/helper.service" ;
import { SearchFields } from "../../utils/properties/searchFields" ;
2020-02-04 14:27:42 +01:00
import { RefineResultsUtils } from "../../services/servicesUtils/refineResults.class" ;
2020-02-17 15:19:14 +01:00
import { RangeFilter } from "../../utils/rangeFilter/rangeFilterHelperClasses.class" ;
2020-03-12 18:03:35 +01:00
import { ZenodoInformationClass } from "../../deposit/utils/zenodoInformation.class" ;
2020-04-27 10:14:05 +02:00
import { Breadcrumb } from "../../utils/breadcrumbs/breadcrumbs.component" ;
2020-05-21 15:17:28 +02:00
import { HelperFunctions } from "../../utils/HelperFunctions.class" ;
2020-07-10 10:37:17 +02:00
import { properties } from "../../../../environments/environment" ;
2020-08-04 09:25:32 +02:00
import { AlertModal } from "../../utils/modal/alert" ;
2020-11-11 15:43:13 +01:00
import { Subscriber } from "rxjs" ;
2020-01-31 16:12:51 +01:00
2020-03-24 16:40:51 +01:00
declare var UIkit : any ;
2020-01-31 16:12:51 +01:00
@Component ( {
selector : 'new-search-page' ,
templateUrl : 'newSearchPage.component.html'
} )
export class NewSearchPageComponent {
2020-03-24 16:40:51 +01:00
@ViewChild ( 'offcanvas_element' ) offcanvasElement : ElementRef ;
2020-01-31 16:12:51 +01:00
@Input ( ) piwikSiteId = null ;
@Input ( ) hasPrefix : boolean = true ;
@Input ( ) pageTitle = "" ;
@Input ( ) results = [ ] ;
@Input ( ) type ;
@Input ( ) entityType ;
@Input ( ) searchUtils : SearchUtilsClass = new SearchUtilsClass ( ) ;
@Input ( ) fieldIds : string [ ] ;
@Input ( ) fieldIdsMap ; //:{ [key:string]:{ name:string, operator:string, type:string, indexField:string, equalityOperator:string }} ;
@Input ( ) selectedFields : AdvancedField [ ] ;
@ViewChild ( ModalLoading ) loading : ModalLoading ;
@Input ( ) csvParams : string ;
@Input ( ) csvPath : string ;
@Input ( ) simpleSearchLink : string = "" ;
@Input ( ) advancedSearchLink : string = "" ;
@Input ( ) disableForms : boolean = false ;
[Trunk | Library]:
1. searchUtils.class.ts: In SearchUtilsClass added field "refineStatus:number = 1;" for refine queries.
2. searchResultsPerPage.component.ts & searchSorting.component.ts: [Bug fix] In EventEmitter (value change), emit raw value, not object with field "value".
3. searchDataProviders.component.ts & searchOrganizations.component.ts & searchProjects.component.ts & searchResearchResults.component.ts:
a. Add subscriptions in array to unsubscribe in ngOnDestroy.
b. Get properties from environment (no service needed).
c. Separate queries for refine and results.
d. Do not call refine query when page, results per page, sortBy change (there is still a bug here).
e. For refine query, added field "disableRefineForms" default set to false - passed in <new-search-page>.
4. newSearchPage.component.html:
a. Disable forms when "disableForms" or "disableRefineForms" is true.
b. Do not show filters, until results query returns, but show results while refine is loading.
c. Deleted old, unused code.
5. newSearchPage.component.ts:
a. Added fields "@Input() disableRefineForms: boolean = false;", "@Input() sortedByChanged: string = "";", "@Input() resultsPerPageChanged: number;"
b. When results per page or sortBy change, do not upadate immediately searchUtils values - do not query for refine when these change (there is still a bug here).
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59155 d315682c-612b-4755-9ff5-7f18f6832af3
2020-07-21 15:48:55 +02:00
@Input ( ) disableRefineForms : boolean = false ;
2020-01-31 16:12:51 +01:00
@Input ( ) loadPaging : boolean = true ;
@Input ( ) oldTotalResults : number = 0 ;
@Input ( ) openaireLink : string ;
2020-04-03 18:00:19 +02:00
@Input ( ) customFilter : SearchCustomFilter ;
2020-05-05 10:46:10 +02:00
@Input ( ) sort : boolean = true ;
[Trunk | Library]:
1. searchUtils.class.ts: In SearchUtilsClass added field "refineStatus:number = 1;" for refine queries.
2. searchResultsPerPage.component.ts & searchSorting.component.ts: [Bug fix] In EventEmitter (value change), emit raw value, not object with field "value".
3. searchDataProviders.component.ts & searchOrganizations.component.ts & searchProjects.component.ts & searchResearchResults.component.ts:
a. Add subscriptions in array to unsubscribe in ngOnDestroy.
b. Get properties from environment (no service needed).
c. Separate queries for refine and results.
d. Do not call refine query when page, results per page, sortBy change (there is still a bug here).
e. For refine query, added field "disableRefineForms" default set to false - passed in <new-search-page>.
4. newSearchPage.component.html:
a. Disable forms when "disableForms" or "disableRefineForms" is true.
b. Do not show filters, until results query returns, but show results while refine is loading.
c. Deleted old, unused code.
5. newSearchPage.component.ts:
a. Added fields "@Input() disableRefineForms: boolean = false;", "@Input() sortedByChanged: string = "";", "@Input() resultsPerPageChanged: number;"
b. When results per page or sortBy change, do not upadate immediately searchUtils values - do not query for refine when these change (there is still a bug here).
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59155 d315682c-612b-4755-9ff5-7f18f6832af3
2020-07-21 15:48:55 +02:00
@Input ( ) sortedByChanged : string = "" ;
@Input ( ) resultsPerPageChanged : number ;
2020-01-31 16:12:51 +01:00
@Input ( ) searchFormClass : string = "searchForm" ;
//From simple:
2020-02-17 15:19:14 +01:00
@Input ( ) rangeFilters : RangeFilter [ ] = [ ] ;
@Input ( ) rangeFields : string [ ] [ ] = [ ] ;
2020-01-31 16:12:51 +01:00
@Input ( ) refineFields = [ ] ;
2020-07-21 14:41:08 +02:00
@Input ( ) filters :Filter [ ] = [ ] ;
2020-02-11 12:58:51 +01:00
selectedFilters : number = 0 ;
2020-02-17 15:19:14 +01:00
selectedRangeFilters : number = 0 ;
2020-01-31 16:12:51 +01:00
private searchFieldsHelper : SearchFields = new SearchFields ( ) ;
@Input ( ) newQueryButton : boolean = true ;
public showUnknownFilters : boolean = false ; // when a filter exists in query but has no results, so no filters returned from the query
2020-02-04 17:33:46 +01:00
URLCreatedFilters : Filter [ ] = [ ] ;
2020-02-17 15:19:14 +01:00
URLCreatedRangeFilters : RangeFilter [ ] = [ ] ;
2020-01-31 16:12:51 +01:00
@Input ( ) showRefine : boolean = true ;
@Input ( ) tableViewLink : string ;
@Input ( ) usedBy : string = "search" ;
2020-03-12 18:03:35 +01:00
@Input ( ) public zenodoInformation : ZenodoInformationClass = new ZenodoInformationClass ( ) ;
@Input ( ) showLastIndex : boolean = true ;
2020-01-31 16:12:51 +01:00
@Input ( ) showResultCount : boolean = true ;
2020-02-17 15:19:14 +01:00
@Input ( ) showMoreFilterValuesInline : boolean = true ;
2020-02-24 14:45:22 +01:00
@Input ( ) filterValuesNum : number = 6 ;
2020-01-31 16:12:51 +01:00
@Input ( ) keywordFields = [ ] ;
@Input ( ) simpleView : boolean = true ;
@Input ( ) formPlaceholderText = "Type Keywords..." ;
2020-10-20 13:21:37 +02:00
@Input ( ) resultTypes :Filter = null ;
2020-10-20 11:11:15 +02:00
resultTypeOptions = { "publications" : { "id" : "publication" , "name" : "Publications" } , "datasets" : { "id" : "dataset" , "name" : "Research data" } ,
"software" : { "id" : "software" , "name" : "Software" } , "other" : { "id" : "other" , "name" : " Other research products" } } ;
2020-06-01 11:02:16 +02:00
selectedTypesNum = 0 ;
2020-02-19 16:35:48 +01:00
@Input ( ) quickFilter : { filter : Filter , selected : boolean , filterId : string , value : string } ;
@Input ( ) includeOnlyResultsAndFilter :boolean = false ;
2020-04-22 15:00:13 +02:00
@Input ( ) showBreadcrumb :boolean = false ;
2020-03-16 11:06:47 +01:00
@Input ( ) lastIndex : boolean = true ;
2020-07-10 10:37:17 +02:00
public dashboard : boolean = properties . isDashboard ;
2020-03-16 11:06:47 +01:00
2020-11-11 15:43:13 +01:00
subscriptions = [ ] ;
2020-01-31 16:12:51 +01:00
public parameterNames : string [ ] = [ ] ;
public parameterValues : string [ ] = [ ] ;
public csvLimit : number = 0 ;
public pagingLimit : number = 0 ;
public resultsPerPage : number = 0 ;
isPiwikEnabled = false ;
properties : EnvProperties ;
public pageContents = null ;
public divContents = null ;
public routerHelper : RouterHelper = new RouterHelper ( ) ;
public errorCodes : ErrorCodes = new ErrorCodes ( ) ;
2020-04-27 10:14:05 +02:00
breadcrumbs :Breadcrumb [ ] = [ ] ;
2020-01-31 16:12:51 +01:00
url = null ;
2020-07-21 14:41:08 +02:00
metaDescription = "" ;
2020-08-19 12:16:43 +02:00
@Input ( ) basicMetaDescription = [ ] ;
2020-02-13 15:44:51 +01:00
@Input ( ) entitiesSelection :boolean = true ;
2020-08-13 13:15:10 +02:00
@Input ( ) showSwitchSearchLink :boolean = true ;
2020-07-13 11:15:00 +02:00
2020-07-24 13:21:22 +02:00
// on 1st load, do not show filters until results query returns.
public hideFilters : boolean = true ;
2020-07-13 11:15:00 +02:00
//Dashboard
filterToggle = false ;
2020-07-13 17:23:20 +02:00
customFilterEnabled :boolean = false ;
2020-08-17 10:51:46 +02:00
//stickyform
@Input ( ) stickyForm :boolean = false ;
2020-08-04 09:25:32 +02:00
@ViewChild ( 'removeCustomFilter' ) removeCustomFilter : AlertModal ;
currentValueToRemove ;
currentFilterToRemove ;
isCustomFilterSelected :boolean = true ;
2020-01-31 16:12:51 +01:00
constructor ( private route : ActivatedRoute ,
private location : Location ,
private _meta : Meta ,
private _title : Title ,
private _piwikService : PiwikService ,
private router : Router ,
private seoService : SEOService ,
2020-10-20 11:11:15 +02:00
private helper : HelperService ,
private cdr :ChangeDetectorRef ) {
2020-01-31 16:12:51 +01:00
}
ngOnInit() {
2020-09-18 09:57:42 +02:00
this . properties = properties ;
//this.getDivContents();
this . getPageContents ( ) ;
this . pagingLimit = this . properties . pagingLimit ;
this . resultsPerPage = this . properties . resultsPerPage ;
this . csvLimit = this . properties . csvLimit ;
this . isPiwikEnabled = this . properties . enablePiwikTrack ;
this . updateUrl ( this . properties . domain + this . properties . baseLink + this . router . url ) ;
this . url = this . properties . domain + this . properties . baseLink + this . router . url ;
if ( typeof document !== 'undefined' && this . isPiwikEnabled && ! this . includeOnlyResultsAndFilter ) {
2020-11-11 15:43:13 +01:00
this . subscriptions . push ( this . _piwikService . trackView ( this . properties , this . pageTitle , this . piwikSiteId ) . subscribe ( ) ) ;
2020-09-18 09:57:42 +02:00
}
2020-05-21 15:17:28 +02:00
this . route . queryParams . subscribe ( params = > {
2020-08-19 12:16:43 +02:00
if ( params [ 'page' ] && params [ 'page' ] != 1 ) {
2020-05-21 15:17:28 +02:00
HelperFunctions . scrollToId ( "searchForm" ) ;
}
2020-07-13 17:23:20 +02:00
this . customFilterEnabled = params [ 'cf' ] && params [ 'cf' ] == "true" ;
2020-05-21 15:17:28 +02:00
} ) ;
2020-08-19 12:16:43 +02:00
if ( ! this . includeOnlyResultsAndFilter ) {
if ( this . basicMetaDescription . length == 0 ) {
if ( this . entityType == "result" ) {
this . basicMetaDescription = [ "Discover" + ( this . properties . adminToolsCommunity == 'openaire' ? "over 100 million of" : "" ) + " research outcomes " , "categorized by research type, year range, funder, languages, community and content providers." ] ;
} else if ( this . entityType == "project" ) {
this . basicMetaDescription = [ "Discover research projects and correlated research categorized by Funder and active year. " , "Statistics data about produced research outcomes per year available." ] ;
} else if ( this . entityType == "organization" ) {
this . basicMetaDescription = [ "Discover worldwide research organizations from over 100 countries and correlated research. " , "Funding, content providers, research pubblications and research data available." ] ;
} else {
this . basicMetaDescription . push ( this . pageTitle )
}
}
this . metaDescription = this . basicMetaDescription . join ( " " ) ;
this . updateTitle ( this . pageTitle ) ;
this . updateDescription ( ) ;
}
2020-01-31 16:12:51 +01:00
this . searchUtils . baseUrl = "/" + this . searchUtils . baseUrl ;
2020-09-18 09:57:42 +02:00
this . seoService . createLinkForCanonicalURL ( this . properties . domain + this . properties . baseLink + this . router . url , false ) ;
2020-04-27 10:14:05 +02:00
this . breadcrumbs . push ( { name : 'home' , route : '/' } ) ;
if ( this . simpleView ) {
2020-04-27 14:54:48 +02:00
this . breadcrumbs . push ( { name : "Search" , route : null } ) ;
2020-04-27 10:14:05 +02:00
} else if ( ! this . simpleView && this . advancedSearchLink ) {
2020-04-27 14:54:48 +02:00
this . breadcrumbs . push ( { name : "Advanced Search" , route : null } ) ;
2020-04-27 10:14:05 +02:00
}
[Trunk | Library]:
1. searchUtils.class.ts: In SearchUtilsClass added field "refineStatus:number = 1;" for refine queries.
2. searchResultsPerPage.component.ts & searchSorting.component.ts: [Bug fix] In EventEmitter (value change), emit raw value, not object with field "value".
3. searchDataProviders.component.ts & searchOrganizations.component.ts & searchProjects.component.ts & searchResearchResults.component.ts:
a. Add subscriptions in array to unsubscribe in ngOnDestroy.
b. Get properties from environment (no service needed).
c. Separate queries for refine and results.
d. Do not call refine query when page, results per page, sortBy change (there is still a bug here).
e. For refine query, added field "disableRefineForms" default set to false - passed in <new-search-page>.
4. newSearchPage.component.html:
a. Disable forms when "disableForms" or "disableRefineForms" is true.
b. Do not show filters, until results query returns, but show results while refine is loading.
c. Deleted old, unused code.
5. newSearchPage.component.ts:
a. Added fields "@Input() disableRefineForms: boolean = false;", "@Input() sortedByChanged: string = "";", "@Input() resultsPerPageChanged: number;"
b. When results per page or sortBy change, do not upadate immediately searchUtils values - do not query for refine when these change (there is still a bug here).
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59155 d315682c-612b-4755-9ff5-7f18f6832af3
2020-07-21 15:48:55 +02:00
//console.log(this.filters)
2020-01-31 16:12:51 +01:00
}
private getPageContents() {
2020-06-29 15:15:52 +02:00
if ( ( this . customFilter && this . customFilter . queryFieldName == "communityId" ) && this . properties . adminToolsCommunity !== "monitor" ) {
2020-11-11 15:43:13 +01:00
this . subscriptions . push ( this . helper . getPageHelpContents ( this . properties , ( this . customFilter ) ? this . customFilter.valueId : this.properties.adminToolsCommunity , this . router . url ) . subscribe ( contents = > {
2020-06-29 15:15:52 +02:00
this . pageContents = contents ;
2020-11-11 15:43:13 +01:00
} ) ) ;
2020-06-29 15:15:52 +02:00
}
2020-01-31 16:12:51 +01:00
}
private getDivContents() {
2020-06-29 15:15:52 +02:00
if ( ( this . customFilter && this . customFilter . queryFieldName == "communityId" ) && this . properties . adminToolsCommunity !== "monitor" ) {
2020-11-11 15:43:13 +01:00
this . subscriptions . push ( this . helper . getDivHelpContents ( this . properties , ( this . customFilter ) ? this . customFilter.valueId : this.properties.adminToolsCommunity , this . router . url ) . subscribe ( contents = > {
2020-06-29 15:15:52 +02:00
this . divContents = contents ;
2020-11-11 15:43:13 +01:00
} ) ) ;
2020-06-29 15:15:52 +02:00
}
2020-01-31 16:12:51 +01:00
}
ngOnDestroy() {
2020-11-11 15:43:13 +01:00
this . subscriptions . forEach ( subscription = > {
if ( subscription instanceof Subscriber ) {
subscription . unsubscribe ( ) ;
}
} ) ;
2020-01-31 16:12:51 +01:00
}
2020-07-21 14:41:08 +02:00
updateDescription() {
2020-08-19 12:16:43 +02:00
// this.metaDescription2 = "";
/ * i f ( t h i s . r e s u l t T y p e s ) {
2020-07-21 14:41:08 +02:00
let array = [ ] ;
for ( let type of this . resultTypeOptions ) {
if ( this . resultTypes [ type . id ] == true ) {
array . push ( type . name ) ;
}
}
if ( array . length == 0 ) {
this . metaDescription += "research outcomes " ;
} else {
this . metaDescription += array . join ( ", " ) + " " ;
}
} else {
this . metaDescription = this . pageTitle + " " ;
2020-08-19 12:16:43 +02:00
} * /
2020-07-21 14:41:08 +02:00
let filterArray = [ ] ;
for ( let filter of this . filters ) {
if ( filter . countSelectedValues > 0 ) {
for ( let value of filter . values ) {
if ( value . selected ) {
filterArray . push ( value . name ) ;
}
}
}
}
for ( let field of this . selectedFields ) {
if ( ( field . type == "entity" || field . type == "refine" ) && field . valueLabel . length > 0 && filterArray . indexOf ( field . valueLabel ) == - 1 ) {
filterArray . push ( field . valueLabel )
} else if ( ! ( field . type == "entity" || field . type == "refine" ) && field . value . length > 0 && filterArray . indexOf ( field . value ) == - 1 ) {
filterArray . push ( field . value ) ;
}
}
2020-08-19 12:16:43 +02:00
this . metaDescription = ( filterArray . length > 0 ? ( this . basicMetaDescription [ 0 ] + " Filtered by: " + filterArray . join ( ", " ) + " " )
: this . basicMetaDescription . join ( " " ) ) ;
2020-07-21 14:41:08 +02:00
this . _meta . updateTag ( { content : this.metaDescription } , "name='description'" ) ;
this . _meta . updateTag ( { content : this.metaDescription } , "property='og:description'" ) ;
2020-01-31 16:12:51 +01:00
}
updateTitle ( title : string ) {
var _prefix = "" ;
if ( this . hasPrefix ) {
_prefix = "OpenAIRE | " ;
}
var _title = _prefix + ( ( title . length > 50 ) ? title . substring ( 0 , 50 ) : title ) ;
this . _title . setTitle ( _title ) ;
this . _meta . updateTag ( { content : _title } , "property='og:title'" ) ;
}
updateUrl ( url : string ) {
this . _meta . updateTag ( { content : url } , "property='og:url'" ) ;
}
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 ;
2020-07-14 17:18:14 +02:00
this . filters [ i ] . radioValue = "" ;
2020-01-31 16:12:51 +01:00
}
}
2020-02-04 14:27:42 +01:00
this . selectedFilters = 0 ;
2020-02-17 15:19:14 +01:00
for ( let i = 0 ; i < this . rangeFilters . length ; i ++ ) {
this . rangeFilters [ i ] . selectedFromValue = null ;
this . rangeFilters [ i ] . selectedToValue = null ;
}
this . selectedRangeFilters = 0 ;
2020-02-11 12:58:51 +01:00
if ( this . quickFilter ) {
this . removeValueFromQuickFilter ( ) ;
}
2020-10-20 13:21:37 +02:00
if ( this . resultTypes ) {
this . resultTypes . values = [ ] ;
}
2020-01-31 16:12:51 +01:00
this . goTo ( 1 ) ;
// this.clearKeywords();
}
2020-05-21 15:17:28 +02:00
goTo ( page : number = 1 , scroll :boolean = true ) {
2020-11-02 18:11:31 +01:00
if ( this . offcanvasElement && ( typeof document !== 'undefined' ) ) {
2020-03-24 16:40:51 +01:00
UIkit . offcanvas ( this . offcanvasElement . nativeElement ) . hide ( ) ;
}
2020-01-31 16:12:51 +01:00
this . searchUtils . page = page ;
2020-02-17 15:19:14 +01:00
this . buildPageURLParameters ( this . filters , this . rangeFilters , true ) ;
2020-01-31 16:12:51 +01:00
this . router . navigate ( [ this . searchUtils . baseUrl ] , { queryParams : this.routerHelper.createQueryParams ( this . parameterNames , this . parameterValues ) } ) ;
2020-05-21 15:17:28 +02:00
if ( scroll ) {
HelperFunctions . scrollToId ( "searchForm" ) ;
}
2020-01-31 16:12:51 +01:00
/* Code For Piwik*/
if ( typeof localStorage !== 'undefined' ) {
//console.log("In PreviousRouteRecorder : "+this.router.url );
localStorage . setItem ( 'previousRoute' , this . router . url ) ;
}
if ( this . isPiwikEnabled && ( typeof document !== 'undefined' ) ) {
2020-11-11 15:43:13 +01:00
this . subscriptions . push ( this . _piwikService . trackView ( this . properties , this . pageTitle , this . piwikSiteId ) . subscribe ( ) ) ;
2020-01-31 16:12:51 +01:00
}
/* End Piwik Code */
}
2020-10-20 11:11:15 +02:00
queryChanged ( $event ) {
if ( $event == "filters_update" ) {
this . cdr . detectChanges ( ) ;
return ;
}
2020-05-21 15:17:28 +02:00
this . goTo ( 1 , false ) ;
2020-01-31 16:12:51 +01:00
}
sizeChanged ( $event ) {
[Trunk | Library]:
1. searchUtils.class.ts: In SearchUtilsClass added field "refineStatus:number = 1;" for refine queries.
2. searchResultsPerPage.component.ts & searchSorting.component.ts: [Bug fix] In EventEmitter (value change), emit raw value, not object with field "value".
3. searchDataProviders.component.ts & searchOrganizations.component.ts & searchProjects.component.ts & searchResearchResults.component.ts:
a. Add subscriptions in array to unsubscribe in ngOnDestroy.
b. Get properties from environment (no service needed).
c. Separate queries for refine and results.
d. Do not call refine query when page, results per page, sortBy change (there is still a bug here).
e. For refine query, added field "disableRefineForms" default set to false - passed in <new-search-page>.
4. newSearchPage.component.html:
a. Disable forms when "disableForms" or "disableRefineForms" is true.
b. Do not show filters, until results query returns, but show results while refine is loading.
c. Deleted old, unused code.
5. newSearchPage.component.ts:
a. Added fields "@Input() disableRefineForms: boolean = false;", "@Input() sortedByChanged: string = "";", "@Input() resultsPerPageChanged: number;"
b. When results per page or sortBy change, do not upadate immediately searchUtils values - do not query for refine when these change (there is still a bug here).
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59155 d315682c-612b-4755-9ff5-7f18f6832af3
2020-07-21 15:48:55 +02:00
//this.searchUtils.size = $event.value;
this . resultsPerPageChanged = $event ;
2020-01-31 16:12:51 +01:00
this . goTo ( 1 ) ;
}
sortByChanged ( $event ) {
[Trunk | Library]:
1. searchUtils.class.ts: In SearchUtilsClass added field "refineStatus:number = 1;" for refine queries.
2. searchResultsPerPage.component.ts & searchSorting.component.ts: [Bug fix] In EventEmitter (value change), emit raw value, not object with field "value".
3. searchDataProviders.component.ts & searchOrganizations.component.ts & searchProjects.component.ts & searchResearchResults.component.ts:
a. Add subscriptions in array to unsubscribe in ngOnDestroy.
b. Get properties from environment (no service needed).
c. Separate queries for refine and results.
d. Do not call refine query when page, results per page, sortBy change (there is still a bug here).
e. For refine query, added field "disableRefineForms" default set to false - passed in <new-search-page>.
4. newSearchPage.component.html:
a. Disable forms when "disableForms" or "disableRefineForms" is true.
b. Do not show filters, until results query returns, but show results while refine is loading.
c. Deleted old, unused code.
5. newSearchPage.component.ts:
a. Added fields "@Input() disableRefineForms: boolean = false;", "@Input() sortedByChanged: string = "";", "@Input() resultsPerPageChanged: number;"
b. When results per page or sortBy change, do not upadate immediately searchUtils values - do not query for refine when these change (there is still a bug here).
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59155 d315682c-612b-4755-9ff5-7f18f6832af3
2020-07-21 15:48:55 +02:00
//this.searchUtils.sortBy = $event.value;
this . sortedByChanged = $event ;
2020-01-31 16:12:51 +01:00
this . goTo ( 1 ) ;
}
getOperatorParameter ( parameter : string ) : string {
for ( let id of this . fieldIds ) {
if ( this . fieldIdsMap [ id ] [ "param" ] == parameter ) {
return this . fieldIdsMap [ id ] [ "operator" ] ;
}
}
}
/ *
* Get A sub - array of this . refineFields array , which contains the ids of the selected filters
* /
public getSelectedFilters ( ) : string [ ] {
var selected : string [ ] = [ ] ;
2020-10-20 17:11:40 +02:00
var filters = this . URLCreatedFilters ;
2020-05-21 15:17:28 +02:00
for ( var i = 0 ; i < filters . length ; i ++ ) {
var filter : Filter = filters [ i ] ;
2020-01-31 16:12:51 +01:00
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 [ ] = [ ] ;
for ( var i = 0 ; i < this . refineFields . length ; i ++ ) {
2020-02-04 17:33:46 +01:00
if ( this . parameterNames . indexOf ( this . refineFields [ i ] ) != - 1 ) {
2020-01-31 16:12:51 +01:00
selected . push ( this . refineFields [ i ] ) ;
}
}
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 ;
}
/ *
* Mark as check the new filters that are selected , when you get them from search
* /
public checkSelectedFilters ( filters : Filter [ ] ) {
this . filters = filters ;
2020-08-04 09:25:32 +02:00
if ( this . customFilter && ! this . customFilter . isHiddenFilter ) {
this . customFilter . selected = null ;
}
2020-01-31 16:12:51 +01:00
for ( var i = 0 ; i < filters . length ; i ++ ) {
var filter : Filter = filters [ i ] ;
filter . countSelectedValues = 0 ;
2020-02-04 17:33:46 +01:00
if ( this . parameterNames . indexOf ( filter . filterId ) != - 1 ) {
let values = ( decodeURIComponent ( this . parameterValues [ this . parameterNames . indexOf ( filter . filterId ) ] ) ) . split ( /,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/ , - 1 ) ;
2020-01-31 16:12:51 +01:00
for ( let filterValue of filter . values ) {
if ( values . indexOf ( StringUtils . quote ( filterValue . id ) ) > - 1 ) {
filterValue . selected = true ;
filter . countSelectedValues ++ ;
} else {
filterValue . selected = false ;
}
}
2020-08-13 15:18:26 +02:00
if ( this . customFilter ) {
this . customFilter . selected = this . customFilter . queryFieldName == filter . filterId && values . indexOf ( StringUtils . quote ( this . customFilter . valueId ) ) != - 1 ;
2020-08-04 09:25:32 +02:00
}
2020-02-11 15:56:20 +01:00
} else if ( this . quickFilter && this . quickFilter . filterId == filter . filterId && this . quickFilter . selected ) {
2020-02-11 12:58:51 +01:00
for ( let filterValue of filter . values ) {
if ( filterValue . id == this . quickFilter . value ) {
filterValue . selected = true ;
filter . countSelectedValues ++ ;
} else {
filterValue . selected = false ;
}
}
2020-01-31 16:12:51 +01:00
} else {
for ( let filterValue of filter . values ) {
filterValue . selected = false ;
}
}
2020-02-11 15:56:20 +01:00
if ( this . quickFilter && filter . filterId == this . quickFilter . filterId ) {
2020-02-11 12:58:51 +01:00
this . quickFilter . filter = filter ;
}
2020-01-31 16:12:51 +01:00
}
2020-08-04 09:25:32 +02:00
if ( this . parameterNames . indexOf ( "cf" ) != - 1 && this . parameterValues [ this . parameterNames . indexOf ( "cf" ) ] == "true" ) {
this . customFilter . selected = true ;
} else if ( this . customFilter && this . customFilter . selected == null ) {
this . customFilter . selected = false ;
}
2020-01-31 16:12:51 +01:00
this . filterFilterValues ( this . filters ) ;
2020-08-19 12:16:43 +02:00
if ( ! this . includeOnlyResultsAndFilter ) {
this . updateDescription ( ) ;
}
2020-01-31 16:12:51 +01:00
return filters ;
}
2020-02-17 15:19:14 +01:00
/ *
* Mark as check the new range filters that are selected
* /
public checkSelectedRangeFilters ( filters : RangeFilter [ ] ) {
//console.log("checkSelectedRangeFilters: parameterNames.length: "+this.parameterNames.length);
this . rangeFilters = filters ;
for ( let i = 0 ; i < filters . length ; i ++ ) {
let filter : RangeFilter = filters [ i ] ;
if ( this . parameterNames . indexOf ( filter . filterId ) != - 1 ) {
//console.log(filter.filterId + " "+this.parameterNames.indexOf(filter.filterId) );
let values = ( decodeURIComponent ( this . parameterValues [ this . parameterNames . indexOf ( filter . filterId ) ] ) ) . split ( /,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/ , - 1 ) ;
let operators : string [ ] = ( StringUtils . URIDecode ( this . parameterValues [ this . parameterNames . indexOf ( filter . filterId ) ] ) ) . split ( /,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/ , - 1 ) ;
if ( values . length == operators . length ) {
for ( let j = 0 ; j < values . length ; j ++ ) {
if ( this . fieldIdsMap [ filter . originalFilterIdFrom + "-range-" + filter . originalFilterIdTo ] . filterType == "range" ) {
let value : string = StringUtils . unquote ( values [ j ] ) ;
let validDates : boolean = true ;
let years : string [ ] = ( value . substring ( 5 ) ) . split ( ":" ) ;
let yearFrom : string = ( Dates . isValidYear ( years [ 0 ] ) ? years [ 0 ] : null ) ;
let yearTo : string = ( Dates . isValidYear ( years [ 1 ] ) ? years [ 1 ] : null ) ;
//console.log("checkSelectedRangeFilters: yearFrom: " + yearFrom + " - yearTo: "+yearTo);
if ( yearFrom ) {
filter . selectedFromValue = yearFrom ;
}
if ( yearTo ) {
filter . selectedToValue = yearTo ;
}
2020-02-24 17:27:01 +01:00
if ( yearFrom && yearTo ) {
filter . selectedFromAndToValues = yearFrom + "-" + yearTo ;
} else if ( yearFrom ) {
2020-02-26 16:01:16 +01:00
filter . selectedFromAndToValues = "From " + yearFrom ;
2020-02-24 17:27:01 +01:00
} else if ( yearTo ) {
2020-02-26 16:01:16 +01:00
filter . selectedFromAndToValues = "Until " + yearTo ;
2020-02-24 17:27:01 +01:00
}
2020-02-17 15:19:14 +01:00
if ( ! yearFrom && ! yearTo ) {
validDates = false ;
}
// if (value.length < 14) {
// validDates = false;
// console.log("not valid (length<14)");
// } else {
// if (!Dates.isValidYear(value.substring(5, 9)) || !Dates.isValidYear(value.substring(10, 14))) {
// validDates = false;
// console.log("not valid years");
// } else {
// filter.selectedFromValue = value.substring(5, 9);
// filter.selectedToValue = value.substring(10, 14);
// console.log(filter);
// }
// }
}
}
}
} else {
filter . selectedFromValue = null ;
filter . selectedToValue = null ;
}
}
return this . rangeFilters ;
}
2020-07-24 13:21:22 +02:00
get existingFiltersWithValues() {
if ( this . filters . length == 0 ) {
return 0 ;
}
return this . filters . some ( filter = > ( filter . values && filter . values . length > 0 ) ) ;
}
2020-01-31 16:12:51 +01:00
/ *
* 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);
2020-02-04 17:33:46 +01:00
if ( filter . filterId . indexOf ( "funder" ) != - 1 && this . parameterNames . indexOf ( filter . filterId ) != - 1 ) {
let funders = ( decodeURIComponent ( this . parameterValues [ this . parameterNames . indexOf ( filter . filterId ) ] ) ) . split ( /,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/ , - 1 ) ;
2020-01-31 16:12:51 +01:00
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 ;
}
}
}
return filters ;
}
2020-02-11 12:58:51 +01:00
public countSelectedFilters ( filters : Filter [ ] ) : number {
2020-02-04 14:27:42 +01:00
this . selectedFilters = 0 ;
for ( let filter of filters ) {
2020-01-31 16:12:51 +01:00
if ( filter . countSelectedValues > 0 ) {
2020-02-04 14:27:42 +01:00
this . selectedFilters += filter . countSelectedValues ;
2020-01-31 16:12:51 +01:00
}
}
2020-02-04 14:27:42 +01:00
return this . selectedFilters ;
2020-01-31 16:12:51 +01:00
}
2020-02-17 15:19:14 +01:00
public countSelectedRangeFilters ( rangeFilters : RangeFilter [ ] ) : number {
this . selectedRangeFilters = 0 ;
for ( let filter of rangeFilters ) {
if ( filter . selectedFromValue || filter . selectedToValue ) {
this . selectedRangeFilters ++ ;
}
}
return this . selectedRangeFilters ;
}
2020-01-31 16:12:51 +01:00
private clearKeywords() {
if ( this . searchUtils . keyword . length > 0 ) {
this . searchUtils . keyword = '' ;
}
this . goTo ( 1 ) ;
}
2020-08-04 09:25:32 +02:00
public removeFilter ( value : Value , filter : Filter , forceRemove :boolean = false ) {
this . currentValueToRemove = value ;
this . currentFilterToRemove = filter ;
2020-08-13 13:15:10 +02:00
if ( ! forceRemove && this . customFilter && this . customFilter . queryFieldName == filter . filterId && this . customFilter . valueId == value . id && this . customFilter . promptToAddFilter ) {
2020-08-04 09:25:32 +02:00
this . openRemoveCustomFilterModal ( ) ;
return ;
}
2020-01-31 16:12:51 +01:00
filter . countSelectedValues -- ;
2020-02-04 14:27:42 +01:00
this . selectedFilters -- ;
2020-01-31 16:12:51 +01:00
if ( value . selected == true ) {
value . selected = false ;
}
2020-07-14 17:18:14 +02:00
if ( filter . filterType == "radio" ) {
filter . radioValue = "" ;
}
2020-02-11 12:58:51 +01:00
if ( this . quickFilter && this . quickFilter . filterId == filter . filterId ) {
this . removeValueFromQuickFilter ( ) ;
}
2020-01-31 16:12:51 +01:00
this . goTo ( 1 ) ;
2020-02-17 15:19:14 +01:00
}
2020-08-04 09:25:32 +02:00
public openRemoveCustomFilterModal() {
this . removeCustomFilter . alertTitle = 'Remove filter' ;
this . removeCustomFilter . message = 'You are about to see results that are not related to ' + this . customFilter . valueName + '. Do you want to proceed?' ;
this . removeCustomFilter . okButtonText = 'Yes' ;
this . removeCustomFilter . cancelButtonText = 'No' ;
this . removeCustomFilter . open ( ) ;
}
closeCustomFilterModal() {
this . removeFilter ( this . currentValueToRemove , this . currentFilterToRemove , true ) ;
this . isCustomFilterSelected = false ;
}
2020-01-31 16:12:51 +01:00
2020-02-17 15:19:14 +01:00
public removeRangeFilter ( filter : RangeFilter ) {
filter . selectedFromValue = null ;
filter . selectedToValue = null ;
this . goTo ( 1 ) ;
2020-01-31 16:12:51 +01:00
}
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 ;
}
filterChanged ( $event ) {
2020-02-17 15:19:14 +01:00
if ( this . quickFilter && this . quickFilter . filter ) {
2020-02-11 12:58:51 +01:00
this . removeValueFromQuickFilter ( ) ;
}
2020-01-31 16:12:51 +01:00
this . goTo ( 1 ) ;
2020-02-11 12:58:51 +01:00
}
/ * *
* if there is a change in the values of the quick filter , this function has to be run , to also update the quickFilter
* /
removeValueFromQuickFilter() {
if ( this . quickFilter . filter . countSelectedValues == 0 ) {
this . quickFilter . selected = false ;
} else {
let isQuickEnabled = false ;
for ( let filterValue of this . quickFilter . filter . values ) {
isQuickEnabled = ( filterValue . name == this . quickFilter . value )
}
this . quickFilter . selected = ( isQuickEnabled && this . quickFilter . filter . countSelectedValues == 1 ) ;
}
2020-01-31 16:12:51 +01:00
}
2020-08-04 09:25:32 +02:00
/ * *
* Set selected the value of the custom filter .
* /
addCustomFilter() {
this . customFilter . selected = true ;
if ( this . refineFields . indexOf ( this . customFilter . queryFieldName ) == - 1 ) {
this . customFilterEnabled = true ;
} else {
for ( let filter of this . filters ) {
if ( this . customFilter . queryFieldName == filter . filterId ) {
for ( let value of filter . values ) {
if ( value . id == this . customFilter . valueId ) {
value . selected = true ;
filter . countSelectedValues ++ ;
}
}
}
}
}
this . filterChanged ( null ) ;
}
2020-01-31 16:12:51 +01:00
// for loading
public openLoading() {
this . loading . open ( ) ;
}
public closeLoading() {
this . loading . close ( ) ;
}
2020-03-04 13:42:52 +01:00
/ * *
* Build advanced search Filters based on the URL parameters
* @param params
* /
createAdvancedSearchSelectedFiltersFromNewURLParameters ( params ) {
for ( let i = 0 ; i < Object . keys ( params ) . length ; i ++ ) {
if ( params [ "f" + i ] && params [ "fv" + i ] ) {
let fieldId = params [ "f" + i ] . split ( "," ) [ 0 ] ;
let operator = ( params [ "f" + i ] . split ( "," ) . length > 1 ) ? params [ "f" + i ] . split ( "," ) [ 1 ] : "and" ;
let fieldparam = ( this . fieldIdsMap [ fieldId ] ) ? this . fieldIdsMap [ fieldId ] . param : "" ;
if ( ! this . fieldIdsMap [ fieldId ] ) {
console . error ( "Field: " + fieldId + " not found in fieldIds map" ) ;
continue ;
}
let value : string = StringUtils . URIDecode ( params [ "fv" + i ] ) ;
if ( this . fieldIdsMap [ fieldId ] . type == "date" ) {
let validDates : boolean = true ;
let dateField : AdvancedField = new AdvancedField ( fieldId , fieldparam , this . fieldIdsMap [ fieldId ] . name , this . fieldIdsMap [ fieldId ] . type , value , operator ) ;
if ( value . indexOf ( "range" ) != - 1 ) {
dateField . dateValue . type = "range" ;
if ( value . length < 26 ) {
validDates = false ;
} else {
if ( ! Dates . isValidDate ( value . substring ( 5 , 15 ) ) || ! Dates . isValidDate ( value . substring ( 16 , 26 ) ) ) {
validDates = false ;
} else {
dateField . dateValue . from = Dates . getDateFromString ( value . substring ( 5 , 15 ) ) ;
dateField . dateValue . to = Dates . getDateFromString ( value . substring ( 16 , 26 ) ) ;
}
}
// "rangeYYYY-MM-DD:YYYY-MM-DD"
} else {
dateField . dateValue . setDatesByType ( value ) ;
}
if ( validDates ) {
this . selectedFields . push ( dateField ) ;
}
} else {
this . selectedFields . push ( new AdvancedField ( fieldId , fieldparam , this . fieldIdsMap [ fieldId ] . name , this . fieldIdsMap [ fieldId ] . type , value , operator ) ) ;
}
}
}
}
2020-01-31 16:12:51 +01:00
/ * *
* Build advanced search Filters based on the URL parameters
* @param params
* /
createAdvancedSearchSelectedFiltersFromURLParameters ( params ) {
2020-03-04 13:42:52 +01:00
this . createAdvancedSearchSelectedFiltersFromNewURLParameters ( params ) ;
2020-01-31 16:12:51 +01:00
for ( var i = 0 ; i < this . fieldIds . length ; i ++ ) {
var fieldId = this . fieldIds [ i ] ;
var fieldparam = ( this . fieldIdsMap [ fieldId ] ) ? this . fieldIdsMap [ fieldId ] . param : "" ;
if ( ! this . fieldIdsMap [ fieldId ] ) {
console . error ( "Field: " + fieldId + " not found in fieldIds map" ) ;
2020-03-04 13:42:52 +01:00
continue ;
2020-01-31 16:12:51 +01:00
}
var operatorId = this . getOperatorParameter ( fieldparam ) ;
if ( params [ fieldparam ] != undefined && params [ operatorId ] != undefined ) {
var values : string [ ] = StringUtils . URIDecode ( params [ fieldparam ] ) . split ( /,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/ , - 1 ) ;
var operators : string [ ] = ( StringUtils . URIDecode ( params [ operatorId ] ) ) . split ( /,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/ , - 1 ) ;
if ( values . length == operators . length ) {
for ( var j = 0 ; j < values . length ; j ++ ) {
if ( this . fieldIdsMap [ fieldId ] . type == "date" ) {
var value : string = StringUtils . unquote ( values [ j ] ) ;
var validDates : boolean = true ;
var dateField : AdvancedField = new AdvancedField ( fieldId , fieldparam , this . fieldIdsMap [ fieldId ] . name , this . fieldIdsMap [ fieldId ] . type , value , operators [ j ] ) ;
if ( value . indexOf ( "range" ) != - 1 ) {
dateField . dateValue . type = "range" ;
if ( value . length < 26 ) {
validDates = false ;
} else {
if ( ! Dates . isValidDate ( value . substring ( 5 , 15 ) ) || ! Dates . isValidDate ( value . substring ( 16 , 26 ) ) ) {
validDates = false ;
} else {
dateField . dateValue . from = Dates . getDateFromString ( value . substring ( 5 , 15 ) ) ;
dateField . dateValue . to = Dates . getDateFromString ( value . substring ( 16 , 26 ) ) ;
}
}
// "rangeYYYY-MM-DD:YYYY-MM-DD"
} else {
dateField . dateValue . setDatesByType ( value ) ;
}
if ( validDates ) {
this . selectedFields . push ( dateField ) ;
}
} else {
2020-03-04 13:42:52 +01:00
this . selectedFields . push ( new AdvancedField ( fieldId , fieldparam , this . fieldIdsMap [ fieldId ] . name , this . fieldIdsMap [ fieldId ] . type , values [ j ] , operators [ j ] ) ) ;
2020-01-31 16:12:51 +01:00
}
}
}
}
}
if ( params [ 'keyword' ] && params [ 'keyword' ] . length > 0 ) {
this . selectedFields . push ( new AdvancedField ( this . fieldIds [ 0 ] , this . fieldIdsMap [ this . fieldIds [ 0 ] ] . param , this . fieldIdsMap [ this . fieldIds [ 0 ] ] . name , this . fieldIdsMap [ this . fieldIds [ 0 ] ] . type , params [ 'keyword' ] , "and" ) ) ;
}
if ( this . selectedFields . length == 0 ) {
this . selectedFields . push ( new AdvancedField ( this . fieldIds [ 0 ] , this . fieldIdsMap [ this . fieldIds [ 0 ] ] . param , this . fieldIdsMap [ this . fieldIds [ 0 ] ] . name , this . fieldIdsMap [ this . fieldIds [ 0 ] ] . type , "" , "and" ) ) ;
}
}
/ * *
* Create Search API query based on the selected fields of the advanced form
* /
getSearchAPIQueryForAdvancedSearhFields() {
var params = "" ;
var countParams = 0 ;
for ( var i = 0 ; i < this . selectedFields . length ; i ++ ) {
if ( this . fieldIdsMap [ this . selectedFields [ i ] . id ] != undefined && ( this . selectedFields [ i ] . value != "" || this . selectedFields [ i ] . type == "date" ) ) {
//console.log("createQueryParameters::"+this.selectedFields[i].type);
if ( this . selectedFields [ i ] . type == "date" ) {
if ( this . selectedFields [ i ] . dateValue . type != "any" ) {
params += ( countParams == 0 ? "" : this . selectedFields [ i ] . operatorId ) + " " + this . selectedFields [ i ] . id + this . fieldIdsMap [ this . selectedFields [ i ] . id ] . equalityOperator + '"' + StringUtils . URIEncode ( Dates . getDateToString ( this . selectedFields [ i ] . dateValue . from ) ) + " "
+ StringUtils . URIEncode ( Dates . getDateToString ( this . selectedFields [ i ] . dateValue . to ) ) + '"' + " " ;
}
} else {
if ( this . selectedFields [ i ] . id == "q" ) {
2020-03-27 13:39:18 +01:00
// console.log(this.selectedFields[i].value)
2020-04-07 13:11:31 +02:00
/ * v a r o p = " " ;
2020-01-31 16:12:51 +01:00
var doisParams = "" ;
2020-03-03 15:32:43 +01:00
if ( ( this . entityType == 'publication' || this . entityType == 'dataset' || this . entityType == 'software' || this . entityType == 'other' || this . entityType == "result" ) ) {
var DOIs : Identifier [ ] = Identifier . getIdentifiersFromString ( this . selectedFields [ i ] . value ) ;
for ( let identifier of DOIs ) {
2020-03-27 13:39:18 +01:00
// console.log(identifier)
2020-03-03 15:32:43 +01:00
// pidclassid exact \"doi\" and pid exact \"10.1016/j.nima.2015.11.134\"
//and (authorid exact \"0000-0001-7291-3210 \" )"
if ( identifier . class == "ORCID" ) {
doisParams += ( doisParams . length > 0 ? " or " : "" ) + '(authorid="' + identifier . id + '")' ;
} else {
doisParams += ( doisParams . length > 0 ? " or " : "" ) + '(pidclassid exact "' + identifier . class + '" and pid="' + identifier . id + '")' ;
}
2020-01-31 16:12:51 +01:00
}
}
if ( doisParams . length > 0 ) {
2020-03-12 18:03:35 +01:00
params += this . createQuotedKeywordQuery ( this . selectedFields [ i ] . value , this . selectedFields [ i ] . id , this . selectedFields [ i ] . operatorId , countParams , true , true ) + " or " + doisParams ;
2020-01-31 16:12:51 +01:00
} else {
2020-03-12 18:03:35 +01:00
params += this . createQuotedKeywordQuery ( this . selectedFields [ i ] . value , this . selectedFields [ i ] . id , this . selectedFields [ i ] . operatorId , countParams , true ) ;
2020-04-07 13:11:31 +02:00
} * /
2020-07-02 17:53:43 +02:00
params += NewSearchPageComponent . createKeywordQuery ( this . entityType , this . selectedFields [ i ] . value , this . selectedFields [ i ] . id , this . selectedFields [ i ] . operatorId , countParams ) ;
2020-03-12 18:03:35 +01:00
//TODO deposit case
2020-03-27 13:39:18 +01:00
// console.log(this.usedBy)
// console.log(this.keywordFields)
2020-03-12 18:03:35 +01:00
if ( this . usedBy == "deposit" ) {
if ( this . keywordFields . length > 0 ) {
params += " or ("
}
for ( let j = 0 ; j < this . keywordFields . length ; j ++ ) {
if ( j > 0 ) {
params += " or "
}
2020-04-07 13:11:31 +02:00
params += NewSearchPageComponent . createQuotedKeywordQuery ( this . selectedFields [ i ] . value , this . keywordFields [ j ] . name , " or " , countParams , false ) ;
2020-03-12 18:03:35 +01:00
// let field = this.keywordFields[i];
//keywordQuery += field.name+field.equalityOperator+StringUtils.URIEncode(keyword);
// params += field.name+field.equalityOperator+StringUtils.quote(StringUtils.URIEncode(keyword));
}
if ( this . keywordFields . length > 0 ) {
params += " ) "
}
}
2020-02-25 16:40:56 +01:00
} else if ( countParams == 0 && this . selectedFields [ i ] . operatorId == "not" && this . fieldIdsMap [ this . selectedFields [ i ] . id ] . equalityOperator != "=" ) {
2020-01-31 16:12:51 +01:00
params += " " + this . selectedFields [ i ] . id + " <> " + '"' + StringUtils . URIEncode ( this . selectedFields [ i ] . value ) + '"' + " " ;
2020-02-25 16:40:56 +01:00
} else if ( this . fieldIdsMap [ this . selectedFields [ i ] . id ] . equalityOperator == "=" ) {
2020-04-07 13:11:31 +02:00
params += NewSearchPageComponent . createQuotedKeywordQuery ( this . selectedFields [ i ] . value , this . selectedFields [ i ] . id , this . selectedFields [ i ] . operatorId , countParams , false ) ;
2020-02-25 16:40:56 +01:00
} else {
2020-04-16 11:30:31 +02:00
params += ( countParams == 0 ? "" : " " + this . selectedFields [ i ] . operatorId + " " ) + this . selectedFields [ i ] . id + this . fieldIdsMap [ this . selectedFields [ i ] . id ] . equalityOperator + '"' + encodeURIComponent ( this . selectedFields [ i ] . value ) + '"' + " " ;
2020-01-31 16:12:51 +01:00
}
}
countParams ++ ;
}
}
2020-03-27 13:39:18 +01:00
// console.log("ParameterS:")
// console.log(params)
2020-01-31 16:12:51 +01:00
return params ;
}
2020-04-07 13:11:31 +02:00
public static createKeywordQuery ( entityType :string , value :string , id , operatorId , countParams = 0 ) {
let params = "" ;
let doisParams = "" ;
2020-06-29 13:10:32 +02:00
var DOIs : Identifier [ ] = Identifier . getIdentifiersFromString ( value ) ;
2020-04-07 13:11:31 +02:00
if ( ( entityType == 'publication' || entityType == 'dataset' || entityType == 'software' || entityType == 'other' || entityType == "result" ) ) {
for ( let identifier of DOIs ) {
// console.log(identifier)
// pidclassid exact \"doi\" and pid exact \"10.1016/j.nima.2015.11.134\"
//and (authorid exact \"0000-0001-7291-3210 \" )"
if ( identifier . class == "ORCID" ) {
doisParams += ( doisParams . length > 0 ? " or " : "" ) + '(authorid="' + identifier . id + '")' ;
} else {
doisParams += ( doisParams . length > 0 ? " or " : "" ) + '(pidclassid exact "' + identifier . class + '" and pid="' + identifier . id + '")' ;
}
}
}
if ( doisParams . length > 0 ) {
2020-04-16 11:30:31 +02:00
params += "(" + this . createQuotedKeywordQuery ( value , id , operatorId , countParams , true , true ) + " or " + doisParams + ")" ;
2020-04-07 13:11:31 +02:00
} else {
2020-06-29 13:10:32 +02:00
//if it is PIDs but no doisquery produced, forced to use quotes as the query will fail due to special characters
params += this . createQuotedKeywordQuery ( value , id , operatorId , countParams , true ,
( DOIs . length > 0 && doisParams . length == 0 ) ) ;
2020-04-07 13:11:31 +02:00
}
return params ;
2020-01-31 16:12:51 +01:00
2020-04-07 13:11:31 +02:00
}
private static createQuotedKeywordQuery ( fieldValue , fieldId , fieldOperator , countParams :number , isSearchAll :boolean , forceQuotted :boolean = false ) {
2020-02-25 16:40:56 +01:00
let params = "" ;
2020-06-16 18:42:51 +02:00
let countQuote = ( fieldValue . match ( /'/g ) || [ ] ) . length ;
let countDoubleQuote = ( fieldValue . match ( /"/g ) || [ ] ) . length ;
let quotedParts = [ ] ;
if ( countQuote % 2 == 0 && countDoubleQuote % 2 == 0 ) {
quotedParts = ( fieldValue ) ? fieldValue . match ( /(["'])(.*?)*?\1/g ) : [ ] ;
}
2020-07-02 17:53:43 +02:00
params += ( countParams == 0 ? "" : fieldOperator ) ;
2020-04-16 11:30:31 +02:00
params += " (" ;
2020-03-03 15:32:43 +01:00
if ( forceQuotted ) {
2020-07-24 14:27:40 +02:00
return ( countParams == 0 ? "" : " " + fieldOperator + " " ) + this . getQuotedQueryPart ( fieldId , '"' + fieldValue + '"' , isSearchAll ) ;
2020-03-03 15:32:43 +01:00
}
2020-03-12 18:03:35 +01:00
if ( quotedParts && quotedParts . length == 1 && quotedParts [ 0 ] == fieldValue ) {
params += this . getQuotedQueryPart ( fieldId , fieldValue , isSearchAll ) ;
2020-02-25 16:40:56 +01:00
} else if ( quotedParts && quotedParts . length > 0 ) {
for ( let i = 0 ; i < quotedParts . length ; i ++ ) {
params += ( i > 0 ) ? " and " : "" ;
2020-03-12 18:03:35 +01:00
params += this . getQuotedQueryPart ( fieldId , quotedParts [ i ] , isSearchAll ) ;
2020-02-25 16:40:56 +01:00
}
let startPoint = 0 ;
let endPoint = 0 ;
for ( let i = 0 ; i < quotedParts . length ; i ++ ) {
2020-03-12 18:03:35 +01:00
let index = fieldValue . indexOf ( quotedParts [ i ] ) ;
endPoint = ( i + 1 < quotedParts.length ) ? fieldValue.indexOf ( quotedParts [ i + 1 ] ) : fieldValue.length ;
// console.log(fieldValue.indexOf(quotedParts[i+1]) +" - "+fieldValue.length);
2020-02-25 16:40:56 +01:00
// console.log(" SP "+ startPoint+" EP: "+endPoint);
if ( index == startPoint ) {
startPoint += quotedParts [ i ] . length ;
} else if ( startPoint < index ) {
endPoint = index ;
}
// console.log(" SP "+ startPoint+" EP: "+endPoint);
2020-03-12 18:03:35 +01:00
if ( decodeURIComponent ( fieldValue . substring ( startPoint , endPoint ) ) . split ( " " ) . join ( "" ) . length > 0 ) {
params += " and " + this . getNoQuotedQueryPart ( fieldId , fieldValue . substring ( startPoint , endPoint ) , isSearchAll ) ;
2020-02-25 16:40:56 +01:00
}
// console.log("For "+i+" " +params+" SP "+ startPoint+" EP: "+endPoint);
2020-03-12 18:03:35 +01:00
// startPoint = (i+1<quotedParts.length)? fieldValue.indexOf(quotedParts[i+i]):fieldValue.length;//(startPoint<index )?(index + quotedParts[i].length):fieldValue.length;
startPoint = ( ( i + 1 < quotedParts.length ) ? ( fieldValue.indexOf ( quotedParts [ i + 1 ] ) + quotedParts [ i + 1 ] .length ) : ( endPoint = = index ? ( index + quotedParts [ i ] .length ) : endPoint ) ) ;
2020-02-25 16:40:56 +01:00
}
2020-03-12 18:03:35 +01:00
if ( startPoint != fieldValue . length && decodeURIComponent ( fieldValue . substring ( startPoint , fieldValue . length ) ) . split ( " " ) . join ( "" ) . length > 0 ) {
params += " and " + this . getNoQuotedQueryPart ( fieldId , fieldValue . substring ( startPoint , fieldValue . length ) , isSearchAll ) ;
2020-02-25 16:40:56 +01:00
}
} else {
2020-03-12 18:03:35 +01:00
params += this . getNoQuotedQueryPart ( fieldId , fieldValue , isSearchAll ) ;
2020-02-25 16:40:56 +01:00
}
2020-04-16 11:30:31 +02:00
params += ")" ;
2020-02-25 16:40:56 +01:00
return params ;
}
2020-04-07 13:11:31 +02:00
private static getQuotedQueryPart ( fieldId :string , value :string , isSearchAll :boolean ) {
2020-03-12 18:03:35 +01:00
return ( isSearchAll ? "__all" : fieldId ) + " exact " + StringUtils . URIEncode ( value ) ;
2020-02-25 16:40:56 +01:00
}
2020-04-07 13:11:31 +02:00
private static getNoQuotedQueryPart ( fieldId :string , value :string , isSearchAll :boolean ) {
2020-07-24 14:27:40 +02:00
//split the keywords of the vlaue and query seperately for each keyword using quotes to allow characters like .@
let valueKeywords = value . split ( " " ) ;
let query = "" ;
let i = 0 ;
for ( let keyword of valueKeywords ) {
if ( keyword . length > 0 ) {
2020-10-20 12:21:37 +02:00
query += ( i != 0 ? " and " : "" ) + ( isSearchAll ? "(" : fieldId + "=" ) + "\"" + StringUtils . URIEncode ( this . checkForReservedWords ( keyword ) ) + "\"" + ( isSearchAll ? ")" : "" ) ;
2020-07-24 14:27:40 +02:00
i ++ ;
}
2020-02-25 16:40:56 +01:00
}
2020-07-24 14:27:40 +02:00
return query
2020-02-25 16:40:56 +01:00
}
2020-10-20 12:21:37 +02:00
private static checkForReservedWords ( keyword :string ) {
let reservedWords = [ "AND" , "OR" , "NOT" ] ;
if ( reservedWords . indexOf ( keyword ) != - 1 ) {
return keyword . toLowerCase ( ) ;
}
return keyword ;
}
2020-01-31 16:12:51 +01:00
/ * *
* Create Search API query based on the filters of refine fields
* @param URLparams
2020-02-11 15:56:20 +01:00
* @param firstLoad
2020-01-31 16:12:51 +01:00
* /
2020-02-11 12:58:51 +01:00
getSearchAPIQueryForRefineFields ( URLparams , firstLoad : boolean ) {
2020-01-31 16:12:51 +01:00
var allFqs = "" ;
2020-03-27 13:39:18 +01:00
// console.log(this.refineFields)
2020-01-31 16:12:51 +01:00
for ( var i = 0 ; i < this . refineFields . length ; i ++ ) {
var filterId = this . refineFields [ i ] ;
if ( URLparams [ filterId ] != undefined ) {
2020-02-04 17:33:46 +01:00
let values = ( StringUtils . URIDecode ( StringUtils . URIDecode ( URLparams [ filterId ] ) ) ) . split ( /,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/ , - 1 ) ;
2020-01-31 16:12:51 +01:00
var countvalues = 0 ;
var fq = "" ;
let filterOp : string = this . searchFieldsHelper . getFieldOperator ( filterId ) ;
2020-02-04 14:27:42 +01:00
// console.info(filterId, filterOp);
2020-01-31 16:12:51 +01:00
for ( let value of values ) {
countvalues ++ ;
var paramId = this . fieldIdsMap [ filterId ] . param ;
// parameters+='&' + paramId+ '='+ value;//+"&" + this.fieldIdsMap[paramId].operator + "="+((countvalues == 1)?"and":"or");
fq += ( fq . length > 0 ? " " + filterOp + " " : "" ) + filterId + " exact " + ( value ) ;
}
if ( countvalues > 0 ) {
fq = "&fq=" + StringUtils . URIEncode ( fq ) ;
}
allFqs += fq ;
}
}
2020-07-13 17:23:20 +02:00
this . customFilterEnabled = URLparams [ "cf" ] == "true" ;
if ( this . customFilter && ( this . customFilter . isHiddenFilter || ( this . refineFields . indexOf ( this . customFilter . queryFieldName ) == - 1 && this . customFilterEnabled ) ) ) {
2020-01-31 16:12:51 +01:00
allFqs += "&fq=" + StringUtils . URIEncode ( this . customFilter . queryFieldName + " exact " + StringUtils . quote ( ( this . customFilter . valueId ) ) ) ;
}
2020-02-28 11:05:59 +01:00
if ( this . quickFilter && this . entityType == "result" ) {
if ( ( firstLoad && URLparams [ this . quickFilter . filterId ] == undefined && URLparams [ "qf" ] == undefined ) || URLparams [ "qf" ] == "true"
|| ( ( URLparams [ this . quickFilter . filterId ] != undefined && StringUtils . URIDecode ( URLparams [ this . quickFilter . filterId ] ) . split ( /,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/ , - 1 ) . indexOf ( StringUtils . quote ( this . quickFilter . value ) ) != - 1 ) ) ) {
2020-02-11 12:58:51 +01:00
this . quickFilter . selected = true ;
} else {
this . quickFilter . selected = false ;
}
2020-02-28 11:05:59 +01:00
if ( ( firstLoad && URLparams [ this . quickFilter . filterId ] == undefined && URLparams [ "qf" ] == undefined )
|| ( URLparams [ this . quickFilter . filterId ] == undefined && URLparams [ "qf" ] == "true" ) ) {
2020-02-11 12:58:51 +01:00
allFqs += "&fq=resultbestaccessright exact " + StringUtils . quote ( this . quickFilter . value ) ;
}
}
if ( this . entityType == "result" ) {
if ( URLparams [ "type" ] ) {
2020-10-20 11:11:15 +02:00
let types = URLparams [ "type" ] ;
types = Array . isArray ( types ) ? types . join ( ',' ) . split ( "," ) : types . split ( "," ) ;
types . map ( function ( t ) {
return StringUtils . unquote ( StringUtils . URIDecode ( t ) ) ;
} ) ;
2020-03-30 16:24:56 +02:00
if ( types . indexOf ( "publications" ) != - 1 && types . indexOf ( "datasets" ) != - 1 && types . indexOf ( "software" ) != - 1 && types . indexOf ( "other" ) != - 1 ) {
allFqs += "&type=results" ;
} else {
for ( let type of types ) {
2020-10-20 11:11:15 +02:00
allFqs += "&type=" + StringUtils . unquote ( StringUtils . URIDecode ( type ) ) ;
2020-03-30 16:24:56 +02:00
}
2020-02-11 12:58:51 +01:00
}
2020-02-13 15:44:51 +01:00
} else {
2020-03-30 16:24:56 +02:00
allFqs += "&type=results" ;
2020-02-11 12:58:51 +01:00
}
} else if ( this . entityType == "publication" ) {
allFqs += "&type=publications" ;
} else if ( this . entityType == "dataset" ) {
allFqs += "&type=datasets" ;
} else if ( this . entityType == "software" ) {
allFqs += "&type=software" ;
} else if ( this . entityType == "other" ) {
allFqs += "&type=other" ;
2020-02-24 14:45:22 +01:00
} else if ( this . entityType == "project" ) {
allFqs += "&type=projects" ;
} else if ( this . entityType == "organization" ) {
allFqs += "&type=organizations" ;
} else if ( this . entityType == "dataprovider" ) {
allFqs += "&type=datasources" ;
}
2020-03-27 13:39:18 +01:00
// console.log("AllFqs (check type): "+allFqs);
// console.log("type: "+this.entityType);
2020-01-31 16:12:51 +01:00
// var keyword = URLparams['keyword'];
// var doiQuery = "";
// var keywordQuery = "";
// if((keyword && keyword.length > 0)){
// if((this.type == 'publications' ||this.type == 'research data' || this.type == 'software' || this.type == 'other research products')){
// 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{
// if(this.usedBy == "deposit") {
// if(this.keywordFields.length > 0) {
// keywordQuery = "&fq=";
// }
//
// for(let i=0; i< this.keywordFields.length ; i++) {
// if(i > 0) {
// keywordQuery += " or ";
// }
// let field = this.keywordFields[i];
// //keywordQuery += field.name+field.equalityOperator+StringUtils.URIEncode(keyword);
// keywordQuery += field.name+field.equalityOperator+StringUtils.quote(StringUtils.URIEncode(keyword));
// }
// } else {
// keywordQuery += "&q=" + StringUtils.URIEncode(keyword);
// }
//
// }
// }
//TODO add DOI?
2020-02-11 12:58:51 +01:00
return allFqs ;
2020-01-31 16:12:51 +01:00
}
2020-02-17 15:19:14 +01:00
/ * *
* Create Search API query based on the filters of refine fields
* @param URLparams
* /
getSearchAPIQueryForRangeFields ( URLparams ) {
let allFqs = "" ;
for ( let i = 0 ; i < this . rangeFields . length ; i ++ ) {
let filterId = this . rangeFields [ i ] [ 0 ] + "-range-" + this . rangeFields [ i ] [ 1 ] ;
let filterParam = this . searchFieldsHelper . getFieldParam ( filterId , this . entityType ) ;
if ( URLparams [ filterParam ] != undefined ) {
let values = ( StringUtils . URIDecode ( StringUtils . URIDecode ( URLparams [ filterParam ] ) ) ) . split ( /,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/ , - 1 ) ;
var countvalues = 0 ;
var fq = "" ;
var fqFrom = "" ;
var fqTo = "" ;
let filterOp : string = this . searchFieldsHelper . getFieldOperator ( filterId ) ;
for ( let value of values ) {
if ( this . fieldIdsMap [ filterId ] . filterType == "range" ) {
let selectedFromValue ;
let selectedToValue ;
let years : string [ ] = ( value . substring ( 5 ) ) . split ( ":" ) ;
let yearFrom : string = ( Dates . isValidYear ( years [ 0 ] ) ? years [ 0 ] : null ) ;
//(Number.isInteger(parseInt(years[0], 10)) ? years[0] : null);
let yearTo : string = ( Dates . isValidYear ( years [ 1 ] ) ? years [ 1 ] : null ) ;
//console.log("getSearchAPIQueryForRangeFields: yearFrom: " + yearFrom + " - yearTo: "+yearTo);
if ( yearFrom ) {
selectedFromValue = yearFrom ;
}
if ( yearTo ) {
selectedToValue = yearTo ;
}
if ( yearFrom || yearTo ) {
// if (value.length <= 14) {
// if(Dates.isValidYear(value.substring(5, 9))) {
// selectedFromValue = value.substring(5, 9);
// }
// if(Dates.isValidYear(value.substring(10, 14))) {
// selectedToValue = value.substring(10, 14);
// }
2020-05-14 16:38:50 +02:00
/ * i f ( t h i s . r a n g e F i e l d s [ i ] [ 0 ] = = t h i s . r a n g e F i e l d s [ i ] [ 1 ] ) {
2020-02-17 15:19:14 +01:00
//console.log(selectedFromValue + " - "+selectedToValue);
if ( selectedFromValue && selectedToValue ) {
let equalityOp = this . fieldIdsMap [ filterId ] . equalityOperator ;
fq += ( fq . length > 0 ? " " + filterOp + " " : "" ) + this . rangeFields [ i ] [ 0 ] + equalityOp + "\"" + selectedFromValue + " " + selectedToValue + "\"" ;
fq = "&fq=" + StringUtils . URIEncode ( fq ) ;
} else if ( selectedFromValue ) {
let equalityOp = this . fieldIdsMap [ this . rangeFields [ i ] [ 0 ] ] . equalityOperator ;
if ( equalityOp == " = " ) {
equalityOp = " >= " ;
}
fq += ( fq . length > 0 ? " " + filterOp + " " : "" ) + this . rangeFields [ i ] [ 0 ] + equalityOp + "\"" + selectedFromValue + "\"" ;
fq = "&fq=" + StringUtils . URIEncode ( fq ) ;
} else if ( selectedToValue ) {
let equalityOp = this . fieldIdsMap [ this . rangeFields [ i ] [ 1 ] ] . equalityOperator ;
if ( equalityOp == " = " ) {
equalityOp = " <= " ;
}
fq += ( fq . length > 0 ? " " + filterOp + " " : "" ) + this . rangeFields [ i ] [ 0 ] + equalityOp + "\"" + selectedToValue + "\"" ;
fq = "&fq=" + StringUtils . URIEncode ( fq ) ;
}
} else {
let equalityOpFrom = this . fieldIdsMap [ this . rangeFields [ i ] [ 0 ] ] . equalityOperator ;
let equalityOpTo = this . fieldIdsMap [ this . rangeFields [ i ] [ 1 ] ] . equalityOperator ;
if ( selectedFromValue ) {
fq += ( fq . length > 0 ? " " + filterOp + " " : "" ) + this . rangeFields [ i ] [ 0 ] + equalityOpFrom + "\"" + selectedFromValue + "\"" ;
// fq = "&fq=" + StringUtils.URIEncode(fq);
}
if ( selectedToValue ) {
fq += ( fq . length > 0 ? " " + filterOp + " " : "" ) + this . rangeFields [ i ] [ 1 ] + equalityOpTo + "\"" + selectedToValue + "\"" ;
// fq = "&fq=" + StringUtils.URIEncode(fq);
}
if ( selectedFromValue || selectedToValue ) {
fq = "&fq=" + StringUtils . URIEncode ( fq ) ;
}
2020-05-14 16:38:50 +02:00
} * /
fq = NewSearchPageComponent . createRangeFilterQuery ( this . rangeFields [ i ] , selectedFromValue , selectedToValue , this . fieldIdsMap [ filterId ] . equalityOperator , this . fieldIdsMap [ this . rangeFields [ i ] [ 0 ] ] . equalityOperator , this . fieldIdsMap [ this . rangeFields [ i ] [ 1 ] ] . equalityOperator , filterOp ) ;
2020-02-17 15:19:14 +01:00
}
}
}
allFqs += fq + fqFrom + fqTo ;
}
}
return allFqs ;
}
2020-05-14 16:38:50 +02:00
// createRangeFilterQuery(this.rangeFields[i], selectedFromValue, selectedToValue, this.fieldIdsMap[this.rangeFields[i][0]].equalityOperator, this.fieldIdsMap[this.rangeFields[i][1]].equalityOperator; filterOp )
public static createRangeFilterQuery ( rangeField , selectedFromValue , selectedToValue , equalityOp , equalityOpFrom , equalityOpTo , filterOp ) {
let fq = "" ;
if ( rangeField [ 0 ] == rangeField [ 1 ] ) {
//console.log(selectedFromValue + " - "+selectedToValue);
if ( selectedFromValue && selectedToValue ) {
fq += ( fq . length > 0 ? " " + filterOp + " " : "" ) + rangeField [ 0 ] + equalityOp + "\"" + selectedFromValue + " " + selectedToValue + "\"" ;
fq = "&fq=" + StringUtils . URIEncode ( fq ) ;
} else if ( selectedFromValue ) {
if ( equalityOpFrom == " = " ) {
equalityOpFrom = " >= " ;
}
fq += ( fq . length > 0 ? " " + filterOp + " " : "" ) + rangeField [ 0 ] + equalityOpFrom + "\"" + selectedFromValue + "\"" ;
fq = "&fq=" + StringUtils . URIEncode ( fq ) ;
} else if ( selectedToValue ) {
if ( equalityOpTo == " = " ) {
equalityOpTo = " <= " ;
}
fq += ( fq . length > 0 ? " " + filterOp + " " : "" ) + rangeField [ 0 ] + equalityOpTo + "\"" + selectedToValue + "\"" ;
fq = "&fq=" + StringUtils . URIEncode ( fq ) ;
}
} else {
2020-02-17 15:19:14 +01:00
2020-05-14 16:38:50 +02:00
if ( selectedFromValue ) {
fq += ( fq . length > 0 ? " " + filterOp + " " : "" ) + rangeField [ 0 ] + equalityOpFrom + "\"" + selectedFromValue + "\"" ;
// fq = "&fq=" + StringUtils.URIEncode(fq);
}
if ( selectedToValue ) {
fq += ( fq . length > 0 ? " " + filterOp + " " : "" ) + rangeField [ 1 ] + equalityOpTo + "\"" + selectedToValue + "\"" ;
// fq = "&fq=" + StringUtils.URIEncode(fq);
}
if ( selectedFromValue || selectedToValue ) {
fq = "&fq=" + StringUtils . URIEncode ( fq ) ;
}
}
return fq ;
}
2020-01-31 16:12:51 +01:00
/ * *
2020-02-04 17:33:46 +01:00
* Sets parameterNames and parameterValues arrays
* used in paging , advanced search link , Goto ( )
* @param filters either query filters or filters defined by the URL parameters
2020-02-17 15:19:14 +01:00
* @param rangeFilters defined by the URL parameters
2020-02-04 17:33:46 +01:00
* @param includePage
2020-01-31 16:12:51 +01:00
* /
2020-02-17 15:19:14 +01:00
buildPageURLParameters ( filters :Filter [ ] , rangeFilters : RangeFilter [ ] , includePage : boolean ) {
2020-01-31 16:12:51 +01:00
this . parameterNames . splice ( 0 , this . parameterNames . length ) ;
this . parameterValues . splice ( 0 , this . parameterValues . length ) ;
for ( var i = 0 ; i < this . selectedFields . length ; i ++ ) {
2020-03-04 13:42:52 +01:00
//default operator is and
this . parameterNames . push ( "f" + i ) ;
this . parameterValues . push ( this . selectedFields [ i ] . id + ( this . selectedFields [ i ] . operatorId != 'and' ? ( "," + this . selectedFields [ i ] . operatorId ) : '' ) ) ;
this . parameterNames . push ( "fv" + i ) ;
if ( this . selectedFields [ i ] . type == "date" ) {
if ( this . selectedFields [ i ] . dateValue . type == "range" ) {
this . parameterValues . push ( StringUtils . URIEncode ( "range" + Dates . getDateToString ( this . selectedFields [ i ] . dateValue . from ) + ":" + Dates . getDateToString ( this . selectedFields [ i ] . dateValue . to ) ) ) ;
2020-01-31 16:12:51 +01:00
} else {
2020-03-04 13:42:52 +01:00
this . parameterValues . push ( StringUtils . URIEncode ( this . selectedFields [ i ] . dateValue . type ) ) ;
2020-01-31 16:12:51 +01:00
}
2020-03-04 13:42:52 +01:00
} else {
2020-03-27 13:39:18 +01:00
// console.log(this.selectedFields[i].value +" " + StringUtils.URIEncode(this.selectedFields[i].value))
2020-03-04 13:42:52 +01:00
this . parameterValues . push ( StringUtils . URIEncode ( this . selectedFields [ i ] . value ) ) ;
2020-01-31 16:12:51 +01:00
}
}
2020-07-24 13:21:22 +02:00
if ( includePage ) {
2020-02-04 17:33:46 +01:00
this . parameterNames . push ( "page" ) ;
this . parameterValues . push ( "" + this . searchUtils . page ) ;
2020-01-31 16:12:51 +01:00
}
[Trunk | Library]:
1. searchUtils.class.ts: In SearchUtilsClass added field "refineStatus:number = 1;" for refine queries.
2. searchResultsPerPage.component.ts & searchSorting.component.ts: [Bug fix] In EventEmitter (value change), emit raw value, not object with field "value".
3. searchDataProviders.component.ts & searchOrganizations.component.ts & searchProjects.component.ts & searchResearchResults.component.ts:
a. Add subscriptions in array to unsubscribe in ngOnDestroy.
b. Get properties from environment (no service needed).
c. Separate queries for refine and results.
d. Do not call refine query when page, results per page, sortBy change (there is still a bug here).
e. For refine query, added field "disableRefineForms" default set to false - passed in <new-search-page>.
4. newSearchPage.component.html:
a. Disable forms when "disableForms" or "disableRefineForms" is true.
b. Do not show filters, until results query returns, but show results while refine is loading.
c. Deleted old, unused code.
5. newSearchPage.component.ts:
a. Added fields "@Input() disableRefineForms: boolean = false;", "@Input() sortedByChanged: string = "";", "@Input() resultsPerPageChanged: number;"
b. When results per page or sortBy change, do not upadate immediately searchUtils values - do not query for refine when these change (there is still a bug here).
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59155 d315682c-612b-4755-9ff5-7f18f6832af3
2020-07-21 15:48:55 +02:00
//if (this.searchUtils.size != this.resultsPerPage) {
2020-07-24 13:21:22 +02:00
if ( this . resultsPerPageChanged ) {
2020-01-31 16:12:51 +01:00
this . parameterNames . push ( "size" ) ;
[Trunk | Library]:
1. searchUtils.class.ts: In SearchUtilsClass added field "refineStatus:number = 1;" for refine queries.
2. searchResultsPerPage.component.ts & searchSorting.component.ts: [Bug fix] In EventEmitter (value change), emit raw value, not object with field "value".
3. searchDataProviders.component.ts & searchOrganizations.component.ts & searchProjects.component.ts & searchResearchResults.component.ts:
a. Add subscriptions in array to unsubscribe in ngOnDestroy.
b. Get properties from environment (no service needed).
c. Separate queries for refine and results.
d. Do not call refine query when page, results per page, sortBy change (there is still a bug here).
e. For refine query, added field "disableRefineForms" default set to false - passed in <new-search-page>.
4. newSearchPage.component.html:
a. Disable forms when "disableForms" or "disableRefineForms" is true.
b. Do not show filters, until results query returns, but show results while refine is loading.
c. Deleted old, unused code.
5. newSearchPage.component.ts:
a. Added fields "@Input() disableRefineForms: boolean = false;", "@Input() sortedByChanged: string = "";", "@Input() resultsPerPageChanged: number;"
b. When results per page or sortBy change, do not upadate immediately searchUtils values - do not query for refine when these change (there is still a bug here).
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59155 d315682c-612b-4755-9ff5-7f18f6832af3
2020-07-21 15:48:55 +02:00
//this.parameterValues.push("" + this.searchUtils.size);
this . parameterValues . push ( "" + this . resultsPerPageChanged ) ;
2020-01-31 16:12:51 +01:00
}
[Trunk | Library]:
1. searchUtils.class.ts: In SearchUtilsClass added field "refineStatus:number = 1;" for refine queries.
2. searchResultsPerPage.component.ts & searchSorting.component.ts: [Bug fix] In EventEmitter (value change), emit raw value, not object with field "value".
3. searchDataProviders.component.ts & searchOrganizations.component.ts & searchProjects.component.ts & searchResearchResults.component.ts:
a. Add subscriptions in array to unsubscribe in ngOnDestroy.
b. Get properties from environment (no service needed).
c. Separate queries for refine and results.
d. Do not call refine query when page, results per page, sortBy change (there is still a bug here).
e. For refine query, added field "disableRefineForms" default set to false - passed in <new-search-page>.
4. newSearchPage.component.html:
a. Disable forms when "disableForms" or "disableRefineForms" is true.
b. Do not show filters, until results query returns, but show results while refine is loading.
c. Deleted old, unused code.
5. newSearchPage.component.ts:
a. Added fields "@Input() disableRefineForms: boolean = false;", "@Input() sortedByChanged: string = "";", "@Input() resultsPerPageChanged: number;"
b. When results per page or sortBy change, do not upadate immediately searchUtils values - do not query for refine when these change (there is still a bug here).
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59155 d315682c-612b-4755-9ff5-7f18f6832af3
2020-07-21 15:48:55 +02:00
//if (this.sort && this.searchUtils.sortBy) {
if ( this . sort && this . sortByChanged ) {
2020-01-31 16:12:51 +01:00
this . parameterNames . push ( "sortBy" ) ;
[Trunk | Library]:
1. searchUtils.class.ts: In SearchUtilsClass added field "refineStatus:number = 1;" for refine queries.
2. searchResultsPerPage.component.ts & searchSorting.component.ts: [Bug fix] In EventEmitter (value change), emit raw value, not object with field "value".
3. searchDataProviders.component.ts & searchOrganizations.component.ts & searchProjects.component.ts & searchResearchResults.component.ts:
a. Add subscriptions in array to unsubscribe in ngOnDestroy.
b. Get properties from environment (no service needed).
c. Separate queries for refine and results.
d. Do not call refine query when page, results per page, sortBy change (there is still a bug here).
e. For refine query, added field "disableRefineForms" default set to false - passed in <new-search-page>.
4. newSearchPage.component.html:
a. Disable forms when "disableForms" or "disableRefineForms" is true.
b. Do not show filters, until results query returns, but show results while refine is loading.
c. Deleted old, unused code.
5. newSearchPage.component.ts:
a. Added fields "@Input() disableRefineForms: boolean = false;", "@Input() sortedByChanged: string = "";", "@Input() resultsPerPageChanged: number;"
b. When results per page or sortBy change, do not upadate immediately searchUtils values - do not query for refine when these change (there is still a bug here).
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59155 d315682c-612b-4755-9ff5-7f18f6832af3
2020-07-21 15:48:55 +02:00
//this.parameterValues.push(this.searchUtils.sortBy);
this . parameterValues . push ( this . sortedByChanged ) ;
2020-01-31 16:12:51 +01:00
}
2020-02-04 17:33:46 +01:00
for ( let filter of filters ) {
2020-01-31 16:12:51 +01:00
var filterLimits = "" ;
if ( filter . countSelectedValues > 0 ) {
for ( let value of filter . values ) {
if ( value . selected == true ) {
filterLimits += ( ( filterLimits . length == 0 ) ? '' : ',' ) + '"' + ( value . id ) + '"' ;
}
}
if ( filterLimits . length > 0 ) {
this . parameterNames . push ( filter . filterId ) ;
this . parameterValues . push ( filterLimits ) ;
}
}
}
2020-02-17 15:19:14 +01:00
for ( let filter of rangeFilters ) {
var filterLimits = "" ;
let yearFrom : string = ( Dates . isValidYear ( filter . selectedFromValue ) ? filter.selectedFromValue : null ) ;
let yearTo : string = ( Dates . isValidYear ( filter . selectedToValue ) ? filter.selectedToValue : null ) ;
if ( yearFrom || yearTo ) {
this . parameterNames . push ( filter . filterId ) ;
this . parameterValues . push ( "range" + ( yearFrom ? yearFrom : "" ) + ":" + ( yearTo ? yearTo : "" ) ) ;
}
// if (filter.countSelectedValues > 0) {
// for (let value of filter.values) {
// if (value.selected == true) {
// filterLimits += ((filterLimits.length == 0) ? '' : ',') + '"' + (value.id) + '"';
// }
// }
// if (filterLimits.length > 0) {
// this.parameterNames.push(filter.filterId);
// this.parameterValues.push(filterLimits);
// }
// }
}
2020-01-31 16:12:51 +01:00
if ( this . searchUtils . keyword . length > 0 ) {
this . parameterNames . push ( "keyword" ) ;
this . parameterValues . push ( this . searchUtils . keyword ) ;
}
2020-10-20 13:21:37 +02:00
if ( this . resultTypes && ( this . entityType == 'publication' || this . entityType == 'dataset' || this . entityType == 'software' || this . entityType == 'other' || this . entityType == "result" ) ) {
2020-02-11 12:58:51 +01:00
let values = [ ] ;
2020-10-20 11:11:15 +02:00
for ( let value of this . resultTypes . values ) {
2020-10-20 17:11:40 +02:00
if ( value . selected ) {
values . push ( value . id ) ;
}
2020-02-11 12:58:51 +01:00
}
2020-06-01 11:02:16 +02:00
this . selectedTypesNum = 0 ;
if ( values . length > 0 && values . length != 4 ) {
2020-02-11 12:58:51 +01:00
this . parameterNames . push ( "type" ) ;
this . parameterValues . push ( values . join ( "," ) ) ;
2020-06-01 11:02:16 +02:00
this . selectedTypesNum = values . length ;
2020-02-11 12:58:51 +01:00
}
if ( this . quickFilter ) {
this . parameterNames . push ( "qf" ) ;
this . parameterValues . push ( "" + this . quickFilter . selected ) ;
}
}
2020-07-13 17:23:20 +02:00
if ( this . customFilterEnabled ) {
this . parameterNames . push ( "cf" ) ;
this . parameterValues . push ( "true" ) ;
}
2020-02-04 17:33:46 +01:00
// if (this.searchUtils.size != this.resultsPerPage) {
// // 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);
// }
2020-02-28 11:05:59 +01:00
// console.log(this.parameterNames)
// console.log(this.parameterValues)
2020-01-31 16:12:51 +01:00
}
2020-02-04 17:33:46 +01:00
/ * *
* create filters based on URL params
* @param URLparams
* /
getRefineFiltersFromURL ( URLparams ) {
2020-02-04 14:27:42 +01:00
let fields = new SearchFields ( ) ;
let filters : Filter [ ] = [ ] ;
for ( let i = 0 ; i < this . refineFields . length ; i ++ ) {
let filterId = this . refineFields [ i ] ;
if ( URLparams [ filterId ] != undefined ) {
let filter = new Filter ( ) ;
2020-02-11 15:56:20 +01:00
filter . title = fields . getFieldName ( filterId , this . entityType ) ;
2020-02-04 14:27:42 +01:00
filter . filterId = filterId ;
filter . originalFilterId = filterId ;
filter . values = [ ] ;
let values = StringUtils . URIDecode ( URLparams [ filterId ] ) . split ( /,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/ , - 1 ) ;
for ( let value of values ) {
let v : Value = new Value ( ) ;
v . name = RefineResultsUtils . keepPartAfterCharacters ( StringUtils . unquote ( value ) , "||" ) ;
2020-06-01 11:02:16 +02:00
v . name = ( v . name . indexOf ( "::" ) != - 1 ) ? v . name . substring ( v . name . indexOf ( "::" ) + 2 ) . split ( "::" ) . join ( "|" ) : v . name ; // for funding streams
2020-02-04 14:27:42 +01:00
v . id = StringUtils . unquote ( value ) ;
v . selected = true ;
filter . values . push ( v ) ;
// console.log(v)
filter . countSelectedValues ++ ;
}
filters . push ( filter )
}
}
2020-02-11 12:58:51 +01:00
if ( this . quickFilter ) {
if ( this . entityType == "result" && ( URLparams [ this . quickFilter . filterId ] == undefined ) && ( URLparams [ "qf" ] == undefined || URLparams [ "qf" ] == "true" ) ) {
let filter = new Filter ( ) ;
2020-02-17 15:19:14 +01:00
filter . title = fields . getFieldName ( this . quickFilter . filterId , this . entityType ) ;
2020-02-11 12:58:51 +01:00
filter . filterId = this . quickFilter . filterId ;
filter . originalFilterId = this . quickFilter . filterId ;
filter . values = [ ] ;
let v : Value = new Value ( ) ;
v . name = this . quickFilter . value ;
v . id = this . quickFilter . value ;
v . selected = true ;
filter . values . push ( v ) ;
filter . countSelectedValues = 1 ;
filters . push ( filter )
}
}
2020-10-20 13:21:37 +02:00
if ( ( this . entityType == 'publication' || this . entityType == 'dataset' || this . entityType == 'software' || this . entityType == 'other' || this . entityType == "result" ) ) {
this . resultTypes = { values : [ ] , filterId : "type" , countSelectedValues : 0 , filterType : 'checkbox' , originalFilterId : "" , valueIsExact : true , title : "Result Types" , filterOperator : "or" } ;
2020-02-11 12:58:51 +01:00
if ( URLparams [ "type" ] ) {
2020-10-20 11:11:15 +02:00
let types = URLparams [ "type" ] ;
types = Array . isArray ( types ) ? types . join ( ',' ) . split ( "," ) : types . split ( "," ) ;
for ( let type of types ) {
if ( [ "publications" , "datasets" , "software" , "other" ] . indexOf ( StringUtils . unquote ( type ) ) != - 1 && this . resultTypeOptions [ StringUtils . unquote ( type ) ] ) {
this . resultTypes . values . push ( { name : this.resultTypeOptions [ StringUtils . unquote ( type ) ] . name , id :StringUtils.unquote ( type ) , selected :true , number : 0 } ) ;
2020-10-20 17:11:40 +02:00
this . resultTypes . countSelectedValues ++ ;
2020-10-20 11:11:15 +02:00
}
}
2020-02-11 12:58:51 +01:00
}
}
this . URLCreatedFilters = filters ;
2020-02-04 14:27:42 +01:00
}
2020-02-17 15:19:14 +01:00
/ * *
* create range filters based on URL params
* @param URLparams
* /
getRangeFiltersFromURL ( URLparams ) {
let fields = new SearchFields ( ) ;
let filters : RangeFilter [ ] = [ ] ;
for ( let i = 0 ; i < this . rangeFields . length ; i ++ ) {
let filterId = this . rangeFields [ i ] [ 0 ] + "-range-" + this . rangeFields [ i ] [ 1 ] ;
let filterParam = fields . getFieldParam ( filterId , this . entityType ) ;
//console.log("rangeFilter (from url): filterId - filterParam");
//console.log(filterId + " - "+ filterParam);
if ( URLparams [ filterParam ] != undefined ) {
let filter = new RangeFilter ( ) ;
filter . title = fields . getFieldName ( filterId , this . entityType ) ;
filter . filterId = filterParam ;
filter . originalFilterIdFrom = this . rangeFields [ i ] [ 0 ] ;
filter . originalFilterIdTo = this . rangeFields [ i ] [ 1 ] ;
let values = ( decodeURIComponent ( URLparams [ filterParam ] ) ) . split ( /,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/ , - 1 ) ;
for ( let j = 0 ; j < values . length ; j ++ ) {
if ( this . fieldIdsMap [ filterId ] . filterType == "range" ) {
let value : string = StringUtils . unquote ( values [ j ] ) ;
let validDates : boolean = true ;
// if (value.length < 14) {
// validDates = false;
// } else {
// if (!Dates.isValidYear(value.substring(5, 9)) || !Dates.isValidYear(value.substring(10, 14))) {
// validDates = false;
// } else {
// filter.selectedFromValue = value.substring(5, 9);
// filter.selectedToValue = value.substring(10, 14);
// }
// }
let years : string [ ] = ( value . substring ( 5 ) ) . split ( ":" ) ;
let yearFrom : string = ( Dates . isValidYear ( years [ 0 ] ) ? years [ 0 ] : null ) ;
let yearTo : string = ( Dates . isValidYear ( years [ 1 ] ) ? years [ 1 ] : null ) ;
//console.log("getRangeFiltersFromURL: yearFrom: " + yearFrom + " - yearTo: "+yearTo);
if ( yearFrom ) {
filter . selectedFromValue = yearFrom ;
//filter.selectedFromAndToValues = yearFrom;
}
/ * i f ( y e a r F r o m & & y e a r T o ) {
filter . selectedFromAndToValues += "-" ;
} * /
if ( yearTo ) {
filter . selectedToValue = yearTo ;
//filter.selectedFromAndToValues += yearTo;
}
//console.log("filter.selectedFromAndToValues: "+filter.selectedFromAndToValues);
if ( ! yearFrom && ! yearTo ) {
validDates = false ;
}
}
}
//console.log(filters);
filters . push ( filter )
}
}
// console.log("Empty Filters");
// console.log(filters);
this . URLCreatedRangeFilters = filters ;
// return filters;
}
2020-02-04 14:27:42 +01:00
/ * *
* Checks if query has no results , display Filters from URL parameters
* Mark checked the selected filters
* Count the checked
* @param filters
* /
2020-03-30 16:24:56 +02:00
public prepareFiltersToShow ( filters : Filter [ ] , totalResults ) : Filter [ ] {
if ( this . URLCreatedFilters . length > 0 && totalResults == 0 ) {
2020-02-04 14:27:42 +01:00
this . showUnknownFilters = true ;
2020-02-04 17:33:46 +01:00
this . filters = this . URLCreatedFilters ;
2020-03-30 16:24:56 +02:00
} else if ( totalResults != 0 ) {
2020-02-04 14:27:42 +01:00
this . showUnknownFilters = false ;
this . filters = filters ;
2020-05-21 15:17:28 +02:00
} else if ( ( this . URLCreatedFilters . length == 0 && totalResults == 0 ) ) {
this . showUnknownFilters = true ;
this . filters = filters ;
2020-02-04 14:27:42 +01:00
}
[Trunk | Library]:
1. searchUtils.class.ts: In SearchUtilsClass added field "refineStatus:number = 1;" for refine queries.
2. searchResultsPerPage.component.ts & searchSorting.component.ts: [Bug fix] In EventEmitter (value change), emit raw value, not object with field "value".
3. searchDataProviders.component.ts & searchOrganizations.component.ts & searchProjects.component.ts & searchResearchResults.component.ts:
a. Add subscriptions in array to unsubscribe in ngOnDestroy.
b. Get properties from environment (no service needed).
c. Separate queries for refine and results.
d. Do not call refine query when page, results per page, sortBy change (there is still a bug here).
e. For refine query, added field "disableRefineForms" default set to false - passed in <new-search-page>.
4. newSearchPage.component.html:
a. Disable forms when "disableForms" or "disableRefineForms" is true.
b. Do not show filters, until results query returns, but show results while refine is loading.
c. Deleted old, unused code.
5. newSearchPage.component.ts:
a. Added fields "@Input() disableRefineForms: boolean = false;", "@Input() sortedByChanged: string = "";", "@Input() resultsPerPageChanged: number;"
b. When results per page or sortBy change, do not upadate immediately searchUtils values - do not query for refine when these change (there is still a bug here).
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59155 d315682c-612b-4755-9ff5-7f18f6832af3
2020-07-21 15:48:55 +02:00
2020-02-17 15:19:14 +01:00
this . buildPageURLParameters ( this . URLCreatedFilters , this . URLCreatedRangeFilters , true ) ;
//this.checkSelectedRangeFilters(this.rangeFilters);
2020-02-04 14:27:42 +01:00
this . checkSelectedFilters ( this . filters ) ;
this . countSelectedFilters ( this . filters ) ;
return this . filters ;
}
2020-02-17 15:19:14 +01:00
/ * *
* Mark checked the selected range filters
* /
public prepareRangeFiltersToShow() {
this . rangeFilters = RangeFilter . parse ( this . rangeFields , this . entityType ) ; // OK
//this.buildPageURLRangeParameters(this.rangeFilters, true);
this . checkSelectedRangeFilters ( this . rangeFilters ) ;
this . countSelectedRangeFilters ( this . rangeFilters ) ;
return this . rangeFilters ;
}
2020-02-04 17:33:46 +01:00
/ * *
* Used to set the variables and search page , and prepare it before the getResults query
* @param fieldIds
* @param selectedFields
* @param refineFields
2020-03-12 18:03:35 +01:00
* @param rangeFields
2020-02-04 17:33:46 +01:00
* @param fieldIdsMap
* @param customFilter
* @param params
2020-03-12 18:03:35 +01:00
* @param entityType
* @param quickFilter
2020-02-04 17:33:46 +01:00
* /
2020-02-17 15:19:14 +01:00
prepareSearchPage ( fieldIds , selectedFields , refineFields , rangeFields , fieldIdsMap , customFilter , params , entityType , quickFilter = null ) {
2020-03-27 13:39:18 +01:00
// console.log(this.refineFields);
2020-02-11 12:58:51 +01:00
this . entityType = entityType ;
this . fieldIds = fieldIds ;
this . selectedFields = selectedFields ;
this . refineFields = refineFields ;
2020-02-17 15:19:14 +01:00
this . rangeFields = rangeFields ;
2020-02-11 12:58:51 +01:00
this . fieldIdsMap = fieldIdsMap ;
this . customFilter = customFilter ;
2020-02-13 15:44:51 +01:00
this . quickFilter = quickFilter ;
2020-02-17 15:19:14 +01:00
this . getRangeFiltersFromURL ( params ) ;
2020-02-11 12:58:51 +01:00
this . getRefineFiltersFromURL ( params ) ;
this . createAdvancedSearchSelectedFiltersFromURLParameters ( params ) ;
}
2020-06-01 11:02:16 +02:00
removeResultType ( type ) {
if ( this . resultTypes && this . resultTypes [ type ] ) {
this . resultTypes [ type ] = false ;
this . goTo ( 1 ) ;
}
}
2020-01-31 16:12:51 +01:00
}