2020-10-20 11:17:15 +02:00
import { Component , Input } from '@angular/core' ;
2020-08-19 12:59:28 +02:00
import { Subscription } from 'rxjs' ;
2018-01-23 11:07:39 +01:00
import { ActivatedRoute , Router } from '@angular/router' ;
import { Location } from '@angular/common' ;
import "rxjs/add/observable/zip" ;
2018-04-17 15:51:47 +02:00
import { Title , Meta } from '@angular/platform-browser' ;
2018-02-16 16:51:10 +01:00
import { ConfigurationService } from '../openaireLibrary/utils/configuration/configuration.service' ;
2018-05-10 16:08:45 +02:00
import { FetchDataproviders } from '../openaireLibrary/utils/fetchEntitiesClasses/fetchDataproviders.class' ;
2018-02-16 16:51:10 +01: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 { NumberUtils } from '../openaireLibrary/utils/number-utils.class' ;
2018-01-23 11:07:39 +01:00
2018-02-16 16:51:10 +01:00
import { RouterHelper } from '../openaireLibrary/utils/routerHelper.class' ;
import { EnvProperties } from '../openaireLibrary/utils/properties/env-properties' ;
import { ErrorCodes } from '../openaireLibrary/utils/properties/errorCodes' ;
import { PiwikService } from '../openaireLibrary/utils/piwik/piwik.service' ;
2018-11-14 15:16:19 +01:00
import { SEOService } from '../openaireLibrary/sharedComponents/SEO/SEO.service' ;
2019-09-11 13:47:16 +02:00
import { SearchResearchResultsService } from "../openaireLibrary/services/searchResearchResults.service" ;
2019-11-02 02:37:11 +01:00
import { HelperService } from "../openaireLibrary/utils/helper/helper.service" ;
2020-02-13 15:45:55 +01:00
import { Filter } from "../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class" ;
2018-01-23 11:07:39 +01:00
@Component ( {
selector : 'home' ,
templateUrl : 'home.component.html' ,
} )
export class HomeComponent {
2019-10-08 13:02:51 +02:00
// MAX 12 logos in every slide
public logos = {
"publication" : [
[
2019-10-10 18:19:47 +02:00
"logo-pubmed.png" ,
"logo-arxiv.png" ,
"logo-base.png" ,
"logo-scielo.png" ,
"logo-la-referencia.png" ,
"logo-soar.png" ,
"logo-repec.png" ,
"logo-core.png" ,
"logo-zenodo.png" ,
"logo-narcis.png"
2019-10-08 13:02:51 +02:00
] ,
[
2019-10-10 18:19:47 +02:00
"logo-crossref.png" ,
"logo-unpaywall.png" ,
"logo-elsevier.png" ,
"logo-spring-nature.png" ,
"logo-frontiers.png" ,
"logo-opencitations.png" ,
"logo-doaj.png" ,
"logo-microsoft.png" ,
"logo-plos.png" ,
"logo-f1000.png" ,
"logo-copernicus.png"
2019-10-08 13:02:51 +02:00
]
] ,
"software" : [
[
2019-10-10 18:19:47 +02:00
"logo-software-heritage.png" ,
"logo-github.png" ,
"logo-doecode.png" ,
"logo-bitbucket.png" ,
2019-10-14 13:31:24 +02:00
"logo-elixir-bio-tools.png" ,
2019-10-10 18:19:47 +02:00
"logo-google-code.png" ,
"logo-sourceforge.png" ,
"logo-zenodo.png"
2019-10-08 13:02:51 +02:00
]
] ,
"dataset" : [
[
2019-10-10 18:19:47 +02:00
"logo-scholexplorer.png" ,
"logo-zenodo.png" ,
"logo-datacite.png" ,
"logo-pangea.png" ,
"logo-figshare.png" ,
"logo-protocols.png" ,
"logo-opentrials.png" ,
"logo-kaggle.png" ,
"logo-reactome.png" ,
"logo-easy.png" ,
"logo-dryad.png"
2019-10-08 13:02:51 +02:00
]
] ,
//"other": [],
"persistent" : [
[
2019-10-10 18:19:47 +02:00
"logo-re3data.png" ,
"logo-orcid.png" ,
"logo-opendoar.png" ,
"logo-grid.png"
2019-10-08 13:02:51 +02:00
]
] ,
"funder" : [
[
2019-10-10 18:19:47 +02:00
"logo-european-commision.png" ,
"logo-nsf.png" ,
2019-10-08 13:02:51 +02:00
"logo-miur.png" ,
2019-10-10 18:19:47 +02:00
"logo-nhmrc.png" ,
"logo-sfi.png" ,
"logo-nwo.png" ,
"logo-welcome-trust.png" ,
"logo-fct.png" ,
"logo-gsrt.png" ,
"logo-fnsnf.png"
2019-10-08 13:02:51 +02:00
]
]
} ;
public pageTitle = "OpenAIRE" ;
2018-01-23 11:07:39 +01:00
public keyword :string = "" ;
public searchFields :SearchFields = new SearchFields ( ) ;
public errorCodes :ErrorCodes = new ErrorCodes ( ) ;
public routerHelper :RouterHelper = new RouterHelper ( ) ;
public publicationsSize :any = null ;
public datasetsSize :any = null ;
2019-11-08 14:46:14 +01:00
public datasetsLinkedSize :any = null ;
public softwareLinkedSize :any = null ;
2019-06-13 16:54:39 +02:00
public softwareSize : any = null ;
public otherSize : any = null ;
2018-01-23 11:07:39 +01:00
public fundersSize :any = null ;
public projectsSize :any = null ;
public datasourcesSize :any = null ;
2018-05-10 16:08:45 +02:00
private numResults : number = 2 ;
public fetchDataproviders : FetchDataproviders ;
2018-01-23 11:07:39 +01:00
showPublications :boolean = false ;
showDatasets :boolean = false ;
2019-06-13 16:54:39 +02:00
showSoftware : boolean = false ;
showOrp : boolean = false ;
2018-01-23 11:07:39 +01:00
showProjects :boolean = false ;
showDataProviders :boolean = false ;
2020-06-29 13:11:34 +02:00
showOrganizations :boolean = false ;
2018-02-05 14:16:11 +01:00
properties : EnvProperties ;
2019-10-07 15:00:45 +02:00
public readMore : boolean = false ;
2020-07-13 00:22:43 +02:00
subs : Subscription [ ] = [ ] ;
2020-02-13 15:45:55 +01:00
resultsQuickFilter : { filter : Filter , selected : boolean , filterId : string , value : string } = {
filter : null ,
selected : true ,
filterId : "resultbestaccessright" ,
value : "Open Access"
} ;
selectedEntity = "all" ;
selectedEntitySimpleUrl ;
selectedEntityAdvancedUrl ;
2020-10-20 11:17:15 +02:00
resultTypes :Filter = { values : [ ] , filterId : "type" , countSelectedValues : 0 , filterType : 'checkbox' , originalFilterId : "" , valueIsExact : true , title : "Result Types" , filterOperator : "or" } ;
2019-11-02 02:37:11 +01:00
public pageContents = null ;
2020-10-14 13:19:00 +02:00
useHelpText : boolean = true ;
2019-11-02 02:37:11 +01:00
2018-01-23 11:07:39 +01:00
constructor (
private route : ActivatedRoute ,
private _router : Router ,
2019-09-11 13:47:16 +02:00
private _searchResearchResultsService : SearchResearchResultsService ,
2018-01-23 11:07:39 +01:00
private _searchDataprovidersService : SearchDataprovidersService ,
private _searchProjectsService : SearchProjectsService ,
private _searchOrganizationsService : SearchOrganizationsService ,
private _refineFieldResultsService :RefineFieldResultsService ,
2018-04-17 15:51:47 +02:00
private location : Location , private _piwikService :PiwikService ,
2019-11-02 02:37:11 +01:00
private config : ConfigurationService , private _meta : Meta , private _title : Title , private seoService : SEOService ,
2020-02-13 15:45:55 +01:00
private helper : HelperService , private router : Router
2018-01-23 11:07:39 +01:00
) {
2020-08-19 12:59:28 +02:00
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 | Find and Share research" ;
2018-01-23 11:07:39 +01:00
2018-04-17 15:51:47 +02:00
this . _title . setTitle ( title ) ;
this . _meta . updateTag ( { content :description } , "name='description'" ) ;
this . _meta . updateTag ( { content :description } , "property='og:description'" ) ;
this . _meta . updateTag ( { content :title } , "property='og:title'" ) ;
2018-11-14 15:16:19 +01:00
2018-01-23 11:07:39 +01:00
2018-05-10 16:08:45 +02:00
//this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
2018-01-23 11:07:39 +01:00
}
2019-11-02 02:37:11 +01:00
private getPageContents() {
2020-07-13 00:22:43 +02:00
this . subs . push ( this . helper . getPageHelpContents ( this . properties , 'openaire' , this . _router . url ) . subscribe ( contents = > {
2019-11-02 02:37:11 +01:00
this . pageContents = contents ;
2020-07-13 00:22:43 +02:00
} ) ) ;
2019-11-02 02:37:11 +01:00
}
2019-10-08 13:02:51 +02:00
public getKeys ( obj : { } ) {
return Object . keys ( obj ) ;
}
createRange ( number ) {
var items : number [ ] = [ ] ;
for ( var i = 1 ; i <= number ; i ++ ) {
items . push ( i ) ;
}
return items ;
}
public ceil ( num : number ) {
return Math . ceil ( num ) ;
}
2018-01-23 11:07:39 +01:00
public ngOnInit() {
2020-07-13 00:22:43 +02:00
this . subs . push ( this . route . data
2018-02-05 14:16:11 +01:00
. subscribe ( ( data : { envSpecific : EnvProperties } ) = > {
this . properties = data . envSpecific ;
2020-09-18 16:02:48 +02:00
this . seoService . createLinkForCanonicalURL ( this . properties . domain + this . properties . baseLink + this . _router . url , false ) ;
2019-11-02 02:37:11 +01:00
this . getPageContents ( ) ;
if ( this . properties != null ) {
2020-09-18 16:02:48 +02:00
var url = this . properties . domain + this . properties . baseLink + this . _router . url ;
2018-04-17 15:51:47 +02:00
this . _meta . updateTag ( { content :url } , "property='og:url'" ) ;
2018-02-05 14:16:11 +01:00
if ( this . properties . enablePiwikTrack && ( typeof document !== 'undefined' ) ) {
2020-07-13 00:22:43 +02:00
this . subs . push ( this . _piwikService . trackView ( this . properties , "OpenAIRE" ) . subscribe ( ) ) ;
2018-02-05 14:16:11 +01:00
}
2020-07-13 00:22:43 +02:00
//this.config.getCommunityInformation(this.properties, this.properties.adminToolsCommunity ).subscribe(data => {
this . subs . push ( this . config . communityInformationState . subscribe ( data = > {
if ( data ) {
var showEntity = { } ;
for ( var i = 0 ; i < data [ 'entities' ] . length ; i ++ ) {
2018-02-05 14:16:11 +01:00
2020-07-13 00:22:43 +02:00
showEntity [ "" + data [ 'entities' ] [ i ] [ "pid" ] + "" ] = data [ 'entities' ] [ i ] [ "isEnabled" ] ;
}
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-10-20 11:17:15 +02: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 } ) ;
}
2020-07-13 00:22:43 +02:00
this . getNumbers ( ) ;
// if(this.showDataProviders) {
// this.fetchDataproviders.getResultsForHome(this.numResults, this.properties);
// }
}
} ,
error = > {
this . handleError ( "Error getting community information" , error ) ;
}
) ) ;
}
} ) ) ;
2018-01-23 11:07:39 +01:00
}
public ngOnDestroy() {
2020-07-13 00:22:43 +02:00
for ( let sub of this . subs ) {
sub . unsubscribe ( ) ;
2018-01-23 11:07:39 +01:00
}
}
private getNumbers() {
if ( this . showPublications ) {
2020-07-13 00:22:43 +02:00
this . subs . push ( this . _searchResearchResultsService . numOfSearchResults ( "publication" , "" , this . properties ) . subscribe (
2018-01-23 11:07:39 +01:00
data = > {
if ( data && data != null && data > 0 ) {
this . publicationsSize = NumberUtils . roundNumber ( data ) ;
}
} ,
err = > {
2019-02-18 15:36:04 +01:00
//console.log(err);
this . handleError ( "Error getting number of publications" , err ) ;
2018-01-23 11:07:39 +01:00
}
2020-07-13 00:22:43 +02:00
) ) ;
2018-01-23 11:07:39 +01:00
}
if ( this . showDatasets ) {
2020-07-13 00:22:43 +02:00
this . subs . push ( this . _searchResearchResultsService . numOfSearchResults ( "dataset" , "" , this . properties ) . subscribe (
2018-01-23 11:07:39 +01:00
data = > {
if ( data && data != null && data > 0 ) {
this . datasetsSize = NumberUtils . roundNumber ( data ) ;
}
} ,
err = > {
2019-02-18 15:36:04 +01:00
//console.log(err);
this . handleError ( "Error getting number of research data" , err ) ;
2018-01-23 11:07:39 +01:00
}
2020-07-13 00:22:43 +02:00
) ) ;
this . subs . push ( this . _searchResearchResultsService . numOfSearchResultsLinkedToPub ( "dataset" , this . properties ) . subscribe (
2019-11-08 14:46:14 +01:00
data = > {
if ( data && data != null && data > 0 ) {
this . datasetsLinkedSize = NumberUtils . roundNumber ( data ) ;
}
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting number of linkedresearch data" , err ) ;
}
2020-07-13 00:22:43 +02:00
) ) ;
2019-11-08 14:46:14 +01:00
2018-01-23 11:07:39 +01:00
}
2019-06-13 16:54:39 +02:00
if ( this . showSoftware ) {
2020-07-13 00:22:43 +02:00
this . subs . push ( this . _searchResearchResultsService . numOfSearchResults ( "software" , "" , this . properties ) . subscribe (
2019-06-13 16:54:39 +02:00
data = > {
if ( data && data > 0 ) {
this . softwareSize = NumberUtils . roundNumber ( data ) ;
} else {
this . showSoftware = false ;
}
} ,
err = > {
this . handleError ( "Error getting number of software data" , err ) ;
}
2020-07-13 00:22:43 +02:00
) ) ;
this . subs . push ( this . _searchResearchResultsService . numOfSearchResultsLinkedToPub ( "software" , this . properties ) . subscribe (
2019-11-08 14:46:14 +01:00
data = > {
if ( data && data != null && data > 0 ) {
this . softwareLinkedSize = NumberUtils . roundNumber ( data ) ;
}
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting number of linked software" , err ) ;
}
2020-07-13 00:22:43 +02:00
) ) ;
2019-06-13 16:54:39 +02:00
}
if ( this . showOrp ) {
2020-07-13 00:22:43 +02:00
this . subs . push ( this . _searchResearchResultsService . numOfSearchResults ( "other" , "" , this . properties ) . subscribe (
2019-06-13 16:54:39 +02:00
data = > {
if ( data && data > 0 ) {
this . otherSize = NumberUtils . roundNumber ( data ) ;
} else {
this . showOrp = false ;
}
} ,
err = > {
this . handleError ( "Error getting number of software data" , err ) ;
}
2020-07-13 00:22:43 +02:00
) ) ;
2019-06-13 16:54:39 +02:00
}
2018-01-23 11:07:39 +01:00
if ( this . showProjects ) {
2020-07-13 00:22:43 +02:00
this . subs . push ( this . _refineFieldResultsService . getRefineFieldsResultsByEntityName ( [ "funder" ] , "project" , this . properties ) . subscribe (
2018-01-23 11:07:39 +01:00
data = > {
if ( data [ 0 ] && data [ 0 ] > 0 ) {
this . projectsSize = NumberUtils . roundNumber ( data [ 0 ] ) ;
}
if ( data [ 1 ] . length > 0 && data [ 1 ] [ 0 ] . filterId == "funder" && data [ 1 ] [ 0 ] . values ) {
this . fundersSize = NumberUtils . roundNumber ( data [ 1 ] [ 0 ] . values . length ) ;
}
} ,
err = > {
2019-02-18 15:36:04 +01:00
//console.log(err);
this . handleError ( "Error getting 'funder' field results of projects" , err ) ;
2020-07-13 00:22:43 +02:00
} ) ) ;
2018-01-23 11:07:39 +01:00
}
if ( this . showDataProviders ) {
2020-07-13 00:22:43 +02:00
this . subs . push ( this . _searchDataprovidersService . numOfSearchDataproviders ( "" , this . properties ) . subscribe (
2018-01-23 11:07:39 +01:00
data = > {
if ( data && data != null && data > 0 ) {
this . datasourcesSize = NumberUtils . roundNumber ( data ) ;
}
} ,
err = > {
2019-02-18 15:36:04 +01:00
//console.log(err);
this . handleError ( "Error getting number of content providers" , err ) ;
2018-01-23 11:07:39 +01:00
}
2020-07-13 00:22:43 +02:00
) ) ;
2018-01-23 11:07:39 +01:00
}
}
2019-02-18 15:36:04 +01:00
private handleError ( message : string , error ) {
console . error ( "Home Page: " + message , error ) ;
}
2020-02-13 15:45:55 +01:00
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 = [ ] ;
2020-10-20 11:17:15 +02:00
console . log ( this . resultTypes . values )
for ( let value of this . resultTypes . values ) {
if ( value . selected ) {
values . push ( value . id ) ;
}
2020-02-13 15:45:55 +01:00
}
2020-06-01 11:20:11 +02:00
if ( values . length > 0 && values . length != 4 ) {
2020-02-13 15:45:55 +01:00
parameterNames . push ( "type" ) ;
parameterValues . push ( values . join ( "," ) ) ;
}
2020-10-20 11:17:15 +02:00
console . log ( parameterNames )
console . log ( parameterValues )
2020-02-13 15:45:55 +01:00
if ( this . resultsQuickFilter ) {
parameterNames . push ( "qf" ) ;
parameterValues . push ( "" + this . resultsQuickFilter . selected ) ;
}
}
}
if ( this . keyword . length > 0 ) {
parameterNames . push ( "q" ) ;
parameterValues . push ( this . keyword ) ;
parameterNames . push ( "op" ) ;
parameterValues . push ( "and" ) ;
}
2020-10-20 11:17:15 +02:00
console . log ( this . routerHelper . createQueryParams ( parameterNames , parameterValues ) )
2020-02-13 15:45:55 +01:00
this . _router . navigate ( [ url ] , { queryParams : this.routerHelper.createQueryParams ( parameterNames , parameterValues ) } ) ;
}
2018-01-23 11:07:39 +01:00
}