2020-10-05 18:36:30 +02:00
import { Component } from '@angular/core' ;
import { Subscription } from 'rxjs' ;
import { ActivatedRoute , Router } from '@angular/router' ;
import { Location } from '@angular/common' ;
import "rxjs/add/observable/zip" ;
2020-10-08 17:52:05 +02:00
import { Title , Meta } from '@angular/platform-browser' ;
2020-10-05 18:36:30 +02:00
import { ConfigurationService } from '../openaireLibrary/utils/configuration/configuration.service' ;
2020-10-08 17:52:05 +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 { NumberUtils } from '../openaireLibrary/utils/number-utils.class' ;
import { RouterHelper } from '../openaireLibrary/utils/routerHelper.class' ;
import { EnvProperties } from '../openaireLibrary/utils/properties/env-properties' ;
import { ErrorCodes } from '../openaireLibrary/utils/properties/errorCodes' ;
2020-10-05 18:36:30 +02:00
import { PiwikService } from '../openaireLibrary/utils/piwik/piwik.service' ;
2020-10-08 17:52:05 +02:00
import { SEOService } from '../openaireLibrary/sharedComponents/SEO/SEO.service' ;
2020-10-05 18:36:30 +02:00
import { SearchResearchResultsService } from "../openaireLibrary/services/searchResearchResults.service" ;
import { properties } from "../../environments/environment" ;
2020-10-08 17:52:05 +02:00
import { portals } from "./portals" ;
2020-10-05 18:36:30 +02:00
@Component ( {
selector : 'home' ,
templateUrl : 'home.component.html' ,
styleUrls : [ 'home.component.css' ]
} )
export class HomeComponent {
2020-10-09 10:04:25 +02:00
public pageTitle = "OpenAIRE - Research Graph" ;
2020-10-08 17:52:05 +02:00
public errorCodes : ErrorCodes = new ErrorCodes ( ) ;
public routerHelper : RouterHelper = new RouterHelper ( ) ;
public publicationsSize : any = null ;
public datasetsSize : any = null ;
public datasetsLinkedSize : any = null ;
public softwareLinkedSize : any = null ;
2020-10-05 18:36:30 +02:00
public softwareSize : any = null ;
public otherSize : any = null ;
2020-10-08 17:52:05 +02:00
public fundersSize : any = null ;
public projectsSize : any = null ;
public datasourcesSize : any = null ;
public portals : any [ ] = portals ;
public state : number = 0 ;
private timeouts : any [ ] = [ ] ;
2020-10-05 18:36:30 +02:00
properties : EnvProperties = properties ;
2020-10-08 17:52:05 +02:00
2020-10-05 18:36:30 +02:00
subs : Subscription [ ] = [ ] ;
2020-10-08 17:52:05 +02:00
constructor (
2020-10-05 18:36:30 +02:00
private route : ActivatedRoute ,
private _router : Router ,
private _searchResearchResultsService : SearchResearchResultsService ,
private _searchDataprovidersService : SearchDataprovidersService ,
private _searchProjectsService : SearchProjectsService ,
private _searchOrganizationsService : SearchOrganizationsService ,
2020-10-08 17:52:05 +02:00
private _refineFieldResultsService : RefineFieldResultsService ,
private location : Location , private _piwikService : PiwikService ,
2020-10-05 18:36:30 +02:00
private config : ConfigurationService , private _meta : Meta , private _title : Title , private seoService : SEOService
) {
2020-10-08 17:52:05 +02:00
2020-11-16 13:56:17 +01:00
let description = "OpenAIRE Research Graph is an open resource that aggregates a collection of research data properties (metadata, links) available within the OpenAIRE Open Science infrastructure for funders, organizations, researchers, research communities and publishers to interlink information by using a semantic graph database approach." ;
2020-10-08 17:52:05 +02:00
this . _title . setTitle ( this . pageTitle ) ;
2020-11-16 13:56:17 +01:00
this . _meta . updateTag ( { content : description } , "name='description'" ) ;
2020-10-08 17:52:05 +02:00
this . _meta . updateTag ( { content : description } , "property='og:description'" ) ;
2020-11-16 13:56:17 +01:00
this . _meta . updateTag ( { content : this.pageTitle } , "property='og:title'" ) ;
2020-10-05 18:36:30 +02:00
}
2020-10-08 17:52:05 +02:00
2020-10-05 18:36:30 +02:00
public ngOnInit() {
2020-10-08 17:52:05 +02:00
if ( this . properties ) {
2020-11-16 13:56:17 +01:00
let url = this . properties . domain + this . properties . baseLink + this . _router . url ;
this . seoService . createLinkForCanonicalURL ( url , false ) ;
2020-10-08 17:52:05 +02:00
this . _meta . updateTag ( { content : url } , "property='og:url'" ) ;
if ( this . properties . enablePiwikTrack && ( typeof document !== 'undefined' ) ) {
2020-11-16 13:56:17 +01:00
this . subs . push ( this . _piwikService . trackView ( this . properties , this . pageTitle ) . subscribe ( ) ) ;
}
2020-10-08 17:52:05 +02:00
this . getNumbers ( ) ;
this . animation ( ) ;
}
2020-10-05 18:36:30 +02:00
}
2020-10-08 17:52:05 +02:00
2020-10-05 18:36:30 +02:00
public ngOnDestroy() {
for ( let sub of this . subs ) {
sub . unsubscribe ( ) ;
}
2020-10-08 17:52:05 +02:00
this . clearTimeouts ( ) ;
2020-10-05 18:36:30 +02:00
}
2020-10-08 17:52:05 +02:00
private animation() {
this . timeouts . push ( setTimeout ( ( ) = > {
this . animation ( ) ;
if ( this . state === ( this . portals . length - 1 ) ) {
this . state = 0
} else {
this . state ++ ;
}
} , 4000 ) ) ;
}
private changeSlide ( slide : number ) {
this . clearTimeouts ( ) ;
this . state = slide ;
this . animation ( ) ;
}
private clearTimeouts() {
this . timeouts . forEach ( timeout = > {
clearTimeout ( timeout ) ;
} ) ;
this . state = 0 ;
}
2020-10-05 18:36:30 +02:00
private getNumbers() {
this . subs . push ( this . _searchResearchResultsService . numOfSearchResults ( "publication" , "" , this . properties ) . subscribe (
data = > {
2020-10-08 17:52:05 +02:00
if ( data && data > 0 ) {
2020-10-05 18:36:30 +02:00
this . publicationsSize = NumberUtils . roundNumber ( data ) ;
2020-10-08 17:52:05 +02:00
2020-10-05 18:36:30 +02:00
}
} ,
err = > {
this . handleError ( "Error getting number of publications" , err ) ;
}
) ) ;
this . subs . push ( this . _searchResearchResultsService . numOfSearchResults ( "dataset" , "" , this . properties ) . subscribe (
data = > {
2020-10-08 17:52:05 +02:00
if ( data && data > 0 ) {
2020-10-05 18:36:30 +02:00
this . datasetsSize = NumberUtils . roundNumber ( data ) ;
}
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting number of research data" , err ) ;
}
) ) ;
this . subs . push ( this . _searchResearchResultsService . numOfSearchResultsLinkedToPub ( "dataset" , this . properties ) . subscribe (
data = > {
2020-10-08 17:52:05 +02:00
if ( data && data > 0 ) {
2020-10-05 18:36:30 +02:00
this . datasetsLinkedSize = NumberUtils . roundNumber ( data ) ;
}
} ,
err = > {
this . handleError ( "Error getting number of linkedresearch data" , err ) ;
}
) ) ;
this . subs . push ( this . _searchResearchResultsService . numOfSearchResults ( "software" , "" , this . properties ) . subscribe (
data = > {
if ( data && data > 0 ) {
this . softwareSize = NumberUtils . roundNumber ( data ) ;
}
} ,
err = > {
this . handleError ( "Error getting number of software data" , err ) ;
}
) ) ;
this . subs . push ( this . _searchResearchResultsService . numOfSearchResultsLinkedToPub ( "software" , this . properties ) . subscribe (
data = > {
2020-10-08 17:52:05 +02:00
if ( data && data > 0 ) {
2020-10-05 18:36:30 +02:00
this . softwareLinkedSize = NumberUtils . roundNumber ( data ) ;
}
} ,
err = > {
this . handleError ( "Error getting number of linked software" , err ) ;
}
) ) ;
this . subs . push ( this . _searchResearchResultsService . numOfSearchResults ( "other" , "" , this . properties ) . subscribe (
data = > {
if ( data && data > 0 ) {
this . otherSize = NumberUtils . roundNumber ( data ) ;
}
} ,
err = > {
this . handleError ( "Error getting number of software data" , err ) ;
}
) ) ;
2020-10-08 17:52:05 +02:00
this . subs . push ( this . _refineFieldResultsService . getRefineFieldsResultsByEntityName ( [ "funder" ] , "project" , this . properties ) . subscribe (
2020-10-05 18:36:30 +02:00
data = > {
2020-10-08 17:52:05 +02:00
if ( data [ 0 ] && data [ 0 ] > 0 ) {
2020-10-05 18:36:30 +02:00
this . projectsSize = NumberUtils . roundNumber ( data [ 0 ] ) ;
}
2020-10-08 17:52:05 +02:00
if ( data [ 1 ] . length > 0 && data [ 1 ] [ 0 ] . filterId == "funder" && data [ 1 ] [ 0 ] . values ) {
2020-10-05 18:36:30 +02:00
this . fundersSize = NumberUtils . roundNumber ( data [ 1 ] [ 0 ] . values . length ) ;
}
2020-10-08 17:52:05 +02:00
2020-10-05 18:36:30 +02:00
} ,
err = > {
this . handleError ( "Error getting 'funder' field results of projects" , err ) ;
} )
) ;
2020-10-08 17:52:05 +02:00
2020-10-05 18:36:30 +02:00
this . subs . push ( this . _searchDataprovidersService . numOfSearchDataproviders ( "" , this . properties ) . subscribe (
data = > {
2020-10-08 17:52:05 +02:00
if ( data && data > 0 ) {
2020-10-05 18:36:30 +02:00
this . datasourcesSize = NumberUtils . roundNumber ( data ) ;
}
2020-10-08 17:52:05 +02:00
2020-10-05 18:36:30 +02:00
} ,
err = > {
this . handleError ( "Error getting number of content providers" , err ) ;
}
) ) ;
}
2020-10-08 17:52:05 +02:00
2020-10-05 18:36:30 +02:00
private handleError ( message : string , error ) {
2020-10-08 17:52:05 +02:00
console . error ( "Home Page: " + message , error ) ;
2020-10-05 18:36:30 +02:00
}
}