import {Component, ElementRef, ViewChild} from '@angular/core'; import {Observable} from 'rxjs/Observable'; import {ActivatedRoute} from '@angular/router'; import {UserComponent} from '../openaireLibrary/login/user.component'; import {SubscribeService} from '../openaireLibrary/utils/subscribe/subscribe.service'; import {EmailService} from "../openaireLibrary/utils/email/email.service"; import {Email} from "../openaireLibrary/utils/email/email"; import {Session} from '../openaireLibrary/login/utils/helper.class'; import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties'; import {SubscribeComponent} from '../utils/subscribe/subscribe.component'; import {ConnectHelper} from '../openaireLibrary/connect/connectHelper'; @Component({ selector: 'openaire-user', template: `
For this action you have to login and subscribe to the research community. Login and Subscribe here. Subscribing to community.... An error occured while trying to subscribe to community....
This action requires authentication. Please sign in to continue.
` }) export class OpenaireUserComponent { @ViewChild(UserComponent) usercomponent:UserComponent; @ViewChild(SubscribeComponent) subscribe:SubscribeComponent; properties:EnvProperties; communityId = null; subscribeLoading:boolean = false; subscribeError:boolean = false; isSubscribed:boolean = false; public server: boolean = true; loggedIn:boolean = false; constructor(private _subscribeService: SubscribeService, private _emailService: EmailService, private route: ActivatedRoute){} public ngOnInit() { if( typeof document !== 'undefined') { this.server = false; this.loggedIn = Session.isLoggedIn(); } this.route.data .subscribe((data: { envSpecific: any }) => { this.route.queryParams.subscribe( communityId => { this.communityId = ConnectHelper.getCommunityFromDomain(data.envSpecific.domain); if(!this.communityId) { this.communityId = communityId['communityId']; } if(this.subscribe.subscribed){ this.usercomponent.redirect(); } }); }); } login(){ this.usercomponent.logIn(); } subscribeTo(){ if(this.subscribe && this.communityId){ this.subscribeLoading = true; this.subscribe.subscribe(); } } afterSubscibeEvent($event){ var res = $event.value; this.subscribeLoading = false; this.isSubscribed = this.subscribe.subscribed; if(res == "ok"){ this.isSubscribed = true; this.usercomponent.redirect(); }else{ this.subscribeError = true; } } }