2022-05-05 09:44:00 +02:00
import {
AfterViewInit ,
2022-12-08 10:52:26 +01:00
ChangeDetectorRef ,
2022-07-17 23:46:13 +02:00
Component ,
2022-05-05 09:44:00 +02:00
ElementRef ,
2022-12-08 10:52:26 +01:00
Inject ,
2022-07-17 23:46:13 +02:00
OnDestroy ,
OnInit ,
2022-12-08 10:52:26 +01:00
PLATFORM_ID ,
2022-05-05 09:44:00 +02:00
QueryList ,
2022-07-17 23:46:13 +02:00
ViewChild ,
ViewChildren
2022-05-05 09:44:00 +02:00
} from '@angular/core' ;
2019-09-30 14:51:38 +02:00
import { ActivatedRoute , Router } from '@angular/router' ;
import { Meta , Title } from '@angular/platform-browser' ;
import { EnvProperties } from '../openaireLibrary/utils/properties/env-properties' ;
import { PiwikService } from '../openaireLibrary/utils/piwik/piwik.service' ;
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 { RefineFieldResultsService } from "../openaireLibrary/services/refineFieldResults.service" ;
import { NumberUtils } from "../openaireLibrary/utils/number-utils.class" ;
import { SearchResearchResultsService } from "../openaireLibrary/services/searchResearchResults.service" ;
2020-06-03 23:55:32 +02:00
import { StakeholderService } from "../openaireLibrary/monitor/services/stakeholder.service" ;
2020-06-09 11:19:25 +02:00
import { LocalStorageService } from "../openaireLibrary/services/localStorage.service" ;
2022-06-08 13:01:10 +02:00
import { Stakeholder , StakeholderEntities , StakeholderInfo } from "../openaireLibrary/monitor/entities/stakeholder" ;
2022-02-17 16:31:58 +01:00
import { User } from "../openaireLibrary/login/utils/helper.class" ;
2020-06-10 23:51:10 +02:00
import { UserManagementService } from "../openaireLibrary/services/user-management.service" ;
2020-11-13 16:08:17 +01:00
import { properties } from "../../environments/environment" ;
import { Subscriber } from "rxjs" ;
2022-02-22 15:40:33 +01:00
import { QuickContactService } from '../openaireLibrary/sharedComponents/quick-contact/quick-contact.service' ;
2022-07-17 23:46:13 +02:00
import { IDeactivateComponent } from "../openaireLibrary/utils/can-exit.guard" ;
2022-05-09 12:39:45 +02:00
import { OpenaireEntities } from "../openaireLibrary/utils/properties/searchFields" ;
2022-12-08 10:52:26 +01:00
import { isPlatformServer } from '@angular/common' ;
import { LayoutService } from '../openaireLibrary/dashboard/sharedComponents/sidebar/layout.service' ;
2019-09-30 14:51:38 +02:00
@Component ( {
selector : 'home' ,
templateUrl : 'home.component.html' ,
2022-07-17 23:46:13 +02:00
styleUrls : [ 'home.component.less' ]
2019-09-30 14:51:38 +02:00
} )
2022-05-05 09:44:00 +02:00
export class HomeComponent implements OnInit , OnDestroy , AfterViewInit , IDeactivateComponent {
2019-09-30 14:51:38 +02:00
public pageTitle = "OpenAIRE | Monitor" ;
2022-02-16 11:03:03 +01:00
public description = "OpenAIRE - Monitor, A new era of monitoring research. Open data. Open methodologies. Work together with us to view, understand and visualize research statistics and indicators." ;
2022-02-17 16:31:58 +01:00
public stakeholders : StakeholderInfo [ ] = [ ] ;
2022-02-21 16:31:15 +01:00
public stakeholdersSlider : {
stakeholders : StakeholderInfo [ ] [ ] ;
funders : StakeholderInfo [ ] [ ] ;
ris : StakeholderInfo [ ] [ ] ;
organizations : StakeholderInfo [ ] [ ] ;
} ;
2020-06-09 11:19:25 +02:00
public selected : Stakeholder = null ;
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 errorCodes : ErrorCodes ;
2022-02-16 11:03:03 +01:00
public properties : EnvProperties = properties ;
2022-06-08 13:01:10 +02:00
public openaireEntities = OpenaireEntities ;
public stakeholderEntities = StakeholderEntities ;
2022-02-16 11:03:03 +01:00
public directLink : boolean = true ;
2020-06-03 23:55:32 +02:00
public publicationsSize : any = null ;
public datasetsSize : any = null ;
2019-12-03 12:10:05 +01:00
public softwareSize : any = null ;
public otherSize : any = null ;
2020-06-03 23:55:32 +02:00
public fundersSize : any = null ;
2022-02-16 11:03:03 +01:00
private errorMessages : ErrorMessagesComponent ;
private subscriptions = [ ] ;
2023-01-16 09:30:32 +01:00
private mutationObserver : MutationObserver ;
2020-06-10 23:51:10 +02:00
private user : User ;
2022-05-05 09:44:00 +02:00
@ViewChildren ( 'scrolling_element' ) elements : QueryList < ElementRef > ;
@ViewChild ( 'contact' ) contact : ElementRef ;
2022-12-08 10:52:26 +01:00
isMobile : boolean = false ;
isServer : boolean ;
2022-05-05 09:44:00 +02:00
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 ,
2020-06-09 11:19:25 +02:00
private localStorageService : LocalStorageService ,
2020-06-10 23:51:10 +02:00
private userManagementService : UserManagementService ,
2019-09-30 14:51:38 +02:00
private helper : HelperService ,
2019-12-03 12:10:05 +01:00
private seoService : SEOService ,
2022-02-22 15:40:33 +01:00
private _refineFieldResultsService : RefineFieldResultsService ,
2022-05-05 09:44:00 +02:00
private _searchResearchResultsService : SearchResearchResultsService ,
2022-12-08 10:52:26 +01:00
private quickContactService : QuickContactService ,
private layoutService : LayoutService ,
private cdr : ChangeDetectorRef ,
@Inject ( PLATFORM_ID ) private platform : any ) {
2022-02-16 11:03:03 +01:00
this . _meta . updateTag ( { content : this.description } , "name='description'" ) ;
this . _meta . updateTag ( { content : this.description } , "property='og:description'" ) ;
this . _meta . updateTag ( { content : this.pageTitle } , "property='og:title'" ) ;
this . _title . setTitle ( this . pageTitle ) ;
2019-09-30 14:51:38 +02:00
this . errorCodes = new ErrorCodes ( ) ;
this . errorMessages = new ErrorMessagesComponent ( ) ;
this . status = this . errorCodes . LOADING ;
2022-12-08 10:52:26 +01:00
this . isServer = isPlatformServer ( this . platform ) ;
2023-07-06 14:28:53 +02:00
this . quickContactService . setDisplay ( false ) ;
2019-09-30 14:51:38 +02:00
}
2022-05-05 09:44:00 +02:00
2019-09-30 14:51:38 +02:00
public ngOnInit() {
2022-02-16 11:03:03 +01:00
let url = this . properties . domain + this . properties . baseLink + this . _router . url ;
2020-11-13 16:08:17 +01:00
this . seoService . createLinkForCanonicalURL ( url , false ) ;
this . _meta . updateTag ( { content : url } , "property='og:url'" ) ;
if ( this . properties . enablePiwikTrack && ( typeof document !== 'undefined' ) ) {
this . subscriptions . push ( this . _piwikService . trackView ( this . properties , "OpenAIRE Monitor" , this . properties . piwikSiteId ) . subscribe ( ) ) ;
}
this . getNumbers ( ) ;
this . subscriptions . push ( this . localStorageService . get ( ) . subscribe ( value = > {
this . directLink = value ;
} ) ) ;
this . subscriptions . push ( this . userManagementService . getUserInfo ( ) . subscribe ( user = > {
this . user = user ;
2022-02-17 16:31:58 +01:00
this . getStakeholders ( ) ;
2020-11-13 16:08:17 +01:00
} ) ) ;
2022-12-08 10:52:26 +01:00
this . layoutService . isMobile . subscribe ( isMobile = > {
this . isMobile = isMobile ;
this . cdr . detectChanges ( ) ;
} ) ;
2020-06-03 23:55:32 +02:00
}
2022-02-24 17:43:20 +01:00
canExit ( ) : boolean {
2022-05-05 09:44:00 +02:00
this . clear ( ) ;
2022-02-24 17:43:20 +01:00
return true ;
}
2022-05-05 09:44:00 +02:00
ngOnDestroy() {
2023-07-06 15:06:01 +02:00
this . quickContactService . setDisplay ( true ) ;
2022-05-05 09:44:00 +02:00
this . clear ( ) ;
}
clear() {
2022-02-24 17:43:20 +01:00
this . subscriptions . forEach ( value = > {
if ( value instanceof Subscriber ) {
value . unsubscribe ( ) ;
2022-05-05 09:44:00 +02:00
} else if ( value instanceof IntersectionObserver || value instanceof MutationObserver ) {
value . disconnect ( ) ;
2022-02-24 17:43:20 +01:00
}
} ) ;
2023-01-16 09:30:32 +01:00
if ( this . mutationObserver ) {
this . mutationObserver . disconnect ( ) ;
}
2022-02-22 15:40:33 +01:00
}
2022-05-05 09:44:00 +02:00
ngAfterViewInit() {
2022-05-06 09:53:20 +02:00
if ( typeof window !== "undefined" ) {
this . createObservers ( ) ;
}
2022-02-22 15:40:33 +01:00
}
2022-05-05 09:44:00 +02:00
createObservers() {
let options = {
root : null ,
rootMargin : '200px' ,
threshold : 1.0
} ;
let intersectionObserver = new IntersectionObserver ( entries = > {
entries . forEach ( entry = > {
2023-07-06 14:28:53 +02:00
this . quickContactService . setDisplay ( ! entry . isIntersecting ) ;
2022-05-05 09:44:00 +02:00
} ) ;
} , options ) ;
2022-12-12 10:27:40 +01:00
if ( this . contact ) {
intersectionObserver . observe ( this . contact . nativeElement ) ;
}
2023-01-16 09:30:32 +01:00
this . mutationObserver = new MutationObserver ( entries = > {
2022-05-05 09:44:00 +02:00
entries . forEach ( entry = > {
if ( entry . attributeName === 'style' ) {
let opacities : number [ ] = this . elements . map ( element = > + element . nativeElement . style . opacity ) ;
let active : number = opacities . indexOf ( Math . max ( . . . opacities ) ) ;
this . elements . forEach ( ( element , index ) = > {
if ( index === active ) {
element . nativeElement . classList . remove ( 'uk-disabled' ) ;
} else {
element . nativeElement . classList . add ( 'uk-disabled' ) ;
}
} )
}
} )
} ) ;
2023-01-16 09:30:32 +01:00
this . elements . changes . subscribe ( ( ) = > {
this . elements . forEach ( element = > {
this . mutationObserver . observe ( element . nativeElement , { attributes : true } ) ;
} ) ;
2022-05-05 09:44:00 +02:00
} ) ;
this . subscriptions . push ( intersectionObserver ) ;
}
2019-09-30 14:51:38 +02:00
private getPageContents() {
2020-11-13 16:08:17 +01:00
this . subscriptions . push ( this . helper . getPageHelpContents ( this . properties , 'monitor' , this . _router . url ) . subscribe ( contents = > {
2019-09-30 14:51:38 +02:00
this . pageContents = contents ;
2020-11-13 16:08:17 +01:00
} ) ) ;
2019-09-30 14:51:38 +02:00
}
2020-06-03 23:55:32 +02:00
2019-09-30 14:51:38 +02:00
private getDivContents() {
2020-11-13 16:08:17 +01:00
this . subscriptions . push ( this . helper . getDivHelpContents ( this . properties , 'monitor' , this . _router . url ) . subscribe ( contents = > {
2019-09-30 14:51:38 +02:00
this . divContents = contents ;
2020-11-13 16:08:17 +01:00
} ) ) ;
2019-09-30 14:51:38 +02:00
}
2020-06-03 23:55:32 +02:00
getNumbers() {
2020-11-13 16:08:17 +01:00
this . subscriptions . push ( this . _refineFieldResultsService . getRefineFieldsResultsByEntityName ( [ "funder" ] , "project" , this . properties ) . subscribe (
2019-12-03 12:10:05 +01:00
data = > {
2020-06-03 23:55:32 +02:00
if ( data [ 1 ] . length > 0 && data [ 1 ] [ 0 ] . filterId == "funder" && data [ 1 ] [ 0 ] . values ) {
2019-12-03 12:10:05 +01:00
this . fundersSize = NumberUtils . roundNumber ( data [ 1 ] [ 0 ] . values . length ) ;
}
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting 'funder' field results of projects" , err ) ;
} ) ) ;
2022-05-05 09:44:00 +02:00
2020-11-13 16:08:17 +01:00
this . subscriptions . push ( this . _searchResearchResultsService . numOfSearchResults ( "publication" , "" , this . properties ) . subscribe (
2020-06-03 23:55:32 +02:00
data = > {
if ( data && data > 0 ) {
this . publicationsSize = NumberUtils . roundNumber ( data ) ;
2019-12-03 12:10:05 +01:00
}
2020-06-03 23:55:32 +02:00
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting number of publications" , err ) ;
}
) ) ;
2022-05-05 09:44:00 +02:00
2020-11-13 16:08:17 +01:00
this . subscriptions . push ( this . _searchResearchResultsService . numOfSearchResults ( "dataset" , "" , this . properties ) . subscribe (
2020-06-03 23:55:32 +02:00
data = > {
if ( data && data > 0 ) {
this . datasetsSize = NumberUtils . roundNumber ( data ) ;
2019-12-03 12:10:05 +01:00
}
2020-06-03 23:55:32 +02:00
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting number of research data" , err ) ;
}
) ) ;
2022-05-05 09:44:00 +02:00
2020-11-13 16:08:17 +01:00
this . subscriptions . push ( this . _searchResearchResultsService . numOfSearchResults ( "software" , "" , this . properties ) . subscribe (
2020-06-03 23:55:32 +02:00
data = > {
if ( data && data > 0 ) {
this . softwareSize = NumberUtils . roundNumber ( data ) ;
2019-12-03 12:10:05 +01:00
}
2020-06-03 23:55:32 +02:00
} ,
err = > {
this . handleError ( "Error getting number of software data" , err ) ;
}
) ) ;
2022-05-05 09:44:00 +02:00
2020-11-13 16:08:17 +01:00
this . subscriptions . push ( this . _searchResearchResultsService . numOfSearchResults ( "other" , "" , this . properties ) . subscribe (
2020-06-03 23:55:32 +02:00
data = > {
if ( data && data > 0 ) {
this . otherSize = NumberUtils . roundNumber ( data ) ;
2019-12-03 12:10:05 +01:00
}
2020-06-03 23:55:32 +02:00
} ,
err = > {
this . handleError ( "Error getting number of software data" , err ) ;
}
) ) ;
2019-12-03 12:10:05 +01:00
}
2020-06-03 23:55:32 +02:00
2020-06-10 23:51:10 +02:00
public getStakeholders() {
2019-12-03 12:10:05 +01:00
this . loading = true ;
this . status = this . errorCodes . LOADING ;
2020-11-13 16:08:17 +01:00
this . subscriptions . push ( this . _stakeholderService . getStakeholders ( this . properties . monitorServiceAPIURL ) . subscribe (
2020-06-03 23:55:32 +02:00
stakeholders = > {
if ( ! stakeholders || stakeholders . length == 0 ) {
this . status = this . errorCodes . NONE ;
} else {
2022-02-17 16:31:58 +01:00
this . stakeholders = StakeholderInfo . toStakeholderInfo ( stakeholders , this . user ) ;
this . sort ( this . stakeholders ) ;
this . stakeholders = this . publicStakeholders . concat ( this . privateStakeholders ) ;
2022-02-21 16:31:15 +01:00
this . stakeholdersSlider = {
2022-10-21 16:11:16 +02:00
stakeholders : this.stakeholderSlider ( this . stakeholders ) ,
funders : this.stakeholderSlider ( this . funders ) ,
ris : this.stakeholderSlider ( this . ris ) ,
organizations : this.stakeholderSlider ( this . organizations )
2022-02-21 16:31:15 +01:00
} ;
2019-12-03 12:10:05 +01:00
}
this . loading = false ;
} ,
error = > {
2022-02-16 11:03:03 +01:00
this . status = this . handleError ( "Error getting stakeholders" , error ) ;
2019-12-03 12:10:05 +01:00
this . loading = false ;
}
2020-11-13 16:08:17 +01:00
) ) ;
2019-12-03 12:10:05 +01:00
}
2020-06-03 23:55:32 +02:00
2022-02-17 16:31:58 +01:00
private sort ( results : StakeholderInfo [ ] ) {
results . sort ( ( left , right ) : number = > {
if ( left . name > right . name ) {
return 1 ;
} else if ( left . name < right . name ) {
return - 1 ;
} else {
return 0 ;
}
} )
}
2022-10-21 16:11:16 +02:00
public stakeholderSlider ( stakeholders : StakeholderInfo [ ] , size : number = 6 ) : StakeholderInfo [ ] [ ] {
2022-02-21 16:31:15 +01:00
let slider : StakeholderInfo [ ] [ ] = [ ] ;
2022-05-05 09:44:00 +02:00
for ( let i = 0 ; i < ( stakeholders . length / size ) ; i ++ ) {
slider . push ( stakeholders . slice ( i * size , ( ( i + 1 ) * size ) ) ) ;
2022-02-17 13:44:23 +01:00
}
return slider ;
}
2022-02-17 16:31:58 +01:00
get publicStakeholders ( ) : StakeholderInfo [ ] {
return this . stakeholders . filter ( stakeholder = > stakeholder . visibility === "PUBLIC" ) ;
}
2022-05-05 09:44:00 +02:00
2022-02-17 16:31:58 +01:00
get privateStakeholders ( ) : StakeholderInfo [ ] {
return this . stakeholders . filter ( stakeholder = > stakeholder . visibility !== "PUBLIC" ) ;
}
get funders ( ) : StakeholderInfo [ ] {
2022-05-05 09:44:00 +02:00
if ( this . stakeholders ) {
return this . stakeholders . filter ( stakeholder = > stakeholder . type === "funder" ) ;
} else {
return [ ] ;
}
2022-02-17 13:44:23 +01:00
}
2022-05-05 09:44:00 +02:00
get ris ( ) : StakeholderInfo [ ] {
if ( this . stakeholders ) {
return this . stakeholders . filter ( stakeholder = > stakeholder . type === "ri" ) ;
} else {
return [ ] ;
}
2022-02-16 11:03:03 +01:00
}
2022-05-05 09:44:00 +02:00
get organizations ( ) : StakeholderInfo [ ] {
if ( this . stakeholders ) {
return this . stakeholders . filter ( stakeholder = > stakeholder . type === "organization" ) ;
} else {
return [ ] ;
}
2019-09-30 14:51:38 +02:00
}
2020-06-03 23:55:32 +02:00
2019-09-30 14:51:38 +02:00
private handleError ( message : string , error ) : number {
2022-02-16 11:03:03 +01:00
let code = "" ;
2019-09-30 14:51:38 +02:00
if ( ! error . status ) {
code = error . code ;
} else {
code = error . status ;
}
2020-10-26 14:11:13 +01:00
console . error ( "Home Component: " + message , error ) ;
2019-09-30 14:51:38 +02:00
return this . errorMessages . getErrorCode ( code ) ;
}
}