import {Component, Input, Output, EventEmitter} from '@angular/core'; import {ViewChild, ChangeDetectionStrategy} from '@angular/core'; import {ViewEncapsulation} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; import {Location} from '@angular/common'; import {Title, Meta} from '@angular/platform-browser'; import {Observable} from 'rxjs/Observable'; import "rxjs/add/observable/zip"; import {ConnectHelper} from '../../openaireLibrary/connect/connectHelper'; import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties'; import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes'; import {ConfigurationService} from '../../openaireLibrary/utils/configuration/configuration.service'; import {CommunitiesService} from '../../openaireLibrary/connect/communities/communities.service'; import {PiwikService} from '../../openaireLibrary/utils/piwik/piwik.service'; import {Session} from '../../openaireLibrary/login/utils/helper.class'; @Component({ selector: 'communities', templateUrl: 'communities.component.html', }) export class CommunitiesComponent { public piwiksub: any; public subfunders: any; public pageTitle = "OpenAIRE" public communitiesResults = null; properties:EnvProperties; constructor ( private route: ActivatedRoute, private _router: Router, private location: Location, private _meta: Meta, private _title: Title, private _piwikService:PiwikService, private _communitiesService:CommunitiesService, private config: ConfigurationService) { var description = "Community Dashboard"; var title = "Community Dashboard"; 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); } public ngOnInit() { this.route.data .subscribe((data: { envSpecific: EnvProperties }) => { this.properties = data.envSpecific; var url = data.envSpecific.baseLink+this._router.url this._meta.updateTag({content:url},"property='og:url'"); if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){ this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE Connect", this.properties.piwikSiteId).subscribe(); } this._communitiesService.getCommunities(this.properties, this.properties.communitiesAPI).subscribe( communitiesResults => { this.communitiesResults = communitiesResults; //console.log(communitiesResults); }); }); } public ngOnDestroy() { if(this.piwiksub){ this.piwiksub.unsubscribe(); } } isProduction():boolean{ return ConnectHelper.isProduction(document.location.hostname); } getProductionPrefix():string{ return ConnectHelper.getProductionPrefix(document.location.hostname); } showCommunity(community):boolean{ if(community['type'] !="ri"){ return false; } if(community['status'] == "hidden"){ return false; }else if(community['status'] == "manager"){ var mail = Session.getUserEmail(); if(mail == null){ // no user return false; }else if(Session.isCommunityCurator() || Session.isPortalAdministrator()){ return true; }else if(community.managers.indexOf(mail)!=-1){ return true; } return false; } return true; } }