2021-04-15 20:52:58 +02:00
import { Component , OnDestroy , OnInit } from '@angular/core' ;
2020-10-05 18:36:30 +02:00
import { Subscription } from 'rxjs' ;
import { ActivatedRoute , Router } from '@angular/router' ;
import { Location } from '@angular/common' ;
2021-04-15 20:27:06 +02:00
import { Meta , Title } 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 { EnvProperties } from '../openaireLibrary/utils/properties/env-properties' ;
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' ;
2021-04-15 20:27:06 +02:00
import { properties } from '../../environments/environment' ;
import { portals } from './portals' ;
import { Filter } from '../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class' ;
import { RouterHelper } from '../openaireLibrary/utils/routerHelper.class' ;
2020-10-05 18:36:30 +02:00
@Component ( {
selector : 'home' ,
templateUrl : 'home.component.html' ,
styleUrls : [ 'home.component.css' ]
} )
2021-04-15 20:52:58 +02:00
export class HomeComponent implements OnInit , OnDestroy {
2021-04-15 20:27:06 +02:00
public pageTitle = 'OpenAIRE - Research Graph' ;
2020-10-08 17:52:05 +02:00
public portals : any [ ] = portals ;
public state : number = 0 ;
2021-04-13 00:21:12 +02:00
public properties : EnvProperties = properties ;
2021-04-15 20:27:06 +02:00
public selectedEntity = 'all' ;
public url : string ;
public routerHelper : RouterHelper = new RouterHelper ( ) ;
public resultTypes : Filter = {
values : [
{ name : 'Publications' , id : 'publications' , selected : true , number : 0 } ,
{ name : "Research data" , id : "datasets" , selected : true , number : 0 } ,
{ name : "Software" , id : "software" , selected : true , number : 0 } ,
{ name : "Other research products" , id : "other" , selected : true , number : 0 }
] ,
filterId : 'type' ,
countSelectedValues : 0 ,
filterType : 'checkbox' ,
originalFilterId : '' ,
valueIsExact : true ,
title : 'Result Types' ,
filterOperator : 'or'
} ;
public resultsQuickFilter : { filter : Filter , selected : boolean , filterId : string , value : string } = {
filter : null ,
selected : true ,
filterId : 'resultbestaccessright' ,
value : 'Open Access'
} ;
public keyword : string = '' ;
2020-10-08 17:52:05 +02:00
private timeouts : any [ ] = [ ] ;
2021-04-13 00:21:12 +02:00
private 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 ,
2020-10-08 17:52:05 +02:00
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
2021-04-15 20:27:06 +02: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 ) ;
2021-04-16 11:01:42 +02:00
this . _meta . updateTag ( { content : description } , 'name="description"' ) ;
this . _meta . updateTag ( { content : description } , 'property="og:description"' ) ;
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 ) ;
2021-04-15 20:27:06 +02:00
this . _meta . updateTag ( { content : url } , 'property=\'og:url\'' ) ;
2020-10-08 17:52:05 +02:00
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 . 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() {
2021-04-15 20:52:58 +02:00
this . subs . forEach ( sub = > {
if ( sub instanceof Subscription ) {
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 ( ) ;
2021-04-15 20:27:06 +02:00
if ( this . state === ( this . portals . length - 1 ) ) {
this . state = 0 ;
2020-10-08 17:52:05 +02:00
} else {
this . state ++ ;
}
} , 4000 ) ) ;
}
2021-04-15 20:27:06 +02:00
entityChanged ( $event ) {
this . selectedEntity = $event . entity ;
this . url = $event . simpleUrl ;
}
2020-10-08 17:52:05 +02:00
private changeSlide ( slide : number ) {
this . clearTimeouts ( ) ;
this . state = slide ;
this . animation ( ) ;
}
private clearTimeouts() {
this . timeouts . forEach ( timeout = > {
clearTimeout ( timeout ) ;
} ) ;
this . state = 0 ;
}
2021-04-15 20:27:06 +02:00
goTo() {
let url = 'https://explore.openaire.eu' + this . url ;
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 ( ',' ) ) ;
}
2021-07-14 17:18:07 +02:00
if ( this . resultsQuickFilter && this . resultsQuickFilter . selected ) {
parameterNames . push ( this . resultsQuickFilter . filterId ) ;
parameterValues . push ( '"' + encodeURIComponent ( this . resultsQuickFilter . value ) + '"' ) ;
2021-04-15 20:27:06 +02:00
}
}
} else if ( this . selectedEntity == 'all' ) {
2021-07-14 17:18:07 +02:00
if ( this . resultsQuickFilter && this . resultsQuickFilter . selected ) {
parameterNames . push ( this . resultsQuickFilter . filterId ) ;
parameterValues . push ( '"' + encodeURIComponent ( this . resultsQuickFilter . value ) + '"' ) ;
2021-04-15 20:27:06 +02:00
}
}
if ( this . keyword . length > 0 ) {
parameterNames . push ( 'fv0' ) ;
parameterValues . push ( this . keyword ) ;
parameterNames . push ( 'f0' ) ;
parameterValues . push ( 'q' ) ;
}
window . open ( url + this . routerHelper . createQueryParamsString ( parameterNames , parameterValues ) , '_blank' ) . focus ( ) ;
}
2020-10-05 18:36:30 +02:00
}