2019-04-18 14:50:14 +02:00
import { Component } from '@angular/core' ;
2019-06-05 15:39:02 +02:00
import { ActivatedRoute , Router } from '@angular/router' ;
import { Meta , Title } from '@angular/platform-browser' ;
import { EnvProperties } from '../openaireLibrary/utils/properties/env-properties' ;
import { CommunitiesService } from '../openaireLibrary/connect/communities/communities.service' ;
import { CommunityInfo } from '../openaireLibrary/connect/community/communityInfo' ;
2018-03-14 14:28:45 +01:00
2019-06-05 15:39:02 +02:00
import { PiwikService } from '../openaireLibrary/utils/piwik/piwik.service' ;
import { StringUtils } from '../openaireLibrary/utils/string-utils.class' ;
2019-04-08 14:17:39 +02:00
2019-06-05 15:39:02 +02:00
import { ErrorCodes } from '../openaireLibrary/utils/properties/errorCodes' ;
import { ErrorMessagesComponent } from '../openaireLibrary/utils/errorMessages.component' ;
2019-07-18 13:36:05 +02:00
import { HelperService } from "../openaireLibrary/utils/helper/helper.service" ;
2019-08-02 16:56:03 +02:00
import { SEOService } from "../openaireLibrary/sharedComponents/SEO/SEO.service" ;
2020-09-18 15:27:26 +02:00
import { properties } from "../../environments/environment" ;
2020-11-12 16:59:26 +01:00
import { Subscriber } from "rxjs" ;
2018-03-14 14:28:45 +01:00
2018-01-26 16:00:07 +01:00
@Component ( {
2019-07-18 13:36:05 +02:00
selector : 'communities' ,
templateUrl : 'communities.component.html' ,
2018-01-26 16:00:07 +01:00
} )
2018-03-14 14:28:45 +01:00
2018-01-26 16:00:07 +01:00
export class CommunitiesComponent {
2020-11-12 16:59:26 +01:00
private subscriptions = [ ] ;
2018-01-26 16:00:07 +01:00
public pageTitle = "OpenAIRE"
2021-11-12 11:56:15 +01:00
public researchCommunities : CommunityInfo [ ] = [ ] ;
2019-07-18 13:36:05 +02:00
public gifs : { "gif" : string , "header" : string , "text" } [ ] = [ ] ;
public pageContents = null ;
public divContents = null ;
2019-04-08 14:17:39 +02:00
// Message variables
public status : number ;
public loading : boolean = true ;
2019-04-09 20:48:03 +02:00
public subscriberErrorMessage : string = "" ;
2019-04-08 14:17:39 +02:00
public errorCodes : ErrorCodes ;
private errorMessages : ErrorMessagesComponent ;
2019-07-18 13:36:05 +02:00
properties : EnvProperties ;
public keyword : string = "" ;
public type : string = "all" ;
constructor (
private route : ActivatedRoute ,
private _router : Router ,
private _meta : Meta ,
private _title : Title ,
private _piwikService : PiwikService ,
private _communitiesService : CommunitiesService ,
2019-08-02 16:56:03 +02:00
private helper : HelperService ,
private seoService : SEOService ) {
2019-07-18 13:36:05 +02:00
var description = "OpenAIRE - Connect, Community Dashboard, research community" ;
var title = "OpenAIRE - Connect" ;
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 ;
2019-04-08 14:17:39 +02:00
}
public ngOnInit() {
2020-11-12 16:59:26 +01:00
this . properties = properties ;
var url = this . properties . domain + this . properties . 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 . subscriptions . push ( this . _piwikService . trackView ( this . properties , "OpenAIRE Connect" , this . properties . piwikSiteId ) . subscribe ( ) ) ;
}
this . getCommunities ( ) ;
this . createGifs ( ) ;
//this.getDivContents();
this . getPageContents ( ) ;
2019-07-18 13:36:05 +02:00
}
2018-01-26 16:00:07 +01:00
2019-07-18 18:03:37 +02:00
private getPageContents() {
2020-11-12 16:59:26 +01:00
this . subscriptions . push ( this . helper . getPageHelpContents ( this . properties , 'connect' , this . _router . url ) . subscribe ( contents = > {
2019-07-18 13:36:05 +02:00
this . pageContents = contents ;
2020-11-12 16:59:26 +01:00
} ) ) ;
2019-07-18 13:36:05 +02:00
}
2019-07-18 18:03:37 +02:00
private getDivContents() {
2020-11-12 16:59:26 +01:00
this . subscriptions . push ( this . helper . getDivHelpContents ( this . properties , 'connect' , this . _router . url ) . subscribe ( contents = > {
2019-07-18 13:36:05 +02:00
this . divContents = contents ;
2020-11-12 16:59:26 +01:00
} ) ) ;
2019-07-18 13:36:05 +02:00
}
public getCommunities() {
this . loading = true ;
this . status = this . errorCodes . LOADING ;
this . subscriberErrorMessage = "" ;
2019-04-08 14:17:39 +02:00
2019-07-18 13:36:05 +02:00
this . researchCommunities = [ ] ;
2020-11-12 16:59:26 +01:00
this . subscriptions . push ( this . _communitiesService . getCommunitiesState ( ) . subscribe (
2019-07-18 13:36:05 +02:00
communitiesResults = > {
2019-07-30 10:59:40 +02:00
if ( ! communitiesResults ) {
return ;
}
2019-07-30 17:25:30 +02:00
if ( communitiesResults . length == 0 ) {
this . status = this . errorCodes . DONE ;
return ;
}
2019-07-18 13:36:05 +02:00
this . sort ( communitiesResults ) ;
communitiesResults . forEach ( ( community , index ) = > {
let showCommunity : boolean = true ;
2019-08-28 14:54:35 +02:00
if ( community [ 'status' ] == "hidden" || community [ 'status' ] == "manager" ) {
2019-07-18 13:36:05 +02:00
showCommunity = false ;
}
if ( showCommunity ) {
this . researchCommunities . push ( community ) ;
}
this . status = this . errorCodes . DONE ;
} ) ;
2019-08-28 14:54:35 +02:00
this . loading = false ;
2019-07-18 13:36:05 +02:00
} ,
error = > {
this . status = this . handleError ( "Error getting communities" , error ) ;
this . loading = false ;
}
2020-11-12 16:59:26 +01:00
) ) ;
2019-07-18 13:36:05 +02:00
}
2019-06-24 21:22:27 +02:00
2019-07-18 13:36:05 +02:00
private createGifs() {
this . gifs . push ( {
2019-07-26 12:59:38 +02:00
gif : "assets/connect-assets/home/gifs/deposit.gif" ,
2019-07-18 13:36:05 +02:00
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 ( {
2019-07-26 12:59:38 +02:00
gif : "assets/connect-assets/home/gifs/link.gif" ,
2019-07-18 13:36:05 +02:00
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 ( {
2019-07-26 12:59:38 +02:00
gif : "assets/connect-assets/home/gifs/overview.gif" ,
2019-07-18 13:36:05 +02:00
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 ( {
2019-07-26 12:59:38 +02:00
gif : "assets/connect-assets/home/gifs/results.gif" ,
2019-07-18 13:36:05 +02:00
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 ( {
2019-07-26 12:59:38 +02:00
gif : "assets/connect-assets/home/gifs/graph-analysis.gif" ,
2019-07-18 13:36:05 +02:00
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."
} ) ;
}
2019-04-08 14:17:39 +02:00
2019-07-18 13:36:05 +02:00
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 ) {
2019-04-15 12:06:58 +02:00
return 1 ;
2019-07-18 13:36:05 +02:00
} else if ( left . title < right . title ) {
return - 1 ;
2019-04-15 12:06:58 +02:00
} else {
2019-07-18 13:36:05 +02:00
return 0 ;
2019-04-15 12:06:58 +02:00
}
2019-07-18 13:36:05 +02:00
}
} )
}
2019-04-15 12:06:58 +02:00
2019-07-18 13:36:05 +02:00
public quote ( param : string ) : string {
return StringUtils . quote ( param ) ;
}
2019-04-08 14:17:39 +02:00
2020-11-12 16:59:26 +01:00
ngOnDestroy() {
this . subscriptions . forEach ( subscription = > {
if ( subscription instanceof Subscriber ) {
subscription . unsubscribe ( ) ;
}
} ) ;
2019-07-18 13:36:05 +02:00
}
2019-04-08 14:17:39 +02:00
2019-07-18 13:36:05 +02:00
private handleError ( message : string , error ) : number {
var code = "" ;
2020-11-12 16:59:26 +01:00
try {
if ( ! error . status ) {
var error = error . json ( ) ;
code = error . code ;
} else {
code = error . status ;
}
} catch ( e ) { }
2019-07-18 13:36:05 +02:00
console . error ( "Communities (component): " + message , error ) ;
return this . errorMessages . getErrorCode ( code ) ;
}
2018-01-26 16:00:07 +01:00
}