Revision 51199
Added by Argiro Kokogiannaki about 6 years ago
subscribe.component.ts | ||
---|---|---|
1 |
import { Component, Input } from '@angular/core'; |
|
1 |
import { Component, Input, ViewChild } from '@angular/core';
|
|
2 | 2 |
import { Location } from '@angular/common'; |
3 | 3 |
import {ActivatedRoute} from '@angular/router'; |
4 | 4 |
import { EnvProperties} from '../../openaireLibrary/utils/properties/env-properties'; |
5 |
import {AlertModal} from '../../openaireLibrary/utils/modal/alert'; |
|
5 | 6 |
|
6 | 7 |
import {SubscribeService} from './subscribe.service'; |
7 | 8 |
import {Session} from '../../openaireLibrary/login/utils/helper.class'; |
... | ... | |
9 | 10 |
selector: 'subscribe', |
10 | 11 |
template: ` |
11 | 12 |
|
12 |
<div *ngIf="subscribed != null"> |
|
13 |
<div *ngIf="subscribed != null && !showNumbers"> |
|
14 |
<div *ngIf="!subscribed && showLoginAlert" class="uk-alert-warning uk-animation-slide-bottom" uk-alert="" > |
|
15 |
<a class="uk-alert-close" uk-close></a> |
|
16 |
<p>Please login first to subscribe</p> |
|
17 |
</div> |
|
13 | 18 |
<a *ngIf="!subscribed" class="uk-button uk-button-primary" (click)="subscribe()"> Subscribe</a> |
14 |
<a *ngIf="subscribed" class="uk-button uk-button-primary" (click)="unsubscribe()"> Unsubscribe</a>
|
|
19 |
<a *ngIf="subscribed" class="uk-button uk-button-danger" (click)="confirmOpen()"> Unsubscribe</a>
|
|
15 | 20 |
</div> |
21 |
|
|
22 |
<span *ngIf="showNumbers && subscribers !=null && subscribers > 0" > |
|
23 |
Members: {{subscribers}} |
|
24 |
</span> |
|
25 |
<modal-alert (alertOutput)="confirmClose($event)"> |
|
26 |
</modal-alert> |
|
16 | 27 |
` |
17 | 28 |
}) |
18 | 29 |
|
... | ... | |
24 | 35 |
|
25 | 36 |
subscribed:boolean = null; |
26 | 37 |
properties:EnvProperties; |
38 |
subscribers:number= null; |
|
39 |
showLoginAlert:Boolean = false; |
|
40 |
@ViewChild(AlertModal) alert; |
|
27 | 41 |
constructor (private route: ActivatedRoute, |
28 | 42 |
private _subscribeService: SubscribeService |
29 | 43 |
) { |
... | ... | |
33 | 47 |
this.route.data |
34 | 48 |
.subscribe((data: { envSpecific: EnvProperties }) => { |
35 | 49 |
this.properties = data.envSpecific; |
36 |
console.log("subscribe "+ this.communityId); |
|
37 |
var email = Session.getUserEmail(); |
|
38 |
if(email == null){ |
|
39 |
this.subscribed = false; |
|
50 |
if(!this.showNumbers){ |
|
51 |
var email = Session.getUserEmail(); |
|
52 |
if(email == null){ |
|
53 |
this.subscribed = false; |
|
54 |
}else{ |
|
55 |
this._subscribeService.isSubscribedToCommunity(this.communityId, email,this.properties.adminToolsAPIURL).subscribe ( |
|
56 |
res => { |
|
57 |
this.subscribed = res; |
|
58 |
}); |
|
59 |
} |
|
40 | 60 |
}else{ |
41 |
//this.properties.adminToolsAPIURL |
|
42 |
this._subscribeService.isSubscribedToCommunity(this.communityId, email,this.properties.adminToolsAPIURL).subscribe ( |
|
61 |
this._subscribeService.getCommunitySubscribers(this.communityId, this.properties.adminToolsAPIURL).subscribe ( |
|
43 | 62 |
res => { |
44 |
this.subscribed = res; |
|
63 |
|
|
64 |
this.subscribers = (res && res.subscribers && res.subscribers.length )?res.subscribers.length:0; |
|
65 |
|
|
45 | 66 |
}); |
46 | 67 |
} |
47 | 68 |
}); |
48 | 69 |
|
70 |
|
|
49 | 71 |
} |
50 | 72 |
|
51 | 73 |
subscribe(){ |
52 | 74 |
var email = Session.getUserEmail(); |
53 | 75 |
if(email == null){ |
54 | 76 |
this.subscribed = false; |
77 |
this.showLoginAlert = true; |
|
55 | 78 |
}else{ |
56 |
//this.properties.adminToolsAPIURL
|
|
79 |
this.showLoginAlert = false;
|
|
57 | 80 |
this._subscribeService.subscribeToCommunity(this.communityId, email, this.properties.adminToolsAPIURL).subscribe ( |
58 | 81 |
res => { |
59 | 82 |
console.log(res); |
... | ... | |
70 | 93 |
this.subscribed = false; |
71 | 94 |
}else{ |
72 | 95 |
//this.properties.adminToolsAPIURL |
73 |
this._subscribeService.unSubscribeToCommunity(this.communityId, email,"http://scoobydoo.di.uoa.gr:8080/uoa-admin-tools/").subscribe (
|
|
96 |
this._subscribeService.unSubscribeToCommunity(this.communityId, email,this.properties.adminToolsAPIURL).subscribe (
|
|
74 | 97 |
res => { |
75 | 98 |
console.log(res); |
76 | 99 |
if(this.subscribed){ |
... | ... | |
79 | 102 |
}); |
80 | 103 |
} |
81 | 104 |
} |
105 |
|
|
106 |
confirmOpen(){ |
|
107 |
|
|
108 |
this.alert.cancelButton = true; |
|
109 |
this.alert.okButton = true; |
|
110 |
this.alert.alertTitle = "Unsubscribe community "; |
|
111 |
this.alert.message = "Do you want to proceed? "; |
|
112 |
this.alert.okButtonText = "Yes"; |
|
113 |
this.alert.cancelButtonText = "No"; |
|
114 |
this.alert.open(); |
|
115 |
} |
|
116 |
confirmClose(data){ |
|
117 |
this.unsubscribe(); |
|
118 |
} |
|
82 | 119 |
} |
Also available in: Unified diff
IsrouteEnabled remove community in every route | Add subscribers in community landing, add confirm for unsubscribe, add message to login for subscribe