2021-04-18 14:03:23 +02:00
import { Component , ViewChild } from '@angular/core' ;
2021-12-03 17:04:39 +01:00
import { Subscription , zip } from 'rxjs' ;
2019-05-23 15:38:44 +02:00
import { ActivatedRoute , Router } from '@angular/router' ;
import { Location } from '@angular/common' ;
2021-04-18 14:03:23 +02:00
import { Meta , Title } from '@angular/platform-browser' ;
2019-05-23 15:38:44 +02:00
import { ConfigurationService } from '../openaireLibrary/utils/configuration/configuration.service' ;
2021-04-18 14:03:23 +02:00
import { SearchDataprovidersService } from '../openaireLibrary/services/searchDataproviders.service' ;
import { SearchProjectsService } from '../openaireLibrary/services/searchProjects.service' ;
import { SearchOrganizationsService } from '../openaireLibrary/services/searchOrganizations.service' ;
import { RefineFieldResultsService } from '../openaireLibrary/services/refineFieldResults.service' ;
import { SearchFields } from '../openaireLibrary/utils/properties/searchFields' ;
import { RouterHelper } from '../openaireLibrary/utils/routerHelper.class' ;
import { EnvProperties } from '../openaireLibrary/utils/properties/env-properties' ;
import { ErrorCodes } from '../openaireLibrary/utils/properties/errorCodes' ;
2019-05-23 15:38:44 +02:00
import { PiwikService } from '../openaireLibrary/utils/piwik/piwik.service' ;
2021-04-18 14:03:23 +02:00
import { SEOService } from '../openaireLibrary/sharedComponents/SEO/SEO.service' ;
2019-09-24 14:42:17 +02:00
import { SearchResearchResultsService } from "../openaireLibrary/services/searchResearchResults.service" ;
2020-11-18 18:01:52 +01:00
import { HelperService } from "../openaireLibrary/utils/helper/helper.service" ;
import { Filter } from "../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class" ;
2020-12-15 13:48:37 +01:00
import { AggregatorInfo , PortalAggregators } from "../utils/aggregators" ;
2020-11-18 18:01:52 +01:00
import { SearchCustomFilter } from "../openaireLibrary/searchPages/searchUtils/searchUtils.class" ;
import { properties } from "../../environments/environment" ;
import { portalProperties } from "../../environments/environment-aggregator" ;
import { StringUtils } from "../openaireLibrary/utils/string-utils.class" ;
2021-01-28 10:45:22 +01:00
import { ConnectHelper } from "../openaireLibrary/connect/connectHelper" ;
2021-04-18 14:03:23 +02:00
import { NumbersComponent } from "../openaireLibrary/sharedComponents/numbers/numbers.component" ;
2019-05-23 15:38:44 +02:00
@Component ( {
2019-05-24 15:54:22 +02:00
selector : 'home' ,
templateUrl : 'home.component.html' ,
2019-05-23 15:38:44 +02:00
} )
export class HomeComponent {
2020-11-18 18:01:52 +01:00
public keyword :string = "" ;
2019-05-23 15:38:44 +02:00
2020-11-18 18:01:52 +01:00
public searchFields :SearchFields = new SearchFields ( ) ;
public errorCodes :ErrorCodes = new ErrorCodes ( ) ;
public routerHelper :RouterHelper = new RouterHelper ( ) ;
showPublications : boolean = portalProperties . entities . publication . isEnabled ;
showDatasets : boolean = portalProperties . entities . dataset . isEnabled ;
showSoftware : boolean = portalProperties . entities . software . isEnabled ;
showOrp : boolean = portalProperties . entities . other . isEnabled ;
showOrganizations : boolean = portalProperties . entities . organization . isEnabled ;
showProjects : boolean = portalProperties . entities . project . isEnabled ;
showDataProviders : boolean = portalProperties . entities . datasource . isEnabled ;
2021-04-18 14:03:23 +02:00
properties : EnvProperties = properties ;
2020-11-18 18:01:52 +01:00
public readMore : boolean = false ;
2019-05-23 15:38:44 +02:00
2021-12-03 17:04:39 +01:00
private noOfFunders = 3 ;
public funders = [ ] ;
2020-11-18 18:01:52 +01:00
subs : Subscription [ ] = [ ] ;
resultsQuickFilter : { filter : Filter , selected : boolean , filterId : string , value : string } = {
filter : null ,
selected : true ,
filterId : "resultbestaccessright" ,
value : "Open Access"
} ;
selectedEntity = "all" ;
selectedEntitySimpleUrl ;
selectedEntityAdvancedUrl ;
resultTypes :Filter = { values : [ ] , filterId : "type" , countSelectedValues : 0 , filterType : 'checkbox' , originalFilterId : "" , valueIsExact : true , title : "Result Types" , filterOperator : "or" } ;
public pageContents = null ;
customFilter :SearchCustomFilter = null ;
aggregatorId ;
2020-12-15 13:48:37 +01:00
aggregator :AggregatorInfo ;
2021-07-14 13:47:56 +02:00
@ViewChild ( 'numbersComponent' , { static : true } ) numbersComponent : NumbersComponent ;
2021-04-18 14:03:23 +02:00
2020-11-18 18:01:52 +01:00
constructor (
2019-05-23 15:38:44 +02:00
private route : ActivatedRoute ,
2019-05-24 15:54:22 +02:00
private _router : Router ,
2019-09-24 14:42:17 +02:00
private _searchResearchResultsService : SearchResearchResultsService ,
2019-05-24 15:54:22 +02:00
private _searchDataprovidersService : SearchDataprovidersService ,
private _searchProjectsService : SearchProjectsService ,
private _searchOrganizationsService : SearchOrganizationsService ,
2020-11-18 18:01:52 +01:00
private _refineFieldResultsService :RefineFieldResultsService ,
private location : Location , private _piwikService :PiwikService ,
private config : ConfigurationService , private _meta : Meta , private _title : Title , private seoService : SEOService ,
private helper : HelperService
2019-05-24 15:54:22 +02:00
) {
2021-01-28 10:45:22 +01:00
this . aggregatorId = ConnectHelper . getCommunityFromDomain ( properties . domain ) ;
2020-11-18 18:01:52 +01:00
this . aggregator = PortalAggregators . getFilterInfoByMenuId ( this . aggregatorId ) ;
this . customFilter = PortalAggregators . getSearchCustomFilterByAggregator ( this . aggregator ) ;
let description = "OpenAIRE Explore: Over 100M of research deduplicated, 170K research software, 11M research data. One of the largest open scholarly records collection worldwide." ;
let title = "OpenAIRE - Explore| " + this . aggregator . title ;
2019-05-23 15:38:44 +02:00
2019-05-24 15:54:22 +02:00
this . _title . setTitle ( title ) ;
2020-11-18 18:01:52 +01:00
this . _meta . updateTag ( { content :description } , "name='description'" ) ;
this . _meta . updateTag ( { content :description } , "property='og:description'" ) ;
this . _meta . updateTag ( { content :title } , "property='og:title'" ) ;
}
private getPageContents() {
this . subs . push ( this . helper . getPageHelpContents ( this . properties , 'openaire' , this . _router . url ) . subscribe ( contents = > {
this . pageContents = contents ;
} ) ) ;
}
2019-06-13 14:40:03 +02:00
2020-11-18 18:01:52 +01:00
public ceil ( num : number ) {
return Math . ceil ( num ) ;
2019-05-23 15:38:44 +02:00
}
public ngOnInit() {
2020-11-18 18:01:52 +01:00
this . seoService . createLinkForCanonicalURL ( this . properties . domain + this . properties . baseLink + this . _router . url , false ) ;
this . getPageContents ( ) ;
if ( this . properties != null ) {
var url = this . properties . domain + this . properties . baseLink + this . _router . url ;
this . _meta . updateTag ( { content :url } , "property='og:url'" ) ;
if ( this . properties . enablePiwikTrack && ( typeof document !== 'undefined' ) ) {
this . subs . push ( this . _piwikService . trackView ( this . properties , "OpenAIRE" ) . subscribe ( ) ) ;
}
2019-05-23 15:38:44 +02:00
2020-11-18 18:01:52 +01:00
//this.config.getCommunityInformation(this.properties, this.properties.adminToolsCommunity ).subscribe(data => {
2020-11-25 18:39:05 +01:00
this . subs . push ( this . config . communityInformationState . subscribe ( data = > {
2020-11-18 18:01:52 +01:00
if ( data ) {
var showEntity = { } ;
for ( var i = 0 ; i < data [ 'entities' ] . length ; i ++ ) {
2019-05-24 15:54:22 +02:00
2020-11-18 18:01:52 +01:00
showEntity [ "" + data [ 'entities' ] [ i ] [ "pid" ] + "" ] = data [ 'entities' ] [ i ] [ "isEnabled" ] ;
2019-05-24 15:54:22 +02:00
}
2021-04-18 14:03:23 +02:00
this . showPublications = ! ! showEntity [ "publication" ] ;
this . showDatasets = ! ! showEntity [ "dataset" ] ;
this . showSoftware = ! ! showEntity [ "software" ] ;
this . showOrp = ! ! showEntity [ "orp" ] ;
this . showProjects = ! ! showEntity [ "project" ] ;
this . showDataProviders = ! ! showEntity [ "datasource" ] ;
this . showOrganizations = ! ! showEntity [ "organization" ] ;
2020-11-18 18:01:52 +01:00
if ( this . showPublications ) {
this . resultTypes . values . push ( { name : "Publications" , id : "publications" , selected :true , number : 0 } ) ;
}
if ( this . showDatasets ) {
this . resultTypes . values . push ( { name : "Research data" , id : "datasets" , selected :true , number : 0 } ) ;
}
if ( this . showSoftware ) {
this . resultTypes . values . push ( { name : "Software" , id : "software" , selected :true , number : 0 } ) ;
}
if ( this . showOrp ) {
this . resultTypes . values . push ( { name : "Other research products" , id : "other" , selected :true , number : 0 } ) ;
}
2021-04-18 14:03:23 +02:00
this . numbersComponent . init ( false , false , this . showPublications , this . showDatasets ,
2022-02-18 15:58:47 +01:00
this . showSoftware , this . showOrp , this . showProjects , this . showDataProviders , this . customFilter ?
StringUtils . URIEncode ( this . customFilter . queryFieldName + " exact " + StringUtils . quote ( ( this . customFilter . valueId ) ) ) : '' ) ;
2021-12-06 15:36:24 +01:00
this . getFunders ( ) ;
2020-11-25 18:39:05 +01:00
}
2020-11-18 18:01:52 +01:00
} ,
error = > {
this . handleError ( "Error getting community information" , error ) ;
}
2020-11-25 18:39:05 +01:00
) ) ;
2020-11-18 18:01:52 +01:00
}
2019-05-23 15:38:44 +02:00
}
public ngOnDestroy() {
2020-11-18 18:01:52 +01:00
for ( let sub of this . subs ) {
sub . unsubscribe ( ) ;
2019-05-24 15:54:22 +02:00
}
}
private handleError ( message : string , error ) {
2020-11-18 18:01:52 +01:00
console . error ( "Home Page: " + message , error ) ;
}
entityChanged ( $event ) {
this . selectedEntity = $event . entity ;
this . selectedEntitySimpleUrl = $event . simpleUrl ;
this . selectedEntityAdvancedUrl = $event . advancedUrl ;
}
goTo ( simple :boolean ) {
let url = ( simple ) ? this . selectedEntitySimpleUrl :this.selectedEntityAdvancedUrl ;
let parameterNames = [ ] ;
let parameterValues = [ ] ;
if ( this . selectedEntity == "result" ) {
if ( this . resultTypes ) {
let values = [ ] ;
for ( let value of this . resultTypes . values ) {
if ( value . selected ) {
values . push ( value . id ) ;
}
}
if ( values . length > 0 && values . length != 4 ) {
parameterNames . push ( "type" ) ;
parameterValues . push ( values . join ( "," ) ) ;
}
if ( this . resultsQuickFilter ) {
parameterNames . push ( "qf" ) ;
parameterValues . push ( "" + this . resultsQuickFilter . selected ) ;
}
}
2020-12-15 13:48:37 +01:00
} else if ( this . selectedEntity == "all" ) {
if ( this . resultsQuickFilter ) {
parameterNames . push ( "qf" ) ;
parameterValues . push ( "true" ) ;
}
2020-11-18 18:01:52 +01:00
}
if ( this . keyword . length > 0 ) {
parameterNames . push ( "fv0" ) ;
parameterValues . push ( this . keyword ) ;
parameterNames . push ( "f0" ) ;
parameterValues . push ( "q" ) ;
}
2020-11-23 17:09:45 +01:00
if ( this . customFilter ) {
parameterNames . push ( this . customFilter . queryFieldName ) ;
parameterValues . push ( this . customFilter . valueId ) ;
parameterNames . push ( "cf" ) ;
parameterValues . push ( "true" ) ;
}
2020-11-18 18:01:52 +01:00
this . _router . navigate ( [ url ] , { queryParams : this.routerHelper.createQueryParams ( parameterNames , parameterValues ) } ) ;
2019-05-24 15:54:22 +02:00
}
2020-11-23 17:09:45 +01:00
getQueryParamsForAdvancedSearch ( entity ) {
let params = { } ;
if ( entity == "result" ) {
if ( this . resultsQuickFilter ) {
params [ "qf" ] = "" + this . resultsQuickFilter . selected ;
}
}
if ( this . keyword . length > 0 ) {
params [ "fv0" ] = "" + this . keyword ;
params [ "f0" ] = "q" ;
}
if ( this . customFilter ) {
params = this . customFilter . getParameters ( params ) ;
}
return params ;
}
2021-12-03 17:04:39 +01:00
2021-12-06 15:36:24 +01:00
getFunders() {
2021-12-03 17:04:39 +01:00
let refineParams1 = '&fq=country%20exact%20%22CA%22' ;
let refineParams2 = '&fq=resultbestaccessright%20exact%20%22Open%20Access%22&fq=country%20exact%20%22CA%22%20' ;
this . subs . push ( zip (
this . _refineFieldResultsService . getRefineFieldsResultsByEntityName ( [ 'relfunder' ] , 'result' , this . properties , refineParams1 ) ,
this . _refineFieldResultsService . getRefineFieldsResultsByEntityName ( [ 'relfunder' ] , 'result' , this . properties , refineParams2 )
) . subscribe ( ( data : any [ ] ) = > {
2021-12-06 15:36:24 +01:00
let queriedFunders1 = data [ 0 ] [ 1 ] [ 0 ] . values ;
queriedFunders1 . forEach ( queriedFunder = > {
if ( queriedFunder . id . includes ( 'nserc' ) ) {
this . funders . push ( {
"id" : queriedFunder . id ,
"name" : queriedFunder . name ,
"publications" : queriedFunder . number ,
"openAccessPublications" : null ,
"logo" : 'assets/nserc_logo.png' ,
"params" : {
relfunder : '"' + encodeURIComponent ( queriedFunder . id ) + '"'
}
} ) ;
} else if ( queriedFunder . id . includes ( 'cihr' ) ) {
this . funders . push ( {
"id" : queriedFunder . id ,
"name" : queriedFunder . name ,
"publications" : queriedFunder . number ,
"openAccessPublications" : null ,
"logo" : 'assets/cihr_logo.png' ,
"params" : {
relfunder : '"' + encodeURIComponent ( queriedFunder . id ) + '"'
}
} ) ;
} else if ( queriedFunder . id . includes ( 'sshrc' ) ) {
this . funders . push ( {
"id" : queriedFunder . id ,
"name" : queriedFunder . name ,
"publications" : queriedFunder . number ,
"openAccessPublications" : null ,
"logo" : 'assets/sshrc_logo.png' ,
"params" : {
relfunder : '"' + encodeURIComponent ( queriedFunder . id ) + '"'
}
} ) ;
}
} ) ;
let queriedFunders2 = data [ 1 ] [ 1 ] [ 0 ] . values ;
queriedFunders2 . forEach ( queriedFunder = > {
for ( let funder of this . funders ) {
if ( queriedFunder . id == funder . id ) {
funder . openAccessPublications = queriedFunder . number ;
2021-12-03 17:04:39 +01:00
}
}
} ) ;
2021-12-06 15:36:24 +01:00
// console.log(this.funders);
} ) ) ;
2021-12-03 17:04:39 +01:00
}
2022-02-18 15:58:47 +01:00
isRouteAvailable ( routeToCheck : string ) {
for ( let i = 0 ; i < this . _router . config . length ; i ++ ) {
let routePath : string = this . _router . config [ i ] . path ;
if ( routePath == routeToCheck ) {
return true ;
}
}
return false ;
}
2019-05-23 15:38:44 +02:00
}