Project

General

Profile

1
import {Component, ElementRef, ViewChild} from '@angular/core';
2
import {Observable} from 'rxjs/Observable';
3
import {ActivatedRoute} from '@angular/router';
4

    
5
import {UserComponent} from '../openaireLibrary/login/user.component';
6
import {SubscribeService} from '../openaireLibrary/utils/subscribe/subscribe.service';
7
import {EmailService} from "../openaireLibrary/utils/email/email.service";
8
import {Email} from "../openaireLibrary/utils/email/email";
9

    
10
import {Session} from '../openaireLibrary/login/utils/helper.class';
11
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
12
import {SubscribeComponent} from '../utils/subscribe/subscribe.component';
13
import {ConnectHelper} from '../openaireLibrary/connect/connectHelper';
14

    
15
@Component({
16
  selector: 'openaire-user',
17
  template: `
18
<div id="tm-main" class="uk-section  uk-margin-small-top tm-middle">
19

    
20
  <user [mainComponent]=false></user>
21
  <div *ngIf="!server" class=" uk-container uk-container-small uk-position-relative">
22

    
23
    <div *ngIf="usercomponent.errorCode == '6' && !isSubscribed" class="uk-alert uk-alert-warning">
24
      <span *ngIf="!isSubscribed ">For this action you have to <span *ngIf="!loggedIn">login and</span> subscribe to the research community.
25
        <span *ngIf="subscribe && !subscribeLoading "> <span *ngIf="!loggedIn">Login and </span>Subscribe <a [class]="'' + (subscribe.loading ? ' uk-disabled' : '')"  (click)="subscribeTo()"  > here</a>.</span>
26
      </span>
27
      <span *ngIf="subscribeLoading ">Subscribing to community....</span>
28
      <span *ngIf="subscribeError ">An error occured while trying to subscribe to community....</span>
29

    
30
    </div>
31
    <div *ngIf="usercomponent.errorCode == '7'" class="uk-alert uk-alert-warning">
32
      This action requires authentication.
33
      <span  *ngIf="!loggedIn">
34
        Please  <a  class=""  (click)="login()"  > sign in</a> to continue.
35
       </span>
36
    </div>
37

    
38

    
39
  </div>
40
</div>
41
<subscribe  [communityId]="communityId" [showTemplate]= false class="" (subscribeEvent)="afterSubscibeEvent($event)"></subscribe>
42
    `
43
})
44

    
45
export class OpenaireUserComponent {
46
  @ViewChild(UserComponent) usercomponent:UserComponent;
47
  @ViewChild(SubscribeComponent) subscribe:SubscribeComponent;
48
  properties:EnvProperties;
49
  communityId = null;
50
  subscribeLoading:boolean = false;
51
  subscribeError:boolean = false;
52
  isSubscribed:boolean = false;
53
  public server: boolean = true;
54
  loggedIn:boolean = false;
55
  constructor(private _subscribeService: SubscribeService,
56
              private _emailService: EmailService, private route: ActivatedRoute){}
57
  public ngOnInit() {
58
    if( typeof document !== 'undefined') {
59
      this.server = false;
60
      this.loggedIn = Session.isLoggedIn();
61
    }
62
    this.route.data
63
      .subscribe((data: { envSpecific: any }) => {
64
        this.route.queryParams.subscribe(
65
          communityId => {
66
            this.communityId  = ConnectHelper.getCommunityFromDomain(data.envSpecific.domain);
67
            if(!this.communityId) {
68
              this.communityId = communityId['communityId'];
69
            }
70
            if(this.subscribe.subscribed){
71
              this.usercomponent.redirect();
72
            }
73
          });
74
      });
75

    
76

    
77

    
78
  }
79
  login(){
80
    this.usercomponent.logIn();
81

    
82
  }
83
  subscribeTo(){
84
    if(this.subscribe && this.communityId){
85
      this.subscribeLoading = true;
86
      this.subscribe.subscribe();
87

    
88

    
89

    
90
    }
91

    
92
  }
93
  afterSubscibeEvent($event){
94
    var res = $event.value;
95
    this.subscribeLoading = false;
96
    this.isSubscribed = this.subscribe.subscribed;
97
    if(res == "ok"){
98
      this.isSubscribed = true;
99
      this.usercomponent.redirect();
100
    }else{
101
      this.subscribeError = true;
102
    }
103

    
104
  }
105

    
106
}
(3-3/3)