Revision 53349
Added by Konstantina Galouni over 5 years ago
subscribe.component.ts | ||
---|---|---|
6 | 6 |
|
7 | 7 |
import {SubscribeService} from '../../openaireLibrary/utils/subscribe/subscribe.service'; |
8 | 8 |
import {Session} from '../../openaireLibrary/login/utils/helper.class'; |
9 |
|
|
10 |
declare var UIkit: any; |
|
11 |
|
|
9 | 12 |
@Component({ |
10 | 13 |
selector: 'subscribe', |
11 | 14 |
template: ` |
... | ... | |
15 | 18 |
<a class="uk-alert-close" uk-close></a> |
16 | 19 |
<p>Please login first to subscribe</p> |
17 | 20 |
</div> |
18 |
<a *ngIf="!subscribed" class="uk-button uk-button-primary" (click)="subscribe()"> Subscribe</a>
|
|
19 |
<a *ngIf="subscribed" class="uk-button uk-button-danger" (click)="confirmOpen()"> Unsubscribe</a>
|
|
21 |
<a *ngIf="!subscribed" [class]="'uk-button uk-button-primary' + (loading ? ' uk-disabled' : '')" (click)="subscribe()"> Subscribe</a>
|
|
22 |
<a *ngIf="subscribed" [class]="'uk-button uk-button-danger' + (loading ? ' uk-disabled' : '')" (click)="confirmOpen()"> Unsubscribe</a>
|
|
20 | 23 |
</span> |
21 | 24 |
|
22 | 25 |
<span *ngIf="showNumbers && subscribers !=null && subscribers > 0" > |
... | ... | |
32 | 35 |
@Input() showNumbers:boolean; |
33 | 36 |
@Input() communityId:string; |
34 | 37 |
|
35 |
|
|
38 |
loading: boolean = false; |
|
36 | 39 |
subscribed:boolean = null; |
37 | 40 |
properties:EnvProperties; |
38 | 41 |
subscribers:number= null; |
... | ... | |
76 | 79 |
this.subscribed = false; |
77 | 80 |
this.showLoginAlert = true; |
78 | 81 |
}else{ |
82 |
this.loading = true; |
|
79 | 83 |
this.showLoginAlert = false; |
80 | 84 |
this._subscribeService.subscribeToCommunity(this.communityId, email, this.properties.adminToolsAPIURL).subscribe ( |
81 | 85 |
res => { |
86 |
this.loading = false; |
|
82 | 87 |
console.log(res); |
83 |
if(!this.subscribed){ |
|
84 |
this.subscribed = true; |
|
85 |
} |
|
88 |
if(res.status && res.status != 200) { |
|
89 |
UIkit.notification({ |
|
90 |
message : '<strong>There was an error in your subscription. Please try again!<strong>', |
|
91 |
status : 'warning', |
|
92 |
timeout : 3000, |
|
93 |
pos : 'top-center' |
|
94 |
}); |
|
95 |
} else { |
|
96 |
if(!this.subscribed){ |
|
97 |
this.subscribed = true; |
|
98 |
} |
|
99 |
} |
|
86 | 100 |
}); |
87 | 101 |
} |
88 | 102 |
} |
... | ... | |
92 | 106 |
if(email == null){ |
93 | 107 |
this.subscribed = false; |
94 | 108 |
}else{ |
109 |
this.loading = true; |
|
95 | 110 |
//this.properties.adminToolsAPIURL |
96 | 111 |
this._subscribeService.unSubscribeToCommunity(this.communityId, email,this.properties.adminToolsAPIURL).subscribe ( |
97 | 112 |
res => { |
113 |
this.loading = false; |
|
114 |
if(res.status && res.status != 200) { |
|
115 |
UIkit.notification({ |
|
116 |
message : '<strong>There was an error in your unsubscription. Please try again!<strong>', |
|
117 |
status : 'warning', |
|
118 |
timeout : 3000, |
|
119 |
pos : 'top-center' |
|
120 |
}); |
|
121 |
} else { |
|
98 | 122 |
console.log(res); |
99 | 123 |
if(this.subscribed){ |
100 | 124 |
this.subscribed = false; |
101 | 125 |
} |
126 |
} |
|
102 | 127 |
}); |
103 | 128 |
} |
104 | 129 |
} |
Also available in: Unified diff
1. subscribe.component: disable subscribe/unsubscribe button when already pushed | add notification when subscribe/unsubscribe fails.
2. subscribe.service: return null in 'isSubscribedToCommunity' function if request fails.