2019-09-30 14:51:38 +02:00
import { Component } from '@angular/core' ;
import { ActivatedRoute , Router } from '@angular/router' ;
import { Meta , Title } from '@angular/platform-browser' ;
import { EnvProperties } from '../openaireLibrary/utils/properties/env-properties' ;
2019-12-03 12:10:05 +01:00
2019-09-30 14:51:38 +02:00
import { CommunityInfo } from '../openaireLibrary/connect/community/communityInfo' ;
import { PiwikService } from '../openaireLibrary/utils/piwik/piwik.service' ;
import { StringUtils } from '../openaireLibrary/utils/string-utils.class' ;
import { ErrorCodes } from '../openaireLibrary/utils/properties/errorCodes' ;
import { ErrorMessagesComponent } from '../openaireLibrary/utils/errorMessages.component' ;
import { HelperService } from "../openaireLibrary/utils/helper/helper.service" ;
import { SEOService } from "../openaireLibrary/sharedComponents/SEO/SEO.service" ;
2019-12-03 12:10:05 +01:00
import { StakeholderService } from "../services/stakeholder.service" ;
import { RefineFieldResultsService } from "../openaireLibrary/services/refineFieldResults.service" ;
import { NumberUtils } from "../openaireLibrary/utils/number-utils.class" ;
import { SearchResearchResultsService } from "../openaireLibrary/services/searchResearchResults.service" ;
2019-09-30 14:51:38 +02:00
@Component ( {
selector : 'home' ,
templateUrl : 'home.component.html' ,
} )
export class HomeComponent {
public piwiksub : any ;
public pageTitle = "OpenAIRE | Monitor" ;
2019-12-03 12:10:05 +01:00
public funders = [ ] ;
public gifs : { "gif" : string , "header" : string , "text" } [ ] = [ ] ;
2019-09-30 14:51:38 +02:00
public pageContents = null ;
public divContents = null ;
2019-12-03 12:10:05 +01:00
// Message variables
2019-09-30 14:51:38 +02:00
public status : number ;
public loading : boolean = true ;
public subscriberErrorMessage : string = "" ;
public errorCodes : ErrorCodes ;
private errorMessages : ErrorMessagesComponent ;
properties : EnvProperties ;
public keyword : string = "" ;
public type : string = "all" ;
2019-12-03 12:10:05 +01:00
public publicationsSize :any = null ;
public datasetsSize :any = null ;
public softwareSize : any = null ;
public otherSize : any = null ;
public fundersSize :any = null ;
numberSubs = [ ] ;
2019-09-30 14:51:38 +02:00
constructor (
private route : ActivatedRoute ,
private _router : Router ,
private _meta : Meta ,
private _title : Title ,
private _piwikService : PiwikService ,
2019-12-03 12:10:05 +01:00
private _stakeholderService : StakeholderService ,
2019-09-30 14:51:38 +02:00
private helper : HelperService ,
2019-12-03 12:10:05 +01:00
private seoService : SEOService ,
private _refineFieldResultsService :RefineFieldResultsService , private _searchResearchResultsService : SearchResearchResultsService ) {
2019-09-30 14:51:38 +02:00
2019-12-03 12:10:05 +01:00
var description = "OpenAIRE - Monitor, Statistics, Search, Funder, EC, European Commision" ;
2019-09-30 14:51:38 +02:00
var title = "OpenAIRE - Monitor" ;
this . _meta . updateTag ( { content : description } , "name='description'" ) ;
this . _meta . updateTag ( { content : description } , "property='og:description'" ) ;
this . _meta . updateTag ( { content : title } , "property='og:title'" ) ;
this . _title . setTitle ( title ) ;
this . errorCodes = new ErrorCodes ( ) ;
this . errorMessages = new ErrorMessagesComponent ( ) ;
this . status = this . errorCodes . LOADING ;
}
public ngOnInit() {
this . route . data
. subscribe ( ( data : { envSpecific : EnvProperties } ) = > {
this . properties = data . envSpecific ;
var url = data . envSpecific . baseLink + this . _router . url ;
this . seoService . createLinkForCanonicalURL ( url , false ) ;
this . _meta . updateTag ( { content : url } , "property='og:url'" ) ;
if ( this . properties . enablePiwikTrack && ( typeof document !== 'undefined' ) ) {
this . piwiksub = this . _piwikService . trackView ( this . properties , "OpenAIRE Monitor" , this . properties . piwikSiteId ) . subscribe ( ) ;
}
2019-12-03 12:10:05 +01:00
this . getNumbers ( ) ;
this . getFunders ( ) ;
// this.createGifs();
2019-09-30 14:51:38 +02:00
//this.getDivContents();
this . getPageContents ( ) ;
2019-12-03 12:10:05 +01:00
2019-09-30 14:51:38 +02:00
} ) ;
}
private getPageContents() {
2019-12-03 12:10:05 +01:00
this . helper . getPageHelpContents ( this . _router . url , this . properties , 'connect' ) . subscribe ( contents = > {
2019-09-30 14:51:38 +02:00
this . pageContents = contents ;
} )
}
private getDivContents() {
2019-12-03 12:10:05 +01:00
this . helper . getDivHelpContents ( this . _router . url , this . properties , 'connect' ) . subscribe ( contents = > {
2019-09-30 14:51:38 +02:00
this . divContents = contents ;
} )
}
2019-12-03 12:10:05 +01:00
getNumbers ( ) {
this . numberSubs . push ( this . _refineFieldResultsService . getRefineFieldsResultsByEntityName ( [ "funder" ] , "project" , this . properties ) . subscribe (
data = > {
if ( data [ 1 ] . length > 0 && data [ 1 ] [ 0 ] . filterId == "funder" && data [ 1 ] [ 0 ] . values ) {
this . fundersSize = NumberUtils . roundNumber ( data [ 1 ] [ 0 ] . values . length ) ;
}
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting 'funder' field results of projects" , err ) ;
} ) ) ;
this . numberSubs . push ( this . _searchResearchResultsService . numOfSearchResults ( "publication" , "" , this . properties ) . subscribe (
data = > {
if ( data && data != null && data > 0 ) {
this . publicationsSize = NumberUtils . roundNumber ( data ) ;
}
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting number of publications" , err ) ;
}
) ) ;
this . numberSubs . push ( this . _searchResearchResultsService . numOfSearchResults ( "dataset" , "" , this . properties ) . subscribe (
data = > {
if ( data && data != null && data > 0 ) {
this . datasetsSize = NumberUtils . roundNumber ( data ) ;
}
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting number of research data" , err ) ;
}
) ) ;
this . numberSubs . 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 . numberSubs . 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 ) ;
}
) ) ;
}
public getFunders() {
this . loading = true ;
this . status = this . errorCodes . LOADING ;
this . subscriberErrorMessage = "" ;
this . funders = [ ] ;
this . _stakeholderService . mockgetFunders ( ) . subscribe (
funders = > {
console . log ( funders )
if ( ! funders ) {
return ;
}
if ( funders . length == 0 ) {
this . status = this . errorCodes . DONE ;
return ;
}
// this.sort(funders);
this . funders = funders ;
this . loading = false ;
} ,
error = > {
this . status = this . handleError ( "Error getting funders" , error ) ;
this . loading = false ;
}
) ;
}
private createGifs() {
this . gifs . push ( {
gif : "assets/connect-assets/home/gifs/deposit.gif" ,
header : "Find a repository to deposit your research outcome" ,
text : "This is OpenAIRE’ s key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
} ) ;
this . gifs . push ( {
gif : "assets/connect-assets/home/gifs/link.gif" ,
header : "Link your research output with your community, funding, and other research products" ,
text : "This is OpenAIRE’ s key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
} ) ;
this . gifs . push ( {
gif : "assets/connect-assets/home/gifs/overview.gif" ,
header : "View community's overview at a glance" ,
text : "This is OpenAIRE’ s key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
} ) ;
this . gifs . push ( {
gif : "assets/connect-assets/home/gifs/results.gif" ,
header : "Search & browse your community's research products. " ,
text : "This is OpenAIRE’ s key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
} ) ;
this . gifs . push ( {
gif : "assets/connect-assets/home/gifs/graph-analysis.gif" ,
header : "View statistics for your community's research products." ,
text : "This is OpenAIRE’ s key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
} ) ;
}
private sort ( results : CommunityInfo [ ] ) {
results . sort ( ( left , right ) : number = > {
if ( ! right . date || left . date > right . date ) {
return - 1 ;
} else if ( ! left . date || left . date < right . date ) {
return 1 ;
} else {
if ( left . title > right . title ) {
return 1 ;
} else if ( left . title < right . title ) {
return - 1 ;
} else {
return 0 ;
}
}
} )
}
2019-09-30 14:51:38 +02:00
public quote ( param : string ) : string {
return StringUtils . quote ( param ) ;
}
public ngOnDestroy() {
if ( this . piwiksub ) {
this . piwiksub . unsubscribe ( ) ;
}
}
private handleError ( message : string , error ) : number {
var code = "" ;
if ( ! error . status ) {
var error = error . json ( ) ;
code = error . code ;
} else {
code = error . status ;
}
console . error ( "Communities (component): " + message , error ) ;
return this . errorMessages . getErrorCode ( code ) ;
}
}