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.


git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@53349 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
konstantina.galouni 2018-10-01 12:46:21 +00:00
parent fb01bcf984
commit 5af7aa6370
1 changed files with 31 additions and 6 deletions

View File

@ -6,6 +6,9 @@ import {AlertModal} from '../../openaireLibrary/utils/modal/alert';
import {SubscribeService} from '../../openaireLibrary/utils/subscribe/subscribe.service';
import {Session} from '../../openaireLibrary/login/utils/helper.class';
declare var UIkit: any;
@Component({
selector: 'subscribe',
template: `
@ -15,8 +18,8 @@ import {Session} from '../../openaireLibrary/login/utils/helper.class';
<a class="uk-alert-close" uk-close></a>
<p>Please login first to subscribe</p>
</div>
<a *ngIf="!subscribed" class="uk-button uk-button-primary" (click)="subscribe()"> Subscribe</a>
<a *ngIf="subscribed" class="uk-button uk-button-danger" (click)="confirmOpen()"> Unsubscribe</a>
<a *ngIf="!subscribed" [class]="'uk-button uk-button-primary' + (loading ? ' uk-disabled' : '')" (click)="subscribe()"> Subscribe</a>
<a *ngIf="subscribed" [class]="'uk-button uk-button-danger' + (loading ? ' uk-disabled' : '')" (click)="confirmOpen()"> Unsubscribe</a>
</span>
<span *ngIf="showNumbers && subscribers !=null && subscribers > 0" >
@ -32,7 +35,7 @@ export class SubscribeComponent {
@Input() showNumbers:boolean;
@Input() communityId:string;
loading: boolean = false;
subscribed:boolean = null;
properties:EnvProperties;
subscribers:number= null;
@ -76,13 +79,24 @@ export class SubscribeComponent {
this.subscribed = false;
this.showLoginAlert = true;
}else{
this.loading = true;
this.showLoginAlert = false;
this._subscribeService.subscribeToCommunity(this.communityId, email, this.properties.adminToolsAPIURL).subscribe (
res => {
this.loading = false;
console.log(res);
if(!this.subscribed){
this.subscribed = true;
}
if(res.status && res.status != 200) {
UIkit.notification({
message : '<strong>There was an error in your subscription. Please try again!<strong>',
status : 'warning',
timeout : 3000,
pos : 'top-center'
});
} else {
if(!this.subscribed){
this.subscribed = true;
}
}
});
}
}
@ -92,13 +106,24 @@ export class SubscribeComponent {
if(email == null){
this.subscribed = false;
}else{
this.loading = true;
//this.properties.adminToolsAPIURL
this._subscribeService.unSubscribeToCommunity(this.communityId, email,this.properties.adminToolsAPIURL).subscribe (
res => {
this.loading = false;
if(res.status && res.status != 200) {
UIkit.notification({
message : '<strong>There was an error in your unsubscription. Please try again!<strong>',
status : 'warning',
timeout : 3000,
pos : 'top-center'
});
} else {
console.log(res);
if(this.subscribed){
this.subscribed = false;
}
}
});
}
}