[Trunk | Library]: subscribe.service.ts: Connect redesign: Add field 'isSubscribedSubject: BehaviorSubject<boolean>' and methods to initiate and get it (singleton service, to update subscriber status).
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@58570 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
b4fd5d7892
commit
1c105985b0
|
@ -1,14 +1,28 @@
|
||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import {map} from "rxjs/operators";
|
import {map, tap} from "rxjs/operators";
|
||||||
import {CustomOptions} from "../../services/servicesUtils/customOptions.class";
|
import {CustomOptions} from "../../services/servicesUtils/customOptions.class";
|
||||||
import {EnvProperties} from "../properties/env-properties";
|
import {EnvProperties} from "../properties/env-properties";
|
||||||
import {COOKIE} from "../../login/utils/helper.class";
|
import {COOKIE} from "../../login/utils/helper.class";
|
||||||
|
import {BehaviorSubject, Observable} from "rxjs";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SubscribeService {
|
export class SubscribeService {
|
||||||
|
private isSubscribedSubject: BehaviorSubject<boolean> = new BehaviorSubject(false);
|
||||||
|
|
||||||
constructor(private http: HttpClient) {
|
constructor(private http: HttpClient) {
|
||||||
|
console.log("Subscribe service constructor");
|
||||||
|
}
|
||||||
|
|
||||||
|
public initIsSubscribedToCommunity(properties: EnvProperties, pid: string) {
|
||||||
|
let url = properties.adminToolsAPIURL + "/community/" + pid + "/is-subscriber/";
|
||||||
|
this.http.get<boolean>(url, CustomOptions.getAuthOptionsWithBody()).subscribe((isSubscribed) => {
|
||||||
|
this.isSubscribedSubject.next(isSubscribed);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public get isSubscribed(): Observable<boolean> {
|
||||||
|
return this.isSubscribedSubject.asObservable();
|
||||||
}
|
}
|
||||||
|
|
||||||
getCommunitySubscribers(properties: EnvProperties, pid: string) {
|
getCommunitySubscribers(properties: EnvProperties, pid: string) {
|
||||||
|
@ -42,11 +56,17 @@ export class SubscribeService {
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribeToCommunity(properties: EnvProperties, pid: string) {
|
subscribeToCommunity(properties: EnvProperties, pid: string) {
|
||||||
return this.http.post<any>(properties.adminToolsAPIURL + "/community/" + pid + "/subscriber", {}, CustomOptions.getAuthOptionsWithBody());
|
return this.http.post<any>(properties.adminToolsAPIURL + "/community/" + pid + "/subscriber", {}, CustomOptions.getAuthOptionsWithBody())
|
||||||
|
.pipe(tap(isSubscribed => {
|
||||||
|
console.log("subscribe servive (subscribeToCommunity): isSubscribed: "+isSubscribed);
|
||||||
|
this.isSubscribedSubject.next(isSubscribed);}));
|
||||||
}
|
}
|
||||||
|
|
||||||
unSubscribeToCommunity(properties: EnvProperties, pid: string) {
|
unSubscribeToCommunity(properties: EnvProperties, pid: string) {
|
||||||
return this.http.post<any>(properties.adminToolsAPIURL + "/community/" + pid + "/subscriber/delete", {}, CustomOptions.getAuthOptionsWithBody());
|
return this.http.post<any>(properties.adminToolsAPIURL + "/community/" + pid + "/subscriber/delete", {}, CustomOptions.getAuthOptionsWithBody())
|
||||||
|
.pipe(tap(unSubscribed => {
|
||||||
|
console.log("subscribe servive (unSubscribeToCommunity): isSubscribed: "+!unSubscribed);
|
||||||
|
this.isSubscribedSubject.next(!unSubscribed);}));
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribeToCommunityByEmail(properties: EnvProperties, pid: string, email: string) {
|
subscribeToCommunityByEmail(properties: EnvProperties, pid: string, email: string) {
|
||||||
|
|
Loading…
Reference in New Issue