2018-01-26 16:00:07 +01:00
import { Component , Directive , ElementRef , Renderer , ChangeDetectionStrategy , ViewEncapsulation } from '@angular/core' ;
import { Observable } from 'rxjs/Observable' ;
2018-02-12 12:41:40 +01:00
import { ActivatedRoute } from '@angular/router' ;
2018-02-15 12:12:55 +01:00
import { EnvProperties } from './openaireLibrary/utils/properties/env-properties' ;
import { MenuItem , RootMenuItem } from './openaireLibrary/sharedComponents/menu' ;
import { EnvironmentSpecificService } from './openaireLibrary/utils/properties/environment-specific.service' ;
2018-03-16 09:55:38 +01:00
import { CommunitiesService } from "./openaireLibrary/connect/communities/communities.service" ;
import { Session } from './openaireLibrary/login/utils/helper.class' ;
2018-03-22 16:38:42 +01:00
import { ConnectHelper } from './utils/connectHelper' ;
2018-02-12 12:41:40 +01:00
2018-01-26 16:00:07 +01:00
@Component ( {
//changeDetection: ChangeDetectionStrategy.Default,
//encapsulation: ViewEncapsulation.Emulated,
selector : 'app-root' ,
styles : [ `
` ],
template : `
2018-03-22 16:38:42 +01:00
< navbar * ngIf = "properties && showMenu && !community" portal = "connect" onlyTop = false [ userMenuItems ] = userMenuItems [ menuItems ] = menuItems
[ ( APIUrl ) ] = "properties.adminToolsAPIURL" [ ( logInUrl ) ] = "properties.loginUrl" [ ( logOutUrl ) ] = "properties.logoutUrl" [ ( cookieDomain ) ] = "properties.cookieDomain" [ showMenu ] = showMenu > < / navbar >
2018-03-22 17:01:06 +01:00
< navbar * ngIf = "properties && community" portal = "connect" onlyTop = false [ ( communityId ) ] = " community.id " [ userMenuItems ] = userMenuItems [ menuItems ] = menuItems
2018-03-22 16:38:42 +01:00
[ ( APIUrl ) ] = "properties.adminToolsAPIURL" [ ( logInUrl ) ] = "properties.loginUrl" [ ( logOutUrl ) ] = "properties.logoutUrl" [ ( cookieDomain ) ] = "properties.cookieDomain" [ ( community ) ] = community [ showMenu ] = showMenu > < / navbar >
2018-03-16 09:55:38 +01:00
2018-01-26 16:00:07 +01:00
< div class = "custom-main-content" >
< main >
< router - outlet > < / r o u t e r - o u t l e t >
< / main >
< / div >
2018-03-16 09:55:38 +01:00
< feedback * ngIf = "isClient && properties" portalName = "Connect" [ feedbackmail ] = properties.feedbackmail > < / feedback >
2018-01-26 16:00:07 +01:00
< cookie - law * ngIf = "isClient" position = "bottom" >
OpenAIRE uses cookies in order to function properly . < br >
Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing experience possible .
By using the OpenAIRE portal you accept our use of cookies . < a href = "//ec.europa.eu/ipg/basics/legal/cookies/index_en.htm" target = "_blank" > Read more < span class = "uk-icon" >
< svg width = "20" height = "20" viewBox = "0 0 20 20" xmlns = "http://www.w3.org/2000/svg" icon = "chevron-right" ratio = "1" > < polyline fill = "none" stroke = "#000" stroke - width = "1.03" points = "7 4 13 10 7 16" > < / polyline > < / svg >
< / span > < / a >
< / c o o k i e - l a w >
< bottom * ngIf = "isClient" > < / bottom >
`
} )
export class AppComponent {
isClient :boolean = false ;
2018-02-12 12:41:40 +01:00
userMenuItems :MenuItem [ ] = [ ] ;
menuItems :RootMenuItem [ ] = [ ] ;
2018-03-01 12:45:37 +01:00
public community = null ;
2018-03-16 09:55:38 +01:00
properties :EnvProperties ;
showMenu :boolean = false ;
2018-03-22 17:01:06 +01:00
communities = null ;
2018-03-01 12:45:37 +01:00
// community: {id:string, name:string, logoUrl:string};
2018-03-16 09:55:38 +01:00
constructor ( private route : ActivatedRoute , private propertiesService :EnvironmentSpecificService , private _communitiesService :CommunitiesService ) {
2018-02-12 12:41:40 +01:00
}
2018-01-26 16:00:07 +01:00
ngOnInit() {
2018-03-01 17:11:31 +01:00
this . propertiesService . loadEnvironment ( )
. then ( es = > {
this . propertiesService . setEnvProperties ( es ) ;
this . properties = this . propertiesService . envSpecific ;
2018-02-12 12:41:40 +01:00
this . route . queryParams . subscribe ( data = > {
2018-03-16 09:55:38 +01:00
var community = null ;
2018-03-22 17:01:06 +01:00
this . community = null ;
2018-03-16 09:55:38 +01:00
this . showMenu = false ;
this . _communitiesService . getCommunities ( this . properties . communityAPI + "communities" ) . subscribe (
communities = > {
// this.community = community;
this . userMenuItems = [ new MenuItem ( "" , "My profile" , "" , "" , false , [ ] , [ ] , { } ) ,
new MenuItem ( "" , "My claims" , "" , "/myclaims" , false , [ ] , [ "/myclaims" ] , { } ) ,
] ;
for ( var com of communities ) {
for ( var manager of com . managers ) {
if ( manager == Session . getUserEmail ( ) ) {
this . userMenuItems . push ( new MenuItem ( "" , "Manage " + ( ( com . shortTitle ) ? com.shortTitle :com.title ) , "https://admin.demo.openaire.eu?communityId=" + com . communityId , "" , false , [ ] , [ ] , { } ) ) ;
}
}
2018-03-22 16:38:42 +01:00
if ( ( data [ 'communityId' ] && data [ 'communityId' ] != "" && com . communityId == data [ 'communityId' ] )
|| ( ConnectHelper . getCommunityFromDomain ( document . location . hostname ) == com . communityId ) ) {
2018-03-16 09:55:38 +01:00
community = com ;
this . community = { id : community.communityId , name : ( community . shortTitle ) ? community.shortTitle :community.title , logoUrl :community.logoUrl } ;
this . menuItems = [
2018-03-22 16:38:42 +01:00
{ rootItem : new MenuItem ( "home" , "Home" , ( typeof document !== 'undefined' && ConnectHelper . isProduction ( document . location . hostname ) ) ? 'https://beta.connect.openaire.eu' : '' , ( typeof document === 'undefined' || ! ConnectHelper . isProduction ( document . location . hostname ) ) ? '/' : '' , false , [ ] , [ ] , { } ) ,
2018-03-16 09:55:38 +01:00
items : [ ] } ,
2018-03-22 16:38:42 +01:00
{ rootItem : new MenuItem ( "dashboard" , "Dashboard" , "" , "/" , false , [ ] , [ ] , ( typeof document !== 'undefined' && ConnectHelper . isProduction ( document . location . hostname ) ) ? { } : { communityId :community.communityId } ) ,
2018-03-16 09:55:38 +01:00
items : [ ]
} ,
{ rootItem : new MenuItem ( "search" , "Search" , "" , "" , false , [ ] , [ ] , { } ) ,
items : [ new MenuItem ( "" , "Publications" , "" , "/search/find/publications" , false , [ "publication" ] , [ "/search/find/publications" ] , { community : encodeURIComponent ( '"' + community . queryId + '"' ) , communityId : community.communityId } ) ,
new MenuItem ( "" , "Research Data" , "" , "/search/find/datasets" , false , [ "dataset" ] , [ "/search/find/datasets" ] , { community : encodeURIComponent ( '"' + community . queryId + '"' ) , communityId : community.communityId } ) ,
new MenuItem ( "" , "Software" , "" , "/search/find/software" , false , [ "software" ] , [ "/search/find/software" ] , { community : encodeURIComponent ( '"' + community . queryId + '"' ) , communityId : community.communityId } ) ,
new MenuItem ( "" , "Projects" , "" , "/search/find/projects/" , false , [ "project" ] , [ "/search/find/projects" ] , { communityId : community.communityId } ) ,
new MenuItem ( "" , "Content Providers" , "" , "/search/find/dataproviders" , false , [ "datasource" ] , [ "/search/find/dataproviders" ] , { communityId : community.communityId } ) ,
// new MenuItem("","Organizations","","/search/find/organizations/",false,["organization"],["/search/find/organizations"],{community: community.communityId}),
] } ,
{
rootItem : new MenuItem ( "monitor" , "Monitor" , "" , "/statistics" , false , [ ] , [ "/statistics" ] , { communityId :community.communityId } ) ,
items : [ ]
} ,
{
rootItem : new MenuItem ( "share" , "Share" , "" , "" , false , [ ] , [ "/participate/deposit-publications" , "/participate/deposit-datasets" ] , { communityId :community.communityId } ) ,
items : [ new MenuItem ( "" , "Publications" , "" , "/participate/deposit-publications" , false , [ "publication" ] , [ "/participate/deposit-publications" ] , { communityId :community.communityId } ) ,
new MenuItem ( "" , "Research Data" , "" , "/participate/deposit-datasets" , false , [ "dataset" ] , [ "/participate/deposit-datasets" ] , { communityId :community.communityId } ) ]
} ,
{
rootItem : new MenuItem ( "link" , "Link" , "" , "/participate/claim" , false , [ ] , [ "/participate/claim" ] , { communityId :community.communityId } ) ,
items : [ ]
}
] ;
2018-03-22 16:38:42 +01:00
2018-03-16 09:55:38 +01:00
}
}
2018-03-22 16:38:42 +01:00
if ( community == null ) {
2018-03-16 09:55:38 +01:00
this . menuItems = [
{ rootItem : new MenuItem ( "communities" , "Communities" , "" , "/" , false , [ ] , [ ] , { } ) ,
2018-03-22 16:38:42 +01:00
items : [ ] }
] ;
2018-03-16 09:55:38 +01:00
}
this . showMenu = true ;
} ) ;
2018-02-12 12:41:40 +01:00
} ) ;
2018-01-26 16:00:07 +01:00
if ( typeof document !== 'undefined' ) {
try {
this . isClient = true ;
} catch ( e ) {
}
}
2018-03-01 17:11:31 +01:00
} , error = > {
console . log ( "App couldn't fetch properties" ) ;
console . log ( error ) ;
2018-02-12 12:41:40 +01:00
2018-03-01 17:11:31 +01:00
} ) ;
2018-01-26 16:00:07 +01:00
}
}