Commit 6df09bb0 authored by Lukas Burgey's avatar Lukas Burgey

Add observer debugging using tap

parent dec71a6c
import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { throwError as observableThrowError, Observable, BehaviorSubject, of, EMPTY } from 'rxjs';
import { map, catchError, combineLatest } from 'rxjs/operators';
import { map, catchError, combineLatest, tap } from 'rxjs/operators';
import { CookieService } from 'ngx-cookie-service';
import { StompConfig, StompRService } from '@stomp/ng2-stompjs';
......@@ -21,12 +22,15 @@ export class UserService {
private initialized = false;
private loggedIn = false;
private observerDebugging = false;
// relogin on failed XHR calls
// is turned off when the user is deactivated
private autoReLogin = true;
private user: User;
private user$: BehaviorSubject<User>;
private user$: BehaviorSubject<User> = new BehaviorSubject(undefined);
private userEmissions: number = 0;
private sshKeys: Map<number, SSHKey> = new Map([]);
private sshKeys$ = new BehaviorSubject<SSHKey[]>([]);
......@@ -48,7 +52,6 @@ export class UserService {
private stompService: StompRService,
private prefs: PreferencesService,
) {
this.user$ = new BehaviorSubject(null);
this.connect();
}
......@@ -58,8 +61,6 @@ export class UserService {
this.userSrc().subscribe(
(newUser: User) => {
console.log('user$:', newUser);
if (newUser == undefined || newUser == null) {
// LOGGED OUT
// show the logout to the user
......@@ -247,6 +248,14 @@ export class UserService {
return observableThrowError(error);
}
private tapLogger(name: string): (e: any) => void {
return e => {
if (this.observerDebugging) {
console.log(name, e);
}
}
}
// PUBLIC API
public login(idp?: IdP): void {
if (idp) {
......@@ -343,23 +352,34 @@ export class UserService {
// DATA SERVICE API
//
public subscribeSpecific<T>(selector: (user: User) => T): Observable<T> {
return this.userSrc().pipe(map(selector));
return this.userSrc().pipe(
map(selector),
tap(this.tapLogger('subscribeSpecific')),
);
}
public sshKeysSrc(): Observable<SSHKey[]> {
return this.sshKeys$.asObservable();
return this.sshKeys$.asObservable().pipe(
tap(this.tapLogger('sshKeysSrc')),
);
}
public userSrc(): Observable<User> {
return this.user$.asObservable();
return this.user$.asObservable().pipe(
tap(this.tapLogger('userSrc')),
);
}
public deploymentsSrc(): Observable<Deployment[]> {
return this.deployments$.asObservable();
return this.deployments$.asObservable().pipe(
tap(this.tapLogger('deploymentsSrc')),
);
}
public depStatesSrc(): Observable<DeploymentState[]> {
return this.deploymentStates$.asObservable();
return this.deploymentStates$.asObservable().pipe(
tap(this.tapLogger('depStatesSrc')),
);
}
public subscribeStateFor(service: Service): Observable<DeploymentState> {
......@@ -367,6 +387,7 @@ export class UserService {
map((states: DeploymentState[]) => states.find(
(dsi: DeploymentState) => dsi.service.id == service.id,
)),
tap(this.tapLogger('subscribeStateFor')),
);
}
......@@ -378,11 +399,14 @@ export class UserService {
);
}
),
tap(this.tapLogger('subscribeDeployment')),
);
}
public servicesSrc(): Observable<Service[]> {
return this.subscribeSpecific(this.serviceSelector);
return this.subscribeSpecific(this.serviceSelector).pipe(
tap(this.tapLogger('servicesSrc')),
);
}
public vosSrc(): Observable<VO[]> {
......@@ -406,7 +430,7 @@ export class UserService {
return vos;
}
)
),
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment