@ -33,6 +33,7 @@ import {NewSearchPageComponent, SearchForm} from "../searchUtils/newSearchPage.c
import { properties } from "../../../../environments/environment" ;
import { Breadcrumb } from "../../utils/breadcrumbs/breadcrumbs.component" ;
import { LayoutService } from "../../dashboard/sharedComponents/sidebar/layout.service" ;
import { GroupedRequestsService } from "../../services/groupedRequests.service" ;
@Component ( {
selector : 'search-all' ,
@ -41,8 +42,9 @@ import {LayoutService} from "../../dashboard/sharedComponents/sidebar/layout.ser
export class SearchAllComponent {
isMobile : boolean = false ;
reload : { result :boolean , projects :boolean , datasources : boolean , services : boolean , organizations :boolean } =
{ result :true , projects :true , datasources : true , services : true , organizations :true } ;
reload : { result :boolean , projects :boolean , datasources : boolean , services : boolean , organizations :boolean , all : boolean } =
{ result :true , projects :true , datasources : true , services : true , organizations : true , all : true } ;
allCounts = null ;
public pageTitle = "Search in OpenAIRE"
public keyword : string = "" ;
public publications : string [ ] ;
@ -126,6 +128,7 @@ export class SearchAllComponent {
private _searchProjectsService : SearchProjectsService ,
private _searchOrganizationsService : SearchOrganizationsService ,
private _refineFieldResultsService : RefineFieldResultsService ,
private groupedRequestsService : GroupedRequestsService ,
private location : Location ,
private _meta : Meta ,
private _title : Title ,
@ -216,44 +219,48 @@ export class SearchAllComponent {
loadAll() {
this . reloadTabs ( ) ;
this . subs . push ( this . route . queryParams . subscribe ( queryParams = > {
this . parameters = Object . assign ( { } , queryParams ) ;
this . keyword = ( queryParams [ 'keyword' ] ) ? queryParams [ 'keyword' ] : ( queryParams [ "q" ] ? queryParams [ "q" ] : ( queryParams [ "f0" ] && queryParams [ "f0" ] == "q" && queryParams [ "fv0" ] ? queryParams [ "fv0" ] : "" ) ) ;
this . selectedFields [ 0 ] . value = StringUtils . URIDecode ( this . keyword ) ;
this . quickFilter . selected = ( ( queryParams [ 'qf' ] == undefined || queryParams [ "qf" ] == "true" ) == true ) ;
if ( queryParams [ "type" ] && queryParams [ "type" ] . length > 0 ) {
this . resultTypes [ 'publication' ] = ( queryParams [ "type" ] . split ( "," ) . indexOf ( "publications" ) != - 1 ) ;
this . resultTypes [ 'dataset' ] = ( queryParams [ "type" ] . split ( "," ) . indexOf ( "datasets" ) != - 1 ) ;
this . resultTypes [ 'software' ] = ( queryParams [ "type" ] . split ( "," ) . indexOf ( "software" ) != - 1 ) ;
this . resultTypes [ 'other' ] = ( queryParams [ "type" ] . split ( "," ) . indexOf ( "other" ) != - 1 ) ;
}
let active = null ;
if ( queryParams [ "active" ] && queryParams [ "active" ] . length > 0 ) {
active = ( ( [ "result" , "projects" , "organizations" , "datasources" , "services" ] ) . indexOf ( queryParams [ "active" ] ) != - 1 ) ? queryParams [ "active" ] : null ;
delete this . parameters [ 'active' ] ;
}
this . subs . push ( this . route . params . subscribe ( params = > {
if ( this . activeEntity == null && ( ! params [ "entity" ] || params [ "entity" ] . length == 0 ) ) {
if ( active ) {
this . activeEntity = active ;
if ( ( typeof document !== 'undefined' ) ) {
if ( active == "result" ) {
active = "research-outcomes" ;
this . subs . push ( this . route . queryParams . subscribe ( queryParams = > {
this . parameters = Object . assign ( { } , queryParams ) ;
this . keyword = ( queryParams [ 'keyword' ] ) ? queryParams [ 'keyword' ] : ( queryParams [ "q" ] ? queryParams [ "q" ] : ( queryParams [ "f0" ] && queryParams [ "f0" ] == "q" && queryParams [ "fv0" ] ? queryParams [ "fv0" ] : "" ) ) ;
this . selectedFields [ 0 ] . value = StringUtils . URIDecode ( this . keyword ) ;
// this.quickFilter.selected = ((queryParams['qf']== undefined || queryParams["qf"] == "true") == true);
if ( queryParams [ "type" ] && queryParams [ "type" ] . length > 0 ) {
this . resultTypes [ 'publication' ] = ( queryParams [ "type" ] . split ( "," ) . indexOf ( "publications" ) != - 1 ) ;
this . resultTypes [ 'dataset' ] = ( queryParams [ "type" ] . split ( "," ) . indexOf ( "datasets" ) != - 1 ) ;
this . resultTypes [ 'software' ] = ( queryParams [ "type" ] . split ( "," ) . indexOf ( "software" ) != - 1 ) ;
this . resultTypes [ 'other' ] = ( queryParams [ "type" ] . split ( "," ) . indexOf ( "other" ) != - 1 ) ;
}
let active = null ;
if ( queryParams [ "active" ] && queryParams [ "active" ] . length > 0 ) {
active = ( ( [ "result" , "projects" , "organizations" , "datasources" , "services" ] ) . indexOf ( queryParams [ "active" ] ) != - 1 ) ? queryParams [ "active" ] : null ;
delete this . parameters [ 'active' ] ;
}
if ( this . activeEntity == null ) {
if ( this . activeEntity == null && ( ! params [ "entity" ] || params [ "entity" ] . length == 0 ) ) {
if ( active ) {
this . activeEntity = active ;
if ( ( typeof document !== 'undefined' ) ) {
if ( active == "result" ) {
active = "research-outcomes" ;
}
let query = location . search . replace ( /(active=)([^&]*)&?/ , '' ) ;
this . location . go ( location . pathname + '/' + active , query == '?' ? '' : query ) ;
}
let query = location . search . replace ( /(active=)([^&]*)&?/ , '' ) ;
this . location . go ( location . pathname + '/' + active , query == '?' ? '' : query ) ;
} else {
this . activeEntity = this . getDefaultEntityToShow ( ) ;
}
} else {
this . activeEntity = this . getDefaultEntityToShow ( ) ;
}
} else if ( params [ "entity" ] && params [ "entity" ] . length > 0 ) {
let entity = params [ "entity" ] ;
if ( entity == "research-outcomes" ) {
entity = "result" ;
} else if ( entity == "dataproviders" ) {
entity = "datasources" ;
} else if ( params [ "entity" ] && params [ "entity" ] . length > 0 ) {
let entity = params [ "entity" ] ;
if ( entity == "research-outcomes" ) {
entity = "result" ;
} else if ( entity == "dataproviders" ) {
entity = "datasources" ;
}
this . activeEntity = ( ( [ "result" , "projects" , "organizations" , "datasources" , "services" ] ) . indexOf ( entity ) != - 1 ) ? entity : this.getDefaultEntityToShow ( ) ;
}
this . activeEntity = ( ( [ "result" , "projects" , "organizations" , "datasources" , "services" ] ) . indexOf ( entity ) != - 1 ) ? entity :this.getDefaultEntityToShow ( ) ;
}
if ( this . activeEntity == "result" ) {
this . searchResults ( ) ;
@ -409,120 +416,176 @@ export class SearchAllComponent {
private count() {
var refineParams = null ;
let groupedQuery : boolean = false ;
let reload = JSON . parse ( JSON . stringify ( this . reload ) ) ;
if ( this . customFilter ) {
refineParams = ( refineParams ? ( refineParams + '&' ) : '' ) + "&fq=" + StringUtils . URIEncode ( this . customFilter . queryFieldName + " exact " + StringUtils . quote ( ( this . customFilter . valueId ) ) ) ;
} else if ( ! this . keyword || this . keyword . length == 0 ) {
groupedQuery = true ;
}
if ( this . activeEntity != "result" && this . reload [ "result" ] && ( this . showPublications || this . showSoftware || this . datasets || this . showOrps ) ) {
this . fetchPublications . searchUtils . status = this . errorCodes . LOADING ;
this . reload [ "result" ] = false ;
this . fetchPublications . results = [ ] ;
//Add Open Access Filter
this . subs . push ( this . numOfSearchResults ( this . fetchPublications , ( refineParams ? ( refineParams + '&' ) : '' ) + ( this . openAccess ? "&fq=resultbestaccessright%20exact%20%22Open%20Access%22" : "" ) ) ) ;
if ( ! groupedQuery ) {
//Add Open Access Filter
this . subs . push ( this . numOfSearchResults ( this . fetchPublications , ( refineParams ? ( refineParams ) : '' ) ) ) ;
}
}
if ( this . activeEntity != "projects" && this . reload [ "projects" ] && this . showProjects ) {
this . fetchProjects . searchUtils . status = this . errorCodes . LOADING ;
this . fetchProjects . results = [ ] ;
this . reload [ "projects" ] = false ;
this . subs . push ( this . _searchProjectsService . numOfSearchProjects2 ( this . keyword . length > 0 ? NewSearchPageComponent . createKeywordQuery ( "project" , this . keyword , "q" , "=" ) : "" , this . properties , refineParams ) . subscribe (
data = > {
this . fetchProjects . searchUtils . totalResults = data ;
this . fetchProjects . searchUtils . status = this . errorCodes . DONE ;
if ( this . fetchProjects . searchUtils . totalResults == 0 ) {
this . fetchProjects . searchUtils . status = this . errorCodes . NONE ;
if ( ! groupedQuery ) {
this . subs . push ( this . _searchProjectsService . numOfSearchProjects2 ( this . keyword . length > 0 ? NewSearchPageComponent . createKeywordQuery ( "project" , this . keyword , "q" , "=" ) : "" , this . properties , refineParams ) . subscribe (
data = > {
this . fetchProjects . searchUtils . totalResults = data ;
this . fetchProjects . searchUtils . status = this . errorCodes . DONE ;
if ( this . fetchProjects . searchUtils . totalResults == 0 ) {
this . fetchProjects . searchUtils . status = this . errorCodes . NONE ;
}
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting number of " + OpenaireEntities . PROJECTS , err ) ;
this . fetchProjects . searchUtils . status = this . errorCodes . ERROR ;
this . fetchProjects . searchUtils . totalResults = null ;
}
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting number of " + OpenaireEntities . PROJECTS , err ) ;
this . fetchProjects . searchUtils . status = this . errorCodes . ERROR ;
this . fetchProjects . searchUtils . totalResults = null ;
}
) ) ;
) ) ;
}
}
if ( this . activeEntity != "datasources" && this . reload [ "datasources" ] && this . showDataProviders ) {
this . fetchDataproviders . results = [ ] ;
this . reload [ "datasources" ] = false ;
// this.fetchDataproviders.getNumForSearch(this.keyword, this.properties, refineParams);
this . subs . push ( this . _searchDataprovidersService . numOfSearchDataproviders2 ( this . keyword . length > 0 ? NewSearchPageComponent . createKeywordQuery ( "dataprovider" , this . keyword , "q" , "=" ) : "" , this . properties , refineParams ) . subscribe (
data = > {
this . fetchDataproviders . searchUtils . totalResults = data ;
this . fetchDataproviders . searchUtils . status = this . errorCodes . DONE ;
if ( this . fetchDataproviders . searchUtils . totalResults == 0 ) {
this . fetchDataproviders . searchUtils . status = this . errorCodes . NONE ;
if ( ! groupedQuery ) {
// this.fetchDataproviders.getNumForSearch(this.keyword, this.properties, refineParams);
this . subs . push ( this . _searchDataprovidersService . numOfSearchDataproviders2 ( this . keyword . length > 0 ? NewSearchPageComponent . createKeywordQuery ( "dataprovider" , this . keyword , "q" , "=" ) : "" , this . properties , refineParams ) . subscribe (
data = > {
this . fetchDataproviders . searchUtils . totalResults = data ;
this . fetchDataproviders . searchUtils . status = this . errorCodes . DONE ;
if ( this . fetchDataproviders . searchUtils . totalResults == 0 ) {
this . fetchDataproviders . searchUtils . status = this . errorCodes . NONE ;
}
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting number of " + OpenaireEntities . DATASOURCES , err ) ;
this . fetchDataproviders . searchUtils . status = this . errorCodes . ERROR ;
this . fetchDataproviders . searchUtils . totalResults = null ;
}
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting number of " + OpenaireEntities . DATASOURCES , err ) ;
this . fetchDataproviders . searchUtils . status = this . errorCodes . ERROR ;
this . fetchDataproviders . searchUtils . totalResults = null ;
}
) ) ;
) ) ;
}
}
if ( this . activeEntity != "services" && this . reload [ "services" ] && this . showServices ) {
this . fetchServices . results = [ ] ;
this . reload [ "services" ] = false ;
this . subs . push ( this . _searchDataprovidersService . numOfSearchDataproviders2 ( this . keyword . length > 0 ? NewSearchPageComponent . createKeywordQuery ( "service" , this . keyword , "q" , "=" ) : "" , this . properties , refineParams , "services" ) . subscribe (
data = > {
this . fetchServices . searchUtils . totalResults = data ;
this . fetchServices . searchUtils . status = this . errorCodes . DONE ;
if ( this . fetchServices . searchUtils . totalResults == 0 ) {
this . fetchServices . searchUtils . status = this . errorCodes . NONE ;
if ( ! groupedQuery ) {
this . subs . push ( this . _searchDataprovidersService . numOfSearchDataproviders2 ( this . keyword . length > 0 ? NewSearchPageComponent . createKeywordQuery ( "service" , this . keyword , "q" , "=" ) : "" , this . properties , refineParams , "services" ) . subscribe (
data = > {
this . fetchServices . searchUtils . totalResults = data ;
this . fetchServices . searchUtils . status = this . errorCodes . DONE ;
if ( this . fetchServices . searchUtils . totalResults == 0 ) {
this . fetchServices . searchUtils . status = this . errorCodes . NONE ;
}
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting number of " + OpenaireEntities . SERVICES , err ) ;
this . fetchServices . searchUtils . status = this . errorCodes . ERROR ;
this . fetchServices . searchUtils . totalResults = null ;
}
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting number of " + OpenaireEntities . SERVICES , err ) ;
this . fetchServices . searchUtils . status = this . errorCodes . ERROR ;
this . fetchServices . searchUtils . totalResults = null ;
}
) ) ;
) ) ;
}
}
if ( this . activeEntity != "organizations" && this . reload [ "organizations" ] && this . showOrganizations ) {
this . fetchOrganizations . searchUtils . status = this . errorCodes . LOADING ;
this . fetchOrganizations . results = [ ] ;
this . reload [ "organizations" ] = false ;
this . subs . push ( this . _searchOrganizationsService . numOfSearchOrganizations2 ( this . keyword . length > 0 ? NewSearchPageComponent . createKeywordQuery ( "organizations" , this . keyword , "q" , "=" ) : "" , this . properties , refineParams ) . subscribe (
data = > {
this . fetchOrganizations . searchUtils . totalResults = data ;
this . fetchOrganizations . searchUtils . status = this . errorCodes . DONE ;
if ( this . fetchOrganizations . searchUtils . totalResults == 0 ) {
this . fetchOrganizations . searchUtils . status = this . errorCodes . NONE ;
}
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting number of " + OpenaireEntities . ORGANIZATIONS , err ) ;
this . fetchOrganizations . searchUtils . status = this . errorCodes . ERROR ;
this . fetchOrganizations . searchUtils . totalResults = null ;
if ( ! groupedQuery ) {
this . subs . push ( this . _searchOrganizationsService . numOfSearchOrganizations2 ( this . keyword . length > 0 ? NewSearchPageComponent . createKeywordQuery ( "organizations" , this . keyword , "q" , "=" ) : "" , this . properties , refineParams ) . subscribe (
data = > {
this . fetchOrganizations . searchUtils . totalResults = data ;
this . fetchOrganizations . searchUtils . status = this . errorCodes . DONE ;
if ( this . fetchOrganizations . searchUtils . totalResults == 0 ) {
this . fetchOrganizations . searchUtils . status = this . errorCodes . NONE ;
}
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting number of " + OpenaireEntities . ORGANIZATIONS , err ) ;
this . fetchOrganizations . searchUtils . status = this . errorCodes . ERROR ;
this . fetchOrganizations . searchUtils . totalResults = null ;
}
) ) ;
}
) ) ;
}
}
if ( groupedQuery && ( reload [ "result" ] || reload [ "datasources" ] || reload [ "projects" ] || reload [ "organizations" ] ) ) {
if ( this . reload [ "all" ] ) {
this . reload [ "all" ] = false ;
this . subs . push ( this . groupedRequestsService . search ( ) . subscribe (
data = > {
this . allCounts = data ;
this . setDefaultCounts ( ) ;
} ,
err = > {
this . handleError ( "Error getting number of search entities" , err ) ;
this . numErrorReturned ( this . fetchPublications ) ;
this . numErrorReturned ( this . fetchDataproviders ) ;
this . numErrorReturned ( this . fetchOrganizations ) ;
this . numErrorReturned ( this . fetchProjects ) ;
}
) ) ;
} else {
this . setDefaultCounts ( ) ;
}
}
}
private numOfSearchResults ( fetchClass : FetchResearchResults , refineParams ) : Subscription {
return this . _searchResearchResultsService . numOfResearchOutcomes ( this . keyword . length > 0 ? NewSearchPageComponent . createKeywordQuery ( "result" , this . keyword , "q" , "=" ) : "" , this . properties , refineParams ) . subscribe (
data = > {
fetchClass . searchUtils . totalResults = data ;
fetchClass . searchUtils . status = this . errorCodes . DONE ;
if ( fetchClass . searchUtils . totalResults == 0 ) {
fetchClass . searchUtils . status = this . errorCodes . NONE ;
}
this . numReturned ( fetchClass , data ) ;
} ,
err = > {
this . handleError ( "Error getting number of research results" , err ) ;
fetchClass . searchUtils . status = this . errorCodes . ERROR ;
fetchClass . searchUtils . totalResults = null ;
this . numErrorReturned ( fetchClass ) ;
}
) ;
}
private setDefaultCounts() {
if ( this . activeEntity != "result" && this . allCounts . hasOwnProperty ( "results" ) && this . allCounts [ 'results' ] > 0 ) {
this . numReturned ( this . fetchPublications , this . allCounts [ 'results' ] ) ;
}
if ( this . allCounts . hasOwnProperty ( this . activeEntity != "datasources" && "datasources" ) && this . allCounts [ 'datasources' ] > 0 ) {
this . numReturned ( this . fetchDataproviders , this . allCounts [ 'datasources' ] ) ;
}
if ( this . allCounts . hasOwnProperty ( this . activeEntity != "organizations" && "organizations" ) && this . allCounts [ 'organizations' ] > 0 ) {
this . numReturned ( this . fetchOrganizations , this . allCounts [ 'organizations' ] ) ;
}
if ( this . allCounts . hasOwnProperty ( this . activeEntity != "projects" && "projects" ) && this . allCounts [ 'projects' ] > 0 ) {
this . numReturned ( this . fetchProjects , this . allCounts [ 'projects' ] ) ;
}
}
private numReturned ( fetchClass , num ) {
fetchClass . searchUtils . totalResults = num ;
fetchClass . searchUtils . status = this . errorCodes . DONE ;
if ( fetchClass . searchUtils . totalResults == 0 ) {
fetchClass . searchUtils . status = this . errorCodes . NONE ;
}
}
private numErrorReturned ( fetchClass ) {
fetchClass . searchUtils . status = this . errorCodes . ERROR ;
fetchClass . searchUtils . totalResults = null ;
}
private reloadTabs() {
this . reload = { result :true , projects :true , datasources : true , services : true , organizations :true } ;
this . reload = { result :true , projects :true , datasources : true , services : true , organizations :true , all : ! this . allCounts };
this . fetchOrganizations . searchUtils . status = this . errorCodes . LOADING ;
this . fetchDataproviders . searchUtils . status = this . errorCodes . LOADING ;
this . fetchServices . searchUtils . status = this . errorCodes . LOADING ;